FastPrepExpand an Encoded String
Problems/Expand an Encoded String

Expand an Encoded String

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem expands a string written with repeat counts in front of bracketed groups, where groups can sit inside other groups. It is the classic decode-string task. A post links it as the coding question of its author's first Adobe round. After the coding, the interviewer asked for test cases on it. The author, an experienced SDET, received an offer for an Adobe SDET job at the Computer Scientist 1 level in Bangalore (offer dated October 2022, posted in November 2022). Most of that round went to questions on automation-framework design. By the author's account, the coding attempt used a stack but still gave wrong output on a few inputs.

The rules here are those of the linked task. Our choices: inputs of 1 to 80 characters, counts from 1 to 100, expanded strings of at most 2000 characters, and new examples. The test-writing follow-up is not tested. The editorial lists the cases worth testing.

Our version is about 90% the same as the reported question.

A string is stored in a short encoded form. In the encoding, k[text] stands for text written k times in a row, and groups may be placed inside other groups. Letters outside any group stand for themselves.

Given the encoded string s, return the fully expanded string.

Function

expandEncoded(s: String) → String

Examples

Example 1

s = "2[ab]c"return = "ababc"

The group 2[ab] becomes abab, and the plain letter c follows it: ababc.

Example 2

s = "3[x2[yz]]"return = "xyzyzxyzyzxyzyz"

Expand the inner group first: 2[yz] is yzyz, so the outer group is 3[xyzyz], which is xyzyz written three times.

Example 3

s = "pq10[r]s"return = "pqrrrrrrrrrrs"

The count can have more than one digit: 10[r] is ten copies of r. With pq before it and s after it, the result is pq, ten rs, then s.

Constraints

  • 1 <= s.length <= 80
  • s contains only lowercase English letters, digits and the brackets [ and ]
  • s is a valid encoding: every count is a number from 1 to 100 with no leading zero and is followed at once by [, every [ follows a count, brackets are balanced, no group is empty, and digits appear only in counts
  • The expanded string has at most 2000 characters

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • 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
  • Decode StringBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Parenthesized String CalculatorMeta · PHONE SCREENMeta interview questions
  • Decode StringSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
  • Plus and Minus CalculatorIndeed · PHONE SCREENIndeed interview questions
  • Basic CalculatorAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Arithmetic Expression EvaluatorMicrosoft · PHONE SCREENMicrosoft interview questions

Interview reports that mention this question

  • Adobe Frontend and QA Interviews: 14 Experiences (Part 6 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public String expandEncoded(String s) {
        // Write your code here.
    }
}
Checking account…