Add stack-queue module: ten stack and queue interview problems, monotonic stack, min stack, queue from stacks and stack from a queue, brute-force cross-checks, dry-run traces, operation counts, pitfalls (11 tests)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6nxynun5JFivebVb1
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
Reverse Polish Notation: stack after every token
|
||||
================================================
|
||||
|
||||
tokens: [2, 1, +, 3, *] result = 9
|
||||
token 2: push 2 stack(top first) = [2]
|
||||
token 1: push 1 stack(top first) = [1, 2]
|
||||
token +: pop 1 then 2, compute 2 + 1 = 3 stack(top first) = [3]
|
||||
token 3: push 3 stack(top first) = [3, 3]
|
||||
token *: pop 3 then 3, compute 3 * 3 = 9 stack(top first) = [9]
|
||||
|
||||
tokens: [4, 13, 5, /, +] result = 6
|
||||
token 4: push 4 stack(top first) = [4]
|
||||
token 13: push 13 stack(top first) = [13, 4]
|
||||
token 5: push 5 stack(top first) = [5, 13, 4]
|
||||
token /: pop 5 then 13, compute 13 / 5 = 2 stack(top first) = [2, 4]
|
||||
token +: pop 2 then 4, compute 4 + 2 = 6 stack(top first) = [6]
|
||||
|
||||
Reference in New Issue
Block a user