Posts

Showing posts from January, 2025

22. Sliding Window & 2 pointer

Image
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...

21. Recursion & Backtracking

Image
print all subsequences (Power Set) subsequences with sum k (print / count / exist) 🥀 subset sum-1,2⭐ combination sum-1, 2 ⭐ ------------------------------------------------------------ N queens⭐ Sudoku solver Rat Maze problem M-colouring (graphs) ----------------------------------------------------------- Palindrome partitioning⭐ print all permutations of an array/ string⭐ k-th Permutation sequence ------------------------------------------------------------- Note -  Lec-6 & 7 most imp... ------------------------------------------------------------------------------------------------------------ 2 types of Recursion - 1. parameterised- fn mein ek parameter m hi ans update hota rahega and last m fn us                                                 pa rameter ko print krdega... 2. functional- function return krega last m ans ko ------------...