Posts

Showing posts from January, 2025

22. Sliding Window & 2 pointer

Image
4 PATTERNS IN SLIDING WINDOW QUESTION- constant window longest subarray no of subarrays shotest window (imp)--when u r not sure of shrinking/ expanding ----------------------------------------------------------------------------------------------------------- 1.) Constant Window- e.g., subarray with max sum and length 'k' ------------------------------------------------------------------------------------------------------------------------- 2.) Longest subarray or substring problem with a condition- go from brute-->better-->optimal e.g., longest subarray with sum<k -------- BETTER- [  time- O(2N) ] 1. start with window of size 1 2. expand and shrink window size 3. when condition violated shrink till condition again becomes true ------------- OPTIMAL- ( time-O(N) ) shrinking ko khatam krke O(n) me krenge... shrinking bahut barr krne se acha ek baar krdo bas  BUT, if asked to print all subarrays then nothing can be done to reduce 2n ------------------------------------...

21. Backtracking

Image
pow fn/ BINARY EXPONENTIATION✅ print all subsequences/ POWER SET✅ print all subsequences with sum k✅ subset sum✅ count no. of subsequences with sum k✅ check if any one subsequence with sum k exists or not✅ combination sum-1,2✅ subset -2✅ N queens Sudoku solver Rat Maze problem M-coloring (graphs) Palindrome partitioning k-th Permutation sequence print all permutations of an array/ string ----------------------------------------------------------------------------------- LEC : 6 & 7 most imp... --------------------------------------------------------------------------------------------------------- POW(x,n)-(binary exponentiation) ----------------------------------------------------------------------------------------------------------- Call stack aise maano ki ek call mein kisi line of code pe vo line abhi execute ni hori vo bolri ki ruko abhi hoke aati hu zara and then vo dusri fn call mein chali gayi and so on... -------------------------------------------------------------------...