Parenthesized String Decompression
Updated
Problem statement
Decompress a valid encoded string encoded.
A repeated group has the form (content){count}, where count is an integer from 2 through 99. Replace the complete group with content repeated count times.
Groups may be nested, and literal lowercase letters may appear before, after, or between groups. Return the fully decompressed string.
Function
decompress(encoded: String) → StringExamples
Example 1
encoded = "a(abc){3}"return = "aabcabcabc"The group abc is repeated three times after the initial a.
Example 2
encoded = "a(b(c){2}){3}d"return = "abccbccbccd"The inner group produces cc, then bcc is repeated three times.
Example 3
encoded = "(x){2}(yz){3}"return = "xxyzyzyz"Adjacent encoded groups are expanded and concatenated.
Constraints
1 <= encoded.length <= 100000.- The input is valid under the grammar above.
- Literal text contains lowercase English letters.
- Every count is in
[2, 99]and appears immediately after a right parenthesis. - Nesting depth is at most
200. - The decompressed result has length at most
200000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
- Evaluate an Arithmetic Expression with DivisionMotive · ONSITE INTERVIEWMotive interview questions
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Flatten JSON With Array IndicesAdobe · PHONE SCREENAdobe interview questions
- Decode StringSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
- Plus and Minus CalculatorIndeed · PHONE SCREENIndeed interview questions
- Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions