Problem
You get an encoded string s. The encoding rule is k[text]. This part decodes to text repeated exactly k times, and k is a positive integer.
An encoded part can be inside another encoded part. Return the decoded string.
s is always valid. It has no extra spaces, and each [ has a matching ]. Digits appear only in the repeat counts k, so the original text has no digits.
Example 1
- Input:
- s = "2[xy]z"
- Output:
- "xyxyz"
Example 2
- Input:
- s = "2[m3[n]]"
- Output:
- "mnnnmnnn"
- Explanation:
- The inner part
3[n]decodes tonnn. Then2[mnnn]decodes tomnnnmnnn.
Example 3
- Input:
- s = "q10[r]"
- Output:
- "qrrrrrrrrrr"
- Explanation:
- A repeat count can have more than one digit.
Constraints
- 1 <= s.length <= 30
- s has lowercase English letters, digits and the square brackets [ and ].
- s is always a valid encoded string.
- All integers in s are in the range [1, 300].
- The decoded string has at most 10^5 characters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Basic Calculator III
Coding · Math · Recursion · Stack
- Minimum Insertions to Balance a Parentheses String
Coding · Bracket Sequences · Greedy · Stack
- Remove All Adjacent Duplicates in String II
Coding · Stack · String
- Using a Robot to Print the Lexicographically Smallest String
Coding · Greedy · Hash Table · Stack
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 5 records
Bloomberg
Leetcode 394. Decode String
Reported Aug 1, 2026 · 2 source reports
SENIOR
Source snapshot: Nov 12, 2026
View sourceCoupang
Leetcode 394. Decode String
Reported Jun 10, 2026 · 1 source report
STAFF
Source snapshot: Nov 12, 2026
View sourceGoogle
Leetcode 394. Decode String
Reported Dec 25, 2024 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 394. Decode String
Reported Oct 20, 2025 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View source