FastPrepDecode String
Problems/Decode String

Decode String

SambaNova Systems logoSambaNova Systems● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand SambaNova new-grad phone-screen report dated March 7, 2022 describes the well-known Decode String problem.

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

The encoding rule is k[encoded_string], meaning that the content inside the brackets is repeated exactly k times. Encoded groups may be nested, and adjacent literal or encoded groups are concatenated.

For this exercise, assume repetition counts are positive decimal integers and literal characters are lowercase English letters.

Function

decodeString(s: String) → String

Examples

Example 1

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

The inner group 2[c] becomes cc, so the outer group is 3[acc].

Example 2

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

Decode the two repeated groups independently, then append the literal suffix ef.

Constraints

  • 1 <= s.length <= 10^5
  • s is a valid encoding with balanced brackets.
  • Every repetition count is in [1, 300].
  • Literal characters are lowercase English letters.
  • The decoded output length is at most 10^5.

More SambaNova Systems Phone Screen questions

  • Deterministic Zigzag SortPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Minimum Window SubstringPHONE SCREEN · Seen Jun 2022
  • Number of ProvincesPHONE SCREEN · Seen Jun 2022
  • Merge Three Sorted ArraysPHONE SCREEN · Seen Jun 2022
  • Task Scheduler with CooldownPHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Point Inside a TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2022
  • Parse Variable, Expression, and Application TreesPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2022
  • Insert, Delete, and Get Random in Constant TimePHONE SCREEN · Seen Mar 2022
  • Ugly NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2021
  • Diagonal TraversePHONE SCREEN · Seen Nov 2020

Similar questions at other companies

  • Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
  • Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Flatten JSON With Array IndicesAdobe · PHONE SCREENAdobe interview questions
  • Plus and Minus CalculatorIndeed · PHONE SCREENIndeed interview questions
  • Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Evaluate an Arithmetic Expression with DivisionMotive · ONSITE INTERVIEWMotive interview questions
  • Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Parse a Partial JSON StreamListen Labs · PHONE SCREEN
All SambaNova Systems interview questionsSee SambaNova Systems hiring insights
Saved
class Solution {
    public String decodeString(String s) {
        // Write your code here.
    }
}
Checking account…