1. Histogram Expansion

    Histogram Expansion When To Use Use this when choosing an index as the minimum height/value and expanding as far as possible improves the objective.

  2. Exactly K via At Most

    Exactly K via At Most Template Use this when counting subarrays/substrings with exactly k of something.

  3. Fixed Size Window

    Fixed Size Window Template Use this when every candidate window must have exactly size k.

  4. Last Seen Jump Left

    Last Seen Jump Left When To Use Use this when duplicates can be handled by jumping l directly instead of removing one element at a time.

  5. Ordered Window

    Ordered Window When To Use Use this when the active window needs ordered queries like min, max, median, or closest value.

  6. Prefix Sum Hashmap

    Prefix Sum + Hashmap When To Use Use this instead of sliding window when the array can contain negative numbers or the target condition is not monotonic.

  7. Rolling Hash String Matching

    Rolling Hash / String Matching Window When To Use Use this when every window has fixed length, but comparing raw strings or full frequency arrays would be too expensive.

  8. Shrink While Valid

    Shrink While Valid Template Use this when you need the smallest valid window.

  9. Variable Size Maintain Invariant

    Variable Size: Maintain Invariant My bias in Max Consecutive Ones III I simulated the operation instead of maintaining an invariant.

  10. Fast Slow Pointer

    Fast Slow Pointer Intuition Both pointer will move through the non-cycle part, then once inside the cycle, they have a relative speed of one for covering the gap between them so in ā€œcā€ steps they will definitely meet.