dsa1 min read
Next Greater Element I — Monotonic Stack with HashMap
Find the next greater element for each query in O(n+m) using a monotonic stack on nums2 and a lookup map.
Read →
1575 articles
Find the next greater element for each query in O(n+m) using a monotonic stack on nums2 and a lookup map.
Find the next greater element in a circular array by iterating twice (0 to 2n) and using a monotonic stack.
Calculate the stock price span (consecutive days <= today) using a monotonic stack that accumulates spans.
Remove k digits to form the smallest number by maintaining a monotonic increasing stack and greedy removal.
Decode a string with nested encodings like 3[a2[bc]] using two stacks: one for counts and one for partial strings.