22. Sliding Window & 2 pointer
Conditions for Sliding Window- Monotonic condition Subarray sum problems with positive numbers Window validity behave predictably upon expand / shrink If, above conditions gets violated in a subarray problem, we go with below methods- 1. prefix sum + hashmap 2. DP 3. Binary Search --------------------------------------------------------------------------------------------------------------------------- 4 Patterns in Sliding Window- (striver) 1. Fix window - ❄️ B uild 1st window of size k => slide window (L++, R++) => update state =>update ans ----------------------------------------------------- 2. Variable window-1 - (Find longest subarray satisfying a condition ) - for each R, smallest index L, which keeps window valid, is chosen. ❄️ expand R => while window invalid: (shrink L) => now, update answer --------------------------------------------------- 3. Variable window-2 - (Count subarrays satisfying a condition ) - (current window invalid => all la...