PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Google

Decompress encoded string with nested repeats

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string parsing and manipulation skills, particularly handling nested repetition encodings and reasoning about output growth, and belongs to the Coding & Algorithms domain.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Decompress encoded string with nested repeats

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given an encoded string, decompress it into its expanded form. Encoding rules: - Parentheses `(...)` denote a group. - A repetition count is written in braces `{n}` **immediately after** a closing parenthesis `)`. - The group `(...)` is repeated exactly `n` times. - Groups may be nested. - You may assume the input is valid: - Parentheses/braces are properly matched. - Every `{n}` appears right after a `)`. - No need to handle invalid edge cases. - `n` is an integer in the range **2 to 99**. Examples: 1) `"a(abc){3}" -> "aabcabcabc"` 2) `"a(b(c){2}){3}d" -> "abccbccbccd"` - `(c){2} -> "cc"` - `(b + "cc") -> "bcc"` - `(bcc){3} -> "bccbccbcc"` - add prefix/suffix: `"a" + "bccbccbcc" + "d"` Task: - Implement a function that takes the encoded string and returns the decompressed string. - State and justify the time and space complexity in terms of input length and output length.

Quick Answer: This question evaluates string parsing and manipulation skills, particularly handling nested repetition encodings and reasoning about output growth, and belongs to the Coding & Algorithms domain.

Related Interview Questions

  • Compute Turnstile Crossing Times - Google (hard)
  • Simulate In-Place Cellular State Updates - Google (hard)
  • Determine Whether a Word Exists in a Graph - Google (medium)
  • Solve Shortest Paths and Rental Allocation - Google (medium)
  • Solve Two Array Optimization Problems - Google (medium)
Google logo
Google
Feb 11, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
13
0
Loading...

Given an encoded string, decompress it into its expanded form.

Encoding rules:

  • Parentheses (...) denote a group.
  • A repetition count is written in braces {n} immediately after a closing parenthesis ) .
  • The group (...) is repeated exactly n times.
  • Groups may be nested.
  • You may assume the input is valid:
    • Parentheses/braces are properly matched.
    • Every {n} appears right after a ) .
    • No need to handle invalid edge cases.
  • n is an integer in the range 2 to 99 .

Examples:

  1. "a(abc){3}" -> "aabcabcabc"
  2. "a(b(c){2}){3}d" -> "abccbccbccd"
    • (c){2} -> "cc"
    • (b + "cc") -> "bcc"
    • (bcc){3} -> "bccbccbcc"
    • add prefix/suffix: "a" + "bccbccbcc" + "d"

Task:

  • Implement a function that takes the encoded string and returns the decompressed string.
  • State and justify the time and space complexity in terms of input length and output length.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.