← 返回 instacart 的题目列表Onsite Coding: Decode Password
类型:qbank
String parsing prompt known as 'Decode Password' / decode. The exact Instacart syntax varies, but the repeated appearance across onsite loops makes the core task clear: manually parse an encoded string and decode nested or repeated substrings.
Requirements
Parse an encoded password/string format from raw input.
Decode nested or repeated substrings according to the prompt's grammar.
Return the decoded string or requested transformed output.
The prompt expects manual parsing rather than relying on a library parser.
Common equivalent form:
3[a2[c]] -> accaccacc
Notes
Use a stack of (previous_string, repeat_count) or recursive descent with an index pointer.
When you see a digit, parse the full number, not one character.
When you see an opening delimiter, push current state and reset the current buffer.
When you see a closing delimiter, pop and append current * repeat.
Complexity is O(output_length) time and space; mention that decoded output can be much larger than input.
If the Instacart version uses a different delimiter or password-specific syntax, map it to the same grammar before coding. Recent onsite candidates describe this as familiar if already practiced, then discuss how to refactor the parser for production use.
Preparation
Drill the stack implementation and recursive implementation.
Test multi-digit repeat counts, nested groups, adjacent groups, and plain characters outside groups.
Practice reading the input grammar out loud before coding; most mistakes come from assuming LeetCode syntax when the prompt uses a custom format.