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 @@
|
||||
Next greater element: the stack of pending indices, step by step
|
||||
================================================================
|
||||
|
||||
input [2, 1, 2, 4, 3]
|
||||
i=0 value=2: push 0 pending(top first) = [0]
|
||||
i=1 value=1: push 1 pending(top first) = [1, 0]
|
||||
i=2 value=2: pop index 1 (value 1) -> its answer is 2; push 2 pending(top first) = [2, 0]
|
||||
i=3 value=4: pop index 2 (value 2) -> its answer is 4; pop index 0 (value 2) -> its answer is 4; push 3 pending(top first) = [3]
|
||||
i=4 value=3: push 4 pending(top first) = [4, 3]
|
||||
indices still pending have no greater element to their right: [4, 3] -> stay -1
|
||||
result [4, 2, 4, -1, -1]
|
||||
|
||||
dailyTemperatures [73, 74, 75, 71, 69, 72, 76, 73]
|
||||
= [1, 1, 4, 2, 1, 1, 0, 0]
|
||||
|
||||
nextGreaterCircular [1, 2, 1] = [2, -1, 2]
|
||||
nextGreaterSubset [4, 1, 2] within [1, 3, 4, 2] = [-1, 3, -1]
|
||||
Reference in New Issue
Block a user