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,28 @@
|
||||
Balanced brackets: every step of four inputs
|
||||
============================================
|
||||
|
||||
input: {[()]} firstMismatch = -1
|
||||
read '{' at 0: push '}' waiting for (top first): }
|
||||
read '[' at 1: push ']' waiting for (top first): ] }
|
||||
read '(' at 2: push ')' waiting for (top first): ) ] }
|
||||
read ')' at 3: pop ')', matches waiting for (top first): ] }
|
||||
read ']' at 4: pop ']', matches waiting for (top first): }
|
||||
read '}' at 5: pop '}', matches waiting for (top first): (empty)
|
||||
end of input: waiting for (empty) -> balanced
|
||||
|
||||
input: ([)] firstMismatch = 2
|
||||
read '(' at 0: push ')' waiting for (top first): )
|
||||
read '[' at 1: push ']' waiting for (top first): ] )
|
||||
read ')' at 2: expected ']' -> NOT balanced
|
||||
|
||||
input: ()) firstMismatch = 2
|
||||
read '(' at 0: push ')' waiting for (top first): )
|
||||
read ')' at 1: pop ')', matches waiting for (top first): (empty)
|
||||
read ')' at 2: stack is empty, nothing to close -> NOT balanced
|
||||
|
||||
input: (() firstMismatch = 0
|
||||
read '(' at 0: push ')' waiting for (top first): )
|
||||
read '(' at 1: push ')' waiting for (top first): ) )
|
||||
read ')' at 2: pop ')', matches waiting for (top first): )
|
||||
end of input: waiting for ) -> NOT balanced, openers left over
|
||||
|
||||
Reference in New Issue
Block a user