Expand an Encoded String
Updated
Problem statement
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) → StringExamples
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 <= 80scontains only lowercase English letters, digits and the brackets[and]sis a valid encoding: every count is a number from1to100with 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
2000characters
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 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)