FastPrepDecode String
Problems/Decode String

Decode String

Bloomberg LP logoBloomberg LP● MediumNEW GRADFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg phone screen for new grad and full-time roles. The report names the well-known Decode String problem, number 394, but does not repeat its statement or examples. Our version is about 99% the same as the reported question.

Given a valid encoded string s, return its decoded form.

An encoded group has the form k[encodedString], meaning that encodedString is repeated exactly k times. Groups may be nested, and a repeat count may contain multiple digits.

The unencoded text contains lowercase English letters. Digits appear only as repeat counts immediately before bracketed groups.

Function

decodeString(s: String) → String

Examples

Example 1

s = "3[a]2[bc]"return = "aaabcbc"

Repeat a three times and bc twice, then concatenate the two decoded parts.

Example 2

s = "3[a2[c]]"return = "accaccacc"

The inner group becomes cc, so the outer group repeats acc three times.

Example 3

s = "2[abc]3[cd]ef"return = "abcabccdcdcdef"

Decode the two adjacent repeated groups, then retain the trailing literal ef.

Constraints

  • 1 <= s.length <= 30.
  • s contains lowercase English letters, digits, and square brackets.
  • s is a valid encoding with well-formed brackets.
  • Every repeat count is between 1 and 300.
  • The decoded output length does not exceed 10^5.

More Bloomberg LP Phone Screen questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
  • Parse a Partial JSON StreamListen Labs · PHONE SCREEN
  • Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Parenthesized String CalculatorMeta · PHONE SCREENMeta interview questions
  • Flatten JSON With Array IndicesAdobe · PHONE SCREENAdobe interview questions
  • Decode StringSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
  • Expand a Repeat-Encoded StringExpedia · ONSITE INTERVIEWExpedia interview questions
  • Plus and Minus CalculatorIndeed · PHONE SCREENIndeed interview questions

Interview reports that mention this question

  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
  • Bloomberg New Grad Question Bank: 161 Questions (Part 1 of 2)
  • Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)
  • Bloomberg New Grad SWE Interviews: 98 Experiences (Part 1 of 5)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String decodeString(String s) {
        // Write your code here.
    }

}
Checking account…