FastPrepParenthesized String Decompression
Problems/Parenthesized String Decompression

Parenthesized String Decompression

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report defines the repeat grammar (content){count}, gives flat and nested examples, says counts range from 2 through 99, and says you need not check that brackets are valid. In the comments the original author corrects the nested example to a(b(c){2}){3}d. We chose lowercase letters, the function signature, an output cap, and the input limits. Our version is about 97% the same as the reported question.

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) → String

Examples

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

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String decompress(String encoded) {
        // write your code here
    }
}
Checking account…