Next Variants

1. Next Greater Element Variants

These problems focus on monotonic stack applications, circularity, and range queries.

  • LeetCode 496arrow-up-right βž” Next Greater Element I: The basic introduction using a HashMap and a Monotonic Stack.

  • LeetCode 503arrow-up-right βž” Next Greater Element II: Introduces Circular Arrays. Requires the "double iteration" or "modulo" technique.

  • LeetCode 556arrow-up-right βž” 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 arrow-up-rightβž” Daily Temperatures: A practical application. Instead of the value, you return the distance (indices) to the next greater element.

  • LeetCode 84arrow-up-right βž” 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 arrow-up-rightβž” Next Permutation: The core problem discussed. Implement the pivot-swap-reverse logic.

  • LeetCode 60arrow-up-right βž” Permutation Sequence: Finds the K-th Permutation. Requires the Factoradic (factorial number system) approach rather than iterative calls.

  • LeetCode 267arrow-up-right βž” Palindrome Permutation II: Combines permutation logic with backtracking. You must generate all unique palindromic permutations.

  • LintCode 51arrow-up-right βž” 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 98arrow-up-right βž” 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 316arrow-up-right βž” Remove Duplicate Letters: Uses a monotonic stack to maintain Lexicographical Order while satisfying the constraint that every character must appear exactly once.

  • LeetCode 402arrow-up-right βž” Remove K Digits: Uses a monotonic stack to find the smallest possible number. This tests the "minimal lexicographical decrease" logic.

  • LeetCode 1856arrow-up-right βž” 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

Monotonic Stack

Visibility boundaries / O(n)O(n) optimization

Lexicographical

Suffix properties / Greedy minimal change

Combinatorics

Factorial number system / Math efficiency

Constraints

Monotonic logic with greedy pruning

Last updated