Queue Using Stacks:Pour Only When the Front Is Empty
Inbound takes every push; outbound serves pop and peek. Pour inbound into outbound only when outbound is empty, or you bury the current front.
Read More14 questions
Inbound takes every push; outbound serves pop and peek. Pour inbound into outbound only when outbound is empty, or you bury the current front.
Read MoreOffer then rotate size-1 so the newest sits at the front; pop and top become poll and peek, and that push is O(n) every time, not amortized.
Read MoreA per-type count accepts ([)]. Push every open; a close is legal only if the top matches, and the stack is empty when the string ends.
Read MoreRescanning the lane after every blast is quadratic. A deque of survivors lets one left-goer pop every smaller right-goer still on top; same-direction rocks never collide.
Read MoreThe operator you apply is the previous one; multiply and divide collapse the top term while plus and minus wait as signed stack entries.
Read MoreSort from the target backward and push a fleet time only when this car would arrive strictly later than the leader ahead; equal time at the destination is still one fleet.
Read MoreA nested forward scan is correct and quadratic. A decreasing stack of day indexes answers each wait in one pass; equal highs do not pop.
Read MoreMatching brackets only checks. Digits accumulate a multi-digit k, [ freezes the outer fragment, and ] expands the inner onto it.
Read MoreFinishing every 2^(2n) bitmask then running a checker is honest; illegal prefixes were already dead at the first extra close.
Read MoreA second deque tracks the running min; push a duplicate when the same floor arrives again, or the first pop of that value lies about getMin.
Read MoreThe same decreasing index stack as Daily Temperatures; walk 2n, write the greater value, and never push on the second lap.
Read MoreA stack of pending numbers is the one-pass fold; the first pop is the right operand, and Java int division already truncates toward zero.
Read MoreA stack of live directory names is the one-pass canonicalizer; splicing until the string settles is quadratic, and replace("..", "") smashes `...`.
Read MoreRepresentation and operations — not the problem set.