stack problem
Problem
| Link | Category / Pattern | Key idea / Template | Difficulty | Notes | |
| Next Greater Element (Right) | https://leetcode.com/problems/next-greater-element-i/ | Monotonic stack — next greater | Maintain decreasing stack; pop while current > stack.top. O(n). | Easy | |
| Next Greater Element (Left) | https://leetcode.com/problems/next-greater-element-ii/ (adapt left) | Monotonic stack — mirror | Iterate left→right; pop until top > current. | Easy | |
| Next Smaller Element (Right) | https://leetcode.com/problems/next-greater-element-iii/ (adapt smaller) | Monotonic stack (increasing) | Pop while current < stack.top. O(n). | Easy | |
| Next Smaller Element (Left) | (Custom implementation) | Monotonic stack | Mirror of NSE right. | Easy | |
| Next Greater Element II (Circular) | https://leetcode.com/problems/next-greater-element-ii/ | Monotonic stack — circular array | Iterate twice; use modulo indexing. O(n). | Medium | |
| Stock Span | https://leetcode.com/problems/online-stock-span/ | Stack (indexes of decreasing prices) | Pop until price[top] > current; span = i - stack.top. O(n). | Easy | |
| Daily Temperatures | https://leetcode.com/problems/daily-temperatures/ | Monotonic stack | NGE logic for next warmer day. | Medium | |
| Largest Rectangle in Histogram | https://leetcode.com/problems/largest-rectangle-in-histogram/ | Monotonic stack — NSL + NSR | Use NSL/NSR to compute max area. O(n). | Hard | |
| Sum of Subarray Minimums | https://leetcode.com/problems/sum-of-subarray-minimums/ | Monotonic stack + combinatorics | Contribution = value * left_span * right_span. O(n). | Hard | |
| Sum of Subarray Ranges | https://leetcode.com/problems/sum-of-subarray-ranges/ | Two monotonic passes (max-min) | Sum(max) - Sum(min) using stacks. O(n). | Hard | |
| Remove K Digits | https://leetcode.com/problems/remove-k-digits/ | Stack/greedy | Keep increasing stack; remove when top > current; strip leading zeros. | Medium | |
| Asteroid Collision | https://leetcode.com/problems/asteroid-collision/ | Stack simulation | Handle sign collisions; compare magnitudes. | Medium | |
| Remove Outermost Parentheses | https://leetcode.com/problems/remove-outermost-parentheses/ | Stack / depth counter | Track depth; skip outermost. | Easy | |
| Minimum Remove to Make Valid Parentheses | https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/ | Stack + mark invalid | Track '(' indices; mark unmatched; rebuild. | Medium | |
| Valid Parenthesis String | https://leetcode.com/problems/valid-parenthesis-string/ | Greedy / two-pass | Track possible open count range. | Medium | |
| Score of Parentheses | https://leetcode.com/problems/score-of-parentheses/ | Stack or depth counting | Score rule: ()=1, AB=A+B, (A)=2*A. | Easy | |
| Longest Valid Parentheses | https://leetcode.com/problems/longest-valid-parentheses/ | Stack or DP | Track base index; extend valid lengths. | Hard | |
| Minimum Swaps for Bracket Balancing | https://www.geeksforgeeks.org/problems/minimum-swaps-for-bracket-balancing2704/1 | Greedy / pointer | Track imbalance and count swaps. | Medium |