When NOT to Use

Avoid forcing this pattern

Avoid forcing this pattern when:

  • Non-contiguous subsequences needed: Sliding window only finds contiguous sequences. For subsequences like Longest Increasing Subsequence, use DP instead.
  • Need to track elements outside current window: If the solution depends on elements you've already passed, sliding window loses that information. Consider prefix sums or different state tracking.
  • Multiple independent windows needed: Standard sliding window maintains one range. Problems needing multiple simultaneous ranges require different approaches.