Next Variants
1. Next Greater Element Variants
These problems focus on monotonic stack applications, circularity, and range queries.
LeetCode 496 β Next Greater Element I: The basic introduction using a HashMap and a Monotonic Stack.
LeetCode 503 β Next Greater Element II: Introduces Circular Arrays. Requires the "double iteration" or "modulo" technique.
LeetCode 556 β Next Greater Element III: A direct bridge to the Next Permutation algorithm. It asks for the next greater integer using the same digits.
LeetCode 739 β Daily Temperatures: A practical application. Instead of the value, you return the distance (indices) to the next greater element.
LeetCode 84 β Largest Rectangle in Histogram: An L5 staple. Uses NGE logic (specifically Previous/Next Smaller Element) to find the width of the rectangle a bar can sustain.
2. Next Permutation Variants
These problems test the lexicographical logic, ranking, and inversions.
LeetCode 31 β Next Permutation: The core problem discussed. Implement the pivot-swap-reverse logic.
LeetCode 60 β Permutation Sequence: Finds the K-th Permutation. Requires the Factoradic (factorial number system) approach rather than iterative calls.
LeetCode 267 β Palindrome Permutation II: Combines permutation logic with backtracking. You must generate all unique palindromic permutations.
LintCode 51 β Previous Permutation: Inverts the logic to find the largest permutation smaller than the current one. Excellent for testing symmetry in your logic.
3. Advanced / Google-Style Twists
These problems move toward tree structures or complex constraints often seen in L5 interviews.
LeetCode 98 β Validate Binary Search Tree: While seemingly unrelated, the NGE in a BST is its In-order Successor. This tests the connection between linear arrays and tree topologies.
LeetCode 316 β Remove Duplicate Letters: Uses a monotonic stack to maintain Lexicographical Order while satisfying the constraint that every character must appear exactly once.
LeetCode 402 β Remove K Digits: Uses a monotonic stack to find the smallest possible number. This tests the "minimal lexicographical decrease" logic.
LeetCode 1856 β Maximum Subarray Min-Product: A "harder" variant of the Histogram problem. Uses NGE logic to define the range where an element is the minimum.
Summary Table for L5 Study Plan
Category
Must-Solve Problem
Core Skill Tested
Last updated