FAANG · LeetCode #385
Mini Parser — three-stage drill
1The ProblemMedium
Mini Parser
Deserialize a string like "[123,[456,789]]" into its nested-integer structure.
Examples
"324"→ 324"[123,[456,789]]"→ [123, [456, 789]]
constraintThe string is a valid nested-list encoding; integers may be negative.
2The PatternTIME O(n) · SPACE O(d)
Recursive Descent
Parse a structured string top-down: each grammar rule is a function, and one lookahead character tells you which to call next. Nesting is handled by recursion, and — unlike backtracking — a choice is never undone, because the next character is always enough to decide.
Problems using this pattern
3The SolutionRESULT → [12, [34]]
Step through it
'[' → start a list, recurse into parse_list
Step 1 / 7
Arrow keys to navigate · escape to reset