Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Questions by Love Babbar

Q. No. Topic: Problem: Done [yes or no] Worth REV Review

1 Array Reverse the array yes/done two pinter//ek start me ek end me fir dono position ka element of array ko swap krate jaw//O(n) me ban jayega
2 Array Find the maximum and minimum element in an array yes/done find max in array or find min in array
3 Array Find the "Kth" max and min element of an array yes/done priority queue me sab element dalo//min ya max priority queue requirment pr depend krega//k element pop kro taki jo last ka top hoaga wo answer hoga
4 Array Given an array which consists of only 0, 1 and 2. Sort the array without using any sorting algo yes/done leetcode (question-sort colours)//frequency count kr lo sbka//frequency ke hisab se element placed kr do//ya dusra approach hoga ki two pointer rkh do ek 0 ke liye and ek 2 ke liye of fir fir traverse ke duration o and 2 ko shi position me dalte rho jb tk travesal ka pointer 2 ka pointer se mil na jaye
5 Array Move all the negative elements to one side of the array yes/done use two pointer approach// ek pointer negative ke liye or ek traverse ke liye
6 Array Find the Union and Intersection of the two sorted arrays. yes/done i solved using set(but we can use approach of making sorted array from two sorted array,but must care about same number present in sorted array more than once)
7 Array Write a program to cyclically rotate an array by one. yes/done use tmp array to don't overlap data,approch-tmp[(i+1)%n]=arr[i];(i+step)%size is to make it cyclic
8 Array find Largest sum contiguous Subarray [V. IMP] yes/done Yes must know kadane's algorithm//take two variable //traverse krke tmpsum =max(arr[i],tmpsum+arr[i]) nikalo har ith pr fir isme se jo max hoga usko finanal ans nikalo finalsum=max(finalsum,tmpsum)
9 Array Minimise the maximum difference between heights [V.IMP] yes/done Yes pahle sort kro fir traverse kro and find kro last-k bada h ya i-1th value+k bada h//same min v nikalo first+k chota h ya ith chota h and min nikalo ans min h ya av jo naya nikale min max ka diff chota h //ye sb har itteration ke liye krna h
10 Array Minimum no. of Jumps to reach end of an array yes/done Yes 3 things we need to see 1) steps=arr[0] 2)maxReach=arr[0] 3)jumps=1//?=how maxdist = max(maxdist, i+arr[i]); it will give max distance?//hm 0 step se ith value ka step le skte h isliye 0se ith me kitna jump kre isko pata krne ke liye jumped index+its value ko chek renge kiska jyada h whi jump krna shi rhega
11 Array find duplicate in an array of N+1 Integers yes/done aproach:-slow=arr[slow] and fast=arr[arr[fast]] and check fast==slow to return that index element(slow fast are index)//sort kro fir chech kro koi reapeted h kya
12 Array Merge 2 sorted arrays without using Extra space. yes/done YES dono ko add kro phle fir sort kr do// O(n) ke liye extra space lena hi hoga and jese simple two sorted link list ko merge krte h wese kr do
13 Array Kadane's Algo [V.V.V.V.V IMP] yes/done YES phle traverse kro and har traverse me tempsum=max(tempsum,tempsum+arr[i]) lagaw fir finalsum=max(finalsum,tempsum) lagaw har iteretion ke liye ye kro
14 Array Merge Intervals yes/done phle do list banaw uper ke liye and lower ke liye fir sort kro dono ko fir flower[0] ko start mano and jaha tk i-1th of uper and lith of lower, overlap nhi kr rha h wha tk ko ek interval bana do fir ith of lower ko fir se start bana do or jab in-1th of lower chala jaw to n-1th of uper hi last inteval ka uper hoga
15 Array Next Permutation yes/done YES array ka last se wo index khojo jaha ith item <i+1th item se fir ith item ko just isse chota in right side se swap kra do fir ith se last tk ko two pointwer se reverse kra do //agar ith nhi milta h yath ith=0 ho mtlb next permution nhi h iska yhi last h isliye iska answer first permutiona hoga
16 Array Count Inversion yes/done merge sort hi krna h bs merge krte samay jb arr2 ka item len then ho arr1 ka item se to [c+=v1.size()-a;] size of arr1-jo item bada h wha se last tk jistna number h usko count me add krte jana h{qki wo utna possible pair bana skta h or two sortesd array me inversion count ke liye wesa pair count krna hota h jo ki arr1 me bada ho arr2 me chhota
17 Array Best time to buy and Sell stock yes/done kadane's algo jesa hi pr isme first item ko min buy smjho and travesre kro or dekho ith item min h ya phle ka hi min shi h ,fir us min ko leke ith item ke liye profit nikalo fir usme of ans me jo max ho usko rkhte jaw
18 Array find all pairs on integer array whose sum is equal to given number yes/done approch=sort the array,find min and max index of (k-arr[i]) by bin search if min!=i then count+=max-min+1 else count+=max-min//matlb har item ka next pair ka uperbond and lower bond pata kro logn me qki wo item utna number ke ath pair bana skta h
19 Array find common elements In 3 sorted arrays yes/done approch=if all equal then check last and push ,then find max among three then increase those index which element have less then max(becouse it was sorted)
20 Array Rearrange the array in alternating positive and negative items with O(1) extra space yes/done YES ek loop chalaw or dekho ki item outofplacwe h kya to fir whi loop me age badte rho jb tk ki uska reqired value ka index na mil jaye fir ek bar right rotaion kra do// agar outofplace and required value ka index diif 2 ya 2 se jyada h mtlb outofplace ka next to rotation ke karan thik ho gya hoga pr next ka next nhi thik huwa hoga isliye 2 plus kr denage //or agar pahla loop khatam ho jata h or outofplace last
21 Array Find if there is any subarray with sum equal to 0 yes/done find prefix sum and store in map and for every prefix sum must check is it already in map(because if zero sum is have then must repeate the prefix sum)
22 Array Find factorial of a large number yes/done store the result in vector in (MSB is on leftof vec) multiply left to rirght and each(i.e, i) time only left most digit is store in vec and carry part is add to multiple of i and next of vec digit.//jese addition me a+b+carry krte h wese hi multiplication me a*b+carry krenge //isme carry ek se jyda digit ka v ho skta h isliye last me sab dit ko push krna hoga result me
23 Array find maximum product subarray yes/done ek loop chalaw first se last tk har bar ek tmp ko multiplies krte jaw arr[i] se fir max ans update krte jaw //yhi kam fir kro last se first tk ka loop chala ke //ab do answer hoga ek forward direction loop wla or ek reverse wla dono me jo max h whi ans h //ye isliye qki odd num of neg num ho skta h jiske karn overall ans neg mil jata hoga
24 Array Find longest coinsecutive subsequence yes/done take var tmpcount and count whenever continuety break tmpcount make 0 and count store max of tmpcount and count(must sort before )
25 Array Given an array of size n and a number k, fin all elements that appear more than " n/k " times. NO/done map me frequency store kro fir map ko traverse kro jiska jiska freq n/k se jyada h wo key ko array me dal ke return kr do
26 Array Maximum profit by buying and selling a share atmost twice yes YES
27 Array Find whether an array is a subset of another array yes/done approch=use map to store count of item of ar1 then decrease count which present in ar2 if count is not <0 for every item of map ,return true
28 Array Find the triplet that sum to a given value yes/done sort kro fir traverse kro fir har ek item ke liye next two value find kro two pointer se jese two sum nikalte h//(i!=s&&i!=e&&s!=e&&A[i]+A[s]+A[e]==x) sirf yhi condition h jisme true hoga nhi to false hoga answer
29 Array Trapping Rain water problem yes/done YES tourch wla approach h// ek bar right side se jalaw jo diwar me takraye usme chad ke fir age ka diwar dekho // is tarah se tumko wo wo idex mil jayega jaha jaha tum height increase kr rha hoga // same kam left sise se v karo //left and right ka last ek same diwar hoga ya same height ka do alag alag diwar higa to use according water trap nikal lo
30 Array Chocolate Distribution problem yes/done YES sort kro fie m size ka subarray me check kro kiska last-first min h whi ans hoga
31 Array Smallest Subarray with sum greater than a given value yes/done 2 pointer lagaw ek for loop lo jo ek point hoga or sum me ith value add krte jayega //jb sum>k ho jayega to second pointer value summ l=me minus krte jayenge //ye while loop se krenge taki jaha sum<k hone agega whi second pointer ruk jayega or min sub store kr lenge
32 Array Three way partitioning of an array around a given value yes/done jese 012 ko kiye the thre pointer se wsi tarh krna h // incremenet of pointer ko dhyan se krna h
33 Array Minimum swaps required bring elements less equal K together yes
34 Array Minimum no. of operations required to make an array palindrome yes/done array ka har item ko check kro palindrome h ya nhi by making a function is palindrome which cbeck that is it palindrome or bot(two pointer se palindrome cj=heck ka function banana h)
35 Array Median of 2 sorted arrays of equal size yes/done jese merge krte h wese hi n time tk kro qki dono equal size ka h and ek n+1 tak ka v lena hoga qki even number of number in array wla case ho jayega
36 Array Median of 2 sorted arrays of different size yes/done same upar wla jesa hi bas is bar n ke jagah (n1+n1)/2 ho jayega qki unwqual size h

37 Matrix Spiral traversal on a Matrix yes/done ek loop chalaw total number of item in matrix bar fir uske andar 4 for loop lagaw(top ke liye fir top-- kro and fir right ke liye fir right-- and fir bottom ke liye fir bottom++,and left ke liye fir left++) //is tarah se dhire dhire centre ki or chalte jayega or count ko har ek print ke bad ++ kr dena taki jese hi count = toatal number of item ho jayega to top bottom ko or bottom top print nhi krega nhi to sb print krne
38 Matrix Search an element in a matriix yes/done yes BS on a matrix //qki har last item of a row is less then first item of next row hoga isliye binary search kro and (% and / se row colum nikalo mid value se)
39 Matrix Find median in a row wise sorted matrix yes yes BS on matrix with some observations
40 Matrix Find row with maximum no. of 1's yes/done first se last column se find karo ki phle kis row me 1 milta h qki sorted h to phle jese hi mil jata h kisi row me to baki ka column check krne ka jarurat hi nhi h qki hmlog left col se khoj rhe the so jo jaldi mila whi max 1 retain krta hoga
41 Matrix Print elements in sorted order using row-column wise sorted matrix yes/done sab item ko ek vector me dalo fir sort kr do fir ek ek krke matrix me place kr do
42 Matrix Maximum size rectangle NO/done yes Max area in a histogram//stack ke help se nest min and pre min nikal lo fir uske help se area nikalo or jo max area hoga usko ans me update kro // or ye kan=m har row ke liye kro fir final jo ans ayega whi max rectangle hoga
43 Matrix Find a specific pair in matrix yes yes reduce time complexity by pre-processing
44 Matrix Rotate matrix by 90 degrees yes/done yes transpose the marix and and reverse the rows//ya to jese spirel print kiye the wese hi kr skte h bas is bar print ke badle logic laga ke rotate krenge ans (top--,right--,botoo++,left++) krenge or jese hi toatal count tk pahuch jayega break kr dena h taki limit cross na kare
45 Matrix Kth smallest element in a row-cpumn wise sorted matrix yes
46 Matrix Common elements in all rows of a given matrix yes/done yes use a map//phle first row ka data ko map me dalo with freq then next row ke value ka freq increase krne se phle chek krao ki jo row ka freq dal rha h uske pi6e ka me common tha ki nhi ye tb comman bolenge jab freq row ke equal hoga or esa hota h to freq ++ kro//eg-3rd row me koi item ka freq dalne se phle uska freq 2 nhi mil rha h mtlb wo sb row me nhi hoga ,agar hota ho har bar count+ hota to fir

47 String Reverse a String yes/done


48 String Check whether a String is Palindrome or not yes/done
49 String Find Duplicate characters in a string yes/done map
String Why strings are immutable in Java? <->
50 String Write a Code to check whether one string is a rotation of another yes/done concatanate the two strings which we want to chech and find if this concatanated string is present in s2 or not
51 String Write a Program to check whether a string is a valid shuffle of two strings or not no
52 String Count and Say problem NO/done yes
53 String Write a program to find the longest Palindrome in a string.[ Longest palindromic Substring] yes/done yes approch=check from longes substring(i.e, n size,n-1 size then n-2.....) if palindrime found then return it because it is longest one.
54 String Find Longest Recurring Subsequence in String yes/done no concept LCS
55 String Print all Subsequences of a string. NO/done recursion
56 String Print all the permutations of the given string yes/done recursion
57 String Split the Binary string into two substring with equal 0’s and 1’s yes no take count and a total count
58 String Word Wrap Problem [VERY IMP]. no yes  solution of Cormen book

59 String EDIT Distance [Very Imp] yes/done yes recursion + tabulation dp


60 String Find next greater number with same set of digits. [Very Very IMP] yes yes constructive akgorithms

61 String Balanced Parenthesis problem.[Imp] yes/done no standard stack problem


62 String Word break Problem[ Very Imp] no yes
63 String Rabin Karp Algo yes rolling hash
64 String KMP Algo yes
65 String Convert a Sentence into its equivalent mobile numeric keypad sequence. yes/done yes
66 String Minimum number of bracket reversals needed to make an expression balanced. yes/done no standard problem
67 String Count All Palindromic Subsequence in a given String. no yes watch pepcoding
68 String Count of number of given string in 2D character array no yes
69 String Search a Word in a 2D Grid of characters. no yes
70 String Boyer Moore Algorithm for Pattern Searching. <->
71 String Converting Roman Numerals to Decimal yes no map
72 String Longest Common Prefix yes do a vertical or a horizontal scanning
73 String Number of flips to make binary string alternate yes only 2 cases can be present
74 String Find the first repeated word in string. yes
75 String Minimum number of swaps for bracket balancing. yes yes think
76 String Find the longest common subsequence between two strings. yes yes Standard question
77 String Program to generate all possible valid IP addresses from given string. <->
78 String Write a program tofind the smallest window that contains all characters of string itself. YES yes variable sized window substring
79 String Rearrange characters in a string such that no two adjacent are same <->
80 String Minimum characters to be added at front to make string palindrome yes yes
81 String Given a sequence of words, print all anagrams together yes no map anagrams with their respective sorted strings
82 String Find the smallest window in a string containing all characters of another string yes yes important conept of variable sized window
83 String Recursively remove all adjacent duplicates yes basic loop
84 String String matching where one string contains wildcard characters <->
85 String Function to find Number of customers who could not get a computer <->
86 String Transform One String to Another using Minimum Number of Given Operation yes yes use of vector and some manipulation
87 String Check if two given strings are isomorphic to each other yes no map
88 String Recursively print all sentences that can be formed from list of word lists <->

89 Searching & Sorting Find first and last positions of an element in a sorted array yes/done no lower bound
90 Searching & Sorting Find a Fixed Point (Value equal to index) in a given array yes/done no linear search
91 Searching & Sorting Search in a rotated sorted array yes/done YES pivot
92 Searching & Sorting square root of an integer yes/done no lower bound/must handle mid*mid which may be exceed the int range
93 Searching & Sorting Maximum and minimum of an array using minimum number of comparisons <->/done
94 Searching & Sorting Optimum location of point to minimize total distance <->
95 Searching & Sorting Find the repeating and the missing yes/done yes create 2 equations 1) sum of array elemets 2) some of the square of the array elements
96 Searching & Sorting find majority element yes/done no map
97 Searching & Sorting Searching in an array where adjacent differ by at most k yes/done no
98 Searching & Sorting find a pair with a given difference yes/done no
99 Searching & Sorting find four elements that sum to a given value YES YES
100 Searching & Sorting maximum sum such that no 2 elements are adjacent yes yes
101 Searching & Sorting Count triplet with sum smaller than a given value yes no
102 Searching & Sorting merge 2 sorted arrays yes yes
103 Searching & Sorting print all subarrays with 0 sum Yes Yes
104 Searching & Sorting Product array Puzzle Yes no
105 Searching & Sorting Sort array according to count of set bits yes YES use comparator
106 Searching & Sorting minimum no. of swaps required to sort the array YES YES use map and sort
107 Searching & Sorting Bishu and Soldiers yes no
108 Searching & Sorting Rasta and Kheshtak no
109 Searching & Sorting Kth smallest number again no
110 Searching & Sorting Find pivot element in a sorted array <->
112 Searching & Sorting K-th Element of Two Sorted Arrays yes
113 Searching & Sorting Aggressive cows YES Yes Binary search on answer
114 Searching & Sorting Book Allocation Problem [ Very IMP] yes/done YES Binary search on answer
115 Searching & Sorting EKOSPOJ: <-> Binary search on answer
116 Searching & Sorting Job Scheduling Algo YES YES
117 Searching & Sorting Missing Number in AP YES YES Corner cases
118 Searching & Sorting Smallest number with atleastn trailing zeroes infactorial <->
119 Searching & Sorting Painters Partition Problem: Yes no
120 Searching & Sorting ROTI-Prata SPOJ <->
121 Searching & Sorting DoubleHelix SPOJ <->
122 Searching & Sorting Subset Sums <->
123 Searching & Sorting Findthe inversion count Yes Yes Merge sort
124 Searching & Sorting Implement Merge-sort in-place <->
125 Searching & Sorting Partitioning and Sorting Arrays with Many Repeated Entries <->

126 LinkedList Write a Program to reverse the Linked List. (Both Iterative and recursive) yes/done no 2 nodes one prev and one current node. An extra is required to swap the curr and prev//head ka next right node me rkho fir head ka next me left ko rkho fir left =head kro ,fir head=right karo
127 LinkedList Reverse a Linked List in group of Given Size. [Very Imp] yes/done yes recursive//same reverse kro pr return me ek pair karo jo hewhead and kth ke bad wla node return kre , newhead to left hoga or second wla isliye chahiye qki next part ko reverse krne ke lye next part ka head chahiye or esa krne ke liye hmko k+1th ke time return krna hoga bina reverse kiye qki k+1th sirf next part ka head ke ie gaye the
128 LinkedList Write a program to Detect loop in a linked list. yes/done no 2 node rkho ek slow ek fast jab dono mile to samjho loop h or agar null ho jata h to loop nhi h
129 LinkedList Write a program to Delete loop in a linked list. NO/done yes use c++//loop detect jese hi hoga to slow =head kr do fir slow and fast dono ko hi ek ek krke increment kro to jaha milega dono whi jaha cycle ban rha h so fast ke ek pre rkhna h or jab wo piont mil jaye to pre ka next =null kr dena
130 LinkedList Find the starting point of the loop. yes/done no use hashSet//same delet wla jesa hi bas is bar delete nhi krna h wo node hi return krna h //or agar null mil jata h to mtlb -1 return krna h
131 LinkedList Remove Duplicates in a sorted Linked List. yes/done no use TreeSet//ek pre rkho agar pre ka data head ke data ke equal h to pre ka next =head kro pr pre ko whi rhne do jab or head ko next move kra do jb head ka data not equal to pre ka data hoga to pre ka next me head dalo or is bar pre = head kr do//simple jese array me krte h
132 LinkedList Remove Duplicates in a Un-sorted Linked List. yes/done yes use LinkedHashSet// same pahle jese hi bas is bar map me v dalo jo data milta h fir head ko next move krte jayenge agar head data map me milta h to pre whi rhne denge bas head ko move kr denge or head ka data map me nhi mile to map me dal do pre and head dono ko move kro
133 LinkedList Write a Program to Move the last element to Front in a Linked List. yes/done ek node lo jo head se suru kro fir move krate jawo jb node ka next !=null ho to hi loop chalaw or jab loop se nikal jaw to mtlb node last node ko point kr rha hoga so ek pre v rkh lena jo iska phla ho usko null kero and node ko head manlo so node ka next me purana head ko dal do
134 LinkedList Add “1” to a number represented as a Linked List. yes/done yes //reverse kro jese linklist reverse krte h fir head mw 1 add kro agar carry ata h to next me add krte jaw or agar last me add krne pr v carry ata h to usko extra node bana ke place kr do fir pura linklist ko reverse krke return kr do
135 LinkedList Add two numbers represented by linked lists. yes/done yes makethe length of both the lists equal. Reverse each list and add //same phle jesa hi krna h // reverse kro dono ko add krte jawo carry ke sath agar koi ek list jaldi khatam ho jata h to bacha huwa list me carry ko add kro, extra node lage carry ke liye to bana lo fir reverse krke return kr do
136 LinkedList Intersection of two Sorted Linked List. NO/done jese 2 sorted array ko murge krte h wese hi do pinter lena h dono list ke liye fir jo equal aye to vector me store kr lo nhi to jo chota aye usko ++ kr do fir jese hi koi ek list khatam ho jaye loop break ho jana chahiye qki ab koi common nhi hoga
137 LinkedList Intersection Point of two Linked Lists. yes/done no 2 pointer approach// agar space use kr skte to do ko do vector se store kr lete fir pi6e se nikalte (since intersection so must be same in last node) jaha same nhi hota wha break kr dete loop or last jo data update hiwa tha whi ans hoga//space use nhi krna h to hmko 2 pointer lena hoga or loop tb tk ke liye chalayenge jab tk dono equal na ho jaye ,fir har loop me dono ko next me move kr denge ,pr usse
138 LinkedList Merge Sort For Linked lists.[Very Important] yes/done simple jese merge krte h ,issme to merge ke liye data kahi store v nhi krna padta h qki pointer ko hi change kr skte h //bas mergesort me mid wla node nikalne pr mid se phle wla node ka next null kr do taki do seperate list ban jaye ,head phla list ka head hoga and mid wla node dusra head hoga ,,or dono ka hi last me null hoga ,null nhi lagane se kya hoga ki merge time pata nhi chalega kaha last h head1
139 LinkedList Quicksort for Linked Lists.[Very Important] <->/done jese quick sort array me krte h wese hi bas partition time linklist ka data vector me store kr lo fir partitio krke lo seperate link list bana dena qki link list me last se pre nhi ja skte and partition me swap v nhi kr payennge isliye// duplicate ke case me kya hoga ki sb head1 me hi rh jayega head2 null rh jayega or qki head1 me sab same h so or partition hoga hi nhi to fix size ho jayega to endless loop ho jayega
140 LinkedList Find the middle Element of a linked list. yes/done 2 pointer//slow fast wla se se kr lo // odd ka case me koi dikkat nhi h pr even hone pr dikkat hoga ki slow miid se age ho jayega isliye fast ko phle update kro fir slow ko kro
141 LinkedList Check if a linked list is a circular linked list. yes/done slow fast se pata kr lo while loop laga ke //agar slow==fast hota h to circular h nhi to null mil jata h to nhi h
142 LinkedList Split a Circular linked list into two halves. <->/done jese mid nikale the wese hi bas sme ek extra pointer chahiye jo mid ka next ko rkhe taki head1 se mid ek list ho mid ka next se last ek list ho
143 LinkedList Write a Program to check whether the Singly Linked list is a palindrome or not. yes/done count kr lo kita node h fir mid se do equal lenth me list ko bato fir ek list ko reverse kro fir check kro data equl h ya nhi //odd case me mid node dono list se exclude kr dena h
144 LinkedList Deletion from a Circular Linked List. <->/done head se while loop suru kro jab tk head1 ka next head na ho jaye qki circular h to kav oga hi //har bar check kro ki key mila ya nhi mile to pre ka next me head1 ka next dal do ///fir se whi loop laga ke reverse kr do left right pointer laga kse jese simple me krte h
145 LinkedList Reverse a Doubly Linked list. yes/done do left right pointer leke interchange krte rho
146 LinkedList Find pairs with a given sum in a DLL. <-> qki doubly linklist h to phle ek pointer end me laga do //fir jese array me two pointer se nikalte h wese hi last ka pre ki or and first ko next ki or move krte rho //target mile to return kro.
147 LinkedList Count triplets in a sorted DLL whose sum is equal to given value “X”. <-> qki doubly ll h to left to right and right to left dono ja stkte h isliye array jese hi nikalenge //first loop head se suru hoga , uske ander ek wile loop rhega jese pairsum = target ke liye krte h pr is bar jab pair mile to check krna h ki dono pair same to nhi h and dono me se koi v phle loop ke node ke = to nhi h na
148 LinkedList Sort a “k”sorted Doubly Linked list.[Very IMP] <-> ek k+1 ka min heap banw fir heap ka jab tk khali na ho jaye tb tk loop chalaw ,phla node ko head bana do, and real list me fir ek node nikal ke heap me dalo(mtlb k+2th node dalo) ek tail pointer bana ke rkho jo har har loop mr heap ka top ko add krte jayega ans heap me bach huwa list me se ek ek node add krte jayega(ek hi bar sb node ko heap me nhi dale qki usse logn complexity ho jayega but hme pata
149 LinkedList Rotate DoublyLinked list by N nodes. <-> end ko head se connect kr do jisse circulsr link list ban jayega fir n time rotate kr do jo node me phuchega whi new head hoga ho head ka pre ka next ko null kro fir head ka pre ko hi null kr do
150 LinkedList Rotate a Doubly Linked list in group of Given Size.[Very IMP] <-> k size me pice pice karo list ko jisme head and tail maintain krna h fir reverse kra do fir reversed kiya huwa head tail ko next part ke sath jod do
151 LinkedList Can we reverse a linked list in less than O(n) ? <-> no not possible
152 LinkedList Why Quicksort is preferred for. Arrays and Merge Sort for LinkedLists ? <-> array ka case me merge sort me extra space lgta h quick me nhi lgta h isliye and ll ke case me just opposite hota h
153 LinkedList Flatten a Linked List yes/done ek part ko khud karo baki ka recursion se kara lo //top se down ko ek list mano bs tail mantain krna h tail ka bottom me next part ko dal do ,qki recursion baki ka part ko flat krke head return krna h so bs hmko present tail me ane wla head ko jod dena h
154 LinkedList Sort a LL of 0's, 1's and 2's <->/done cout krke rkha lo 1kitna h 2 kitna h and 0 kitha h fir place kr do list me
155 LinkedList Clone a linked list with next and random pointer <->/done phle clon banaw jisme next ko follow kren bas fir original ka next ko copy ka corresponding ko point kraw fir copy ka coresponding original ka next se point krar isse zik zek jesa ban jaye to kya hoga ki jb hm original ka rendom ko nikalenge to wo randome node ka next jarur corespong hoga mtlb ye node copy list me uska random hoga ,original me jisse random niakale the uska next ka ,islye esa ho sbme
156 LinkedList Merge K sorted Linked list <->/done simple merge krte jana h jese sorted array ko krta h
157 LinkedList Multiply 2 no. represented by LL <->/done jese vector se num banate h wese hi list data ko num me change krna h bus har bat % v krte rhana h taki limit se bahar na jaye,dono ke esa hi krna h fir dono number ko into krke fir % kr dena h taki result v mod se bahar na jaye;
158 LinkedList Delete nodes which have a greater value on right side <->/done phle reverse kro fir travesrse kro jo v pre ka data se kab hoga usko delete/skip kra do fire return krne se phle reverse kra do
159 LinkedList Segregate even and odd nodes in a Linked List yes/done 2 point/node bana lo odd and even fir traverse kro list ko jab jo aye usko us list ke tain me add kra do fir dono ,odd and even ko join kra ke return kr do
160 LinkedList Program for n’th node from the end of a Linked List <->/done size nikal ke size-n tk travesre krke node value return kro// ya reverse kro fir n th traverse krke node value return karo
161 LinkedList Find the first non-repeating character from a stream of characters <->/done map me dalo sabka freq fir head se suru kro loop and check kro data ka freq in map is =1 to age nhi dekhna h return kro

162 Binary Trees level order traversal yes/done q banaw fir while loop lagaw jb tk ki q khali na ho ajye,loop me q ka front pop kro fir data print kro or agar uska left ya right ho to q ka end me dal do
163 Binary Trees Reverse Level Order traversal yes/done same uper ke jese hi karo bas har bar while loop me jake q ka size nikalo fir utna ka for loop chalaw qki wo size hi ek level ka size h ,fir loop ke ander hi temp list bana ke rkho for loop ka data ko fir for loop se nikalte hi final list me tmp list ko dal do bki jb v q pop krenge to uska left right milne pr q me push kr denge //fir whule se nikal ke final list ko traverse krenge jise item ek list hoga jo ki ek level ka hoga
164 Binary Trees Height of a tree yes/done recursion se kenge// left ka height and right ka height ka max return krenge // base case hoge ki jab null ho to 0 return kr dena h
165 Binary Trees Diameter of a tree yes/done ek recursion function banayenge jo pair return krega jise ek height hoga and ek max dimeter hoga ,fir left kr liye call hoga and right e liye call hoga fir left ka height +right ka height+node ko dimeter manege fir left ,right, av ka dimeter me jo bada hoga wo max dimeter hoga and jo mah height hoga left and right me uska pair bana ke return kr denge
166 Binary Trees Mirror of a tree yes/done swap the left and the right node (using recursion from bootom to top)//phle bootop jaw fir node ka left ko right kr do and right ko left kr do fir node res=turn kr do // base case jab node nuul ho to null return karo//left ka mirror law right ka mirror law then change krke node return kr do
167 Binary Trees Inorder Traversal of a tree both using recursion and Iteration yes/done //recursion se kro left,node-right//
168 Binary Trees Preorder Traversal of a tree both using recursion and Iteration yes/done //recursion se kro node-left-right
169 Binary Trees Postorder Traversal of a tree both using recursion and Iteration yes/done //recursion se kro left-right-node
170 Binary Trees Left View of a tree yes/done //pre order traverse kro level ko pata krne ke liye left ya right me jane time level me 1+ kr dena h,and jb level =sizeof vector ho to wo node ka data vector me push kr dena h
171 Binary Trees Right View of Tree yes/done put right above left//pre order hi krna h pr is bar left se phle right ko call krna h//baki user wla jesa hi
172 Binary Trees Top View of a tree NO/done yes null case//while loop se level wise travese kro and is bar q me ek pai store kro jisme node and k=number line me uska position rhega //map me number line ke corresponding node value rkhte jayenge agar mp me us number line ka value ke corresponding koi value nhi h to qki top sw dekh rhe h mtlb ek bat data mil gya to mp ko update nhi kr skte qki uske niche wla to nhi dikhna chahiye,//root ko number
173 Binary Trees Bottom View of a tree yes/done yes one line modification//same jese top view kiye the //bas is bar mp me update krte rhna h qki bottom se dekh rhe h to last update hi dikhega
174 Binary Trees Zig-Zag traversal of a binary tree yes/done //jese level traverse krte h wese hi krna h bs ek flag rkhna jo batayega ki us level h=ka data ko reverse ya same order me push krna h ans vextor me qki zig zag h to ek bar ek level ka data push o jaye to flag=!flag kr dena h taki zig zag me hi hota rhe
175 Binary Trees Check if a tree is balanced or not yes/done recursion se kro jo ki ek pair dega jo batayega left part ka max height kitna h and balance tha ya nhi same right se v information lega ir dekhenge ki dono dono balance h and left and right ka height ka diff 1 ya 0 hi h to true and max height retuen kr denge
176 Binary Trees Diagnol Traversal of a Binary tree NO/done yes each node is starting with left so we don’t need to check for right child//right right right wla do ek hi diagonal ka level hoga so jb right jayenge to level change nhi krenge pr jab left jayenge to level +1 kr denge //ek map hoga jo level and vector ka hoga jio koi v node ka data uske level ka vec n]me dal dega //pr question me bola h left phle ka diagonal lena h isliye node ka data level me push kr denge fir
177 Binary Trees Boundary traversal of a Binary tree yes/done yes check for the right and leaf. Leaf are of two types left subtree leaf and right subtree leaf//leftnode nikal lo left left call krke agat left kaleft nhi ho to right ko call kro jab tk ki leaf node na ho recursion chalate rho //fir leafnode nikal lo //fir rightnode v nikal lo//pr dhyan ye dena h ki agar root ka left nhi h to sirf leaf and right hi hoga//same right nhi h to leaf an dleft hi hoga //and root ka data do bar na push
178 Binary Trees Construct Binary Tree from String with Bracket Representation no
179 Binary Trees Convert Binary tree into Doubly Linked List NO/done yes not an easy question// do pointer head and tail reference pass kro fir LNR traverse kro , fir tail me node add kro and tail ko node kro
180 Binary Trees Convert Binary tree into Sum tree yes/done go from bottom to up//LRN traverse kro fir and base case leaf node hoga and leaf node ka data ko 0 kr dena h and uska return kr dena h //usi trh left and right ka sum ko node ka data bana dena and left right and node value plus krke return kr dena h
181 Binary Trees Construct Binary tree from Inorder and preorder traversal nope/done // pre orer se traverse kro qki usme phle node ata h fir inorder me uska index khojo taki uske lft part ko lrft tree and right part ko right part bana ske fir pre order me next node dekhna h fir left wla part ke khojna h fir preor ka next right ke liye hoga //jab split krte krte ek v item nhi bach jayega tonull return kr dena h taki jis root ke laft right partition kiya tha uska left right node ban ske
182 Binary Trees Find minimum swaps required to convert a Binary tree into BST <->
183 Binary Trees Check if Binary tree is Sum tree or not <->/done left and right pair return krega jisme ek ye batayega ki left/right node condition fulfill krta h( if true)ya nhi//agar left right dono true h to left right and node ka data ko sum krke pair ke second bana ke return kr do
184 Binary Trees Check if all leaf nodes are at same level or not <->/done same uper wla jesa hi bs isme sirf leaaf node ka par return krna h (base case hoga ye) //pr dhyan ye dena h ki jb left ka pair nikalne ke liye left jana chahte h r left null h to right ko return kr denge qki left nhi mtlb sirf right hi hoga qki right v nhi hota to base case hota //same right ke case mev krna h ki right nhi ja pa rhe h to return left kr denge //or jb left right pair mil jaye to dono me check krne h dono=
185 Binary Trees Check if a Binary Tree contains duplicate subtrees of size 2 or more [ IMP ] <->
186 Binary Trees Check if 2 trees are mirror or not <->
187 Binary Trees Sum of Nodes on the Longest path from root to leaf node <->/done //pair return karega jisme first hoga max height and second hoga max height wla ka second +node ka data ;
188 Binary Trees Check if given graph is tree or not. [ IMP ] <->
189 Binary Trees Find Largest subtree sum in a tree <->
190 Binary Trees Maximum Sum of nodes in Binary tree such that no two are adjacent <->/done pair return krega jisme first =left ka first +right ka first hoga+node ka data hoga//second me left ka first and second me jo max h plus right ka first and second me jo max h // isse wo wla conncept h ki ek me node ka data ko include krna h ek me nhi krna h(or jisme nhi krna h usme option h ki max ko choose kre
191 Binary Trees Print all "K" Sum paths in a Binary tree <->
192 Binary Trees Find LCA in a Binary tree <->/done base case node==null ho to return null, nhi to check kro node vale =n1 ya n2 ho to return kro node nhi to left ke left se khojo fir right se khojo fir check kro left and right dono tarf se node mil rha h kya to whi node lca hoga nhi to dekho dono me se koi ek v node return kr rha h kya to ehi return kr do nhi to null = return kr do
193 Binary Trees Find distance between 2 nodes in a Binary tree <->/done 3 bar seperate function bana do ,ek jo n1 wla node ka level bata de fir ek n2 wla level ke liye fir lca ka node ka level fir calculate kr o distance//ya sab kam ek hi call me krna h to ek class define kro jisme ye sb info ho fir usi me update krte jawo and dis v update kr dena and return kr dena
194 Binary Trees Kth Ancestor of node in a Binary tree <->/done phle node khojo fir k ko -- krte jawo jese hi k=0 ho jaye to whi node ans hoga usko return kr do pr return d]se phle k ka value intmax kr dena taki dobara k =0 na ho paye fir last tk whi ans rh jayega update nhi hoga
195 Binary Trees Find all Duplicate subtrees in a Binary tree [ IMP ] <->
196 Binary Trees Tree Isomorphism Problem yes/done yes left with left && right with right or right left && left right//jan dono node not null ho and data v same ho to return true krna h nhi to koi ek v null huwa ya data same nhi huwa to false dena h//ek abt manna h ki swap huwa hoga so n1 ka left ko n2 ka right se check krna h fir ek bat manna h nhi swap huwa h so left ko left and right ko right se krna h fir dekhna h dono case me jiska left&& right true ayega

197 Binary Search Trees Fina a value in a BST yes/done yes property of bst is used//value chota h to left me move kro nhi to right me move kro or agar mil jaye to direct return kr do na
198 Binary Search Trees Deletion of a node in a BST <->
199 Binary Search Trees Find min and max value in a BST yes/done keep moving twords left until node is null
200 Binary Search Trees Find inorder successor and inorder predecessor in a BST <->
201 Binary Search Trees Check if a tree is a BST or not yes/done naïve way inorder+array
202 Binary Search Trees Populate Inorder successor of all nodes <->
203 Binary Search Trees Find LCA of 2 nodes in a BST <->
204 Binary Search Trees Construct BST from preorder traversal <->
205 Binary Search Trees Convert Binary tree into BST <->
206 Binary Search Trees Convert a normal BST into a Balanced BST <->
207 Binary Search Trees Merge two BST [ V.V.V>IMP ] <->
208 Binary Search Trees Find Kth largest element in a BST <->/done
209 Binary Search Trees Find Kth smallest element in a BST <->/done
210 Binary Search Trees Count pairs from 2 BST whose sum is equal to given value "X" <->
211 Binary Search Trees Find the median of BST in O(n) time and O(1) space <->/done
212 Binary Search Trees Count BST ndoes that lie in a given range yes/done use the property of BST
213 Binary Search Trees Replace every element with the least greater element on its right <->
214 Binary Search Trees Given "n" appointments, find the conflicting appointments <->
215 Binary Search Trees Check preorder is valid or not <->
216 Binary Search Trees Check whether BST contains Dead end <->
217 Binary Search Trees Largest BST in a Binary Tree [ V.V.V.V.V IMP ] <->/done
218 Binary Search Trees Flatten BST to sorted list yes/done inorder

219 Greedy Activity Selection Problem yes no sort the pair according to the end time. End time of one activity should be greater than the start time of another activity
220 Greedy Job SequencingProblem <->
221 Greedy Huffman Coding <->
222 Greedy Water Connection Problem <->
223 Greedy Fractional Knapsack Problem <->
224 Greedy Greedy Algorithm to find Minimum number of Coins <->
225 Greedy Maximum trains for which stoppage can be provided <->
226 Greedy Minimum Platforms Problem <->
227 Greedy Buy Maximum Stocks if i stocks can be bought on i-th day <->
228 Greedy Find the minimum and maximum amount to buy all N candies <->
229 Greedy Minimize Cash Flow among a given set of friends who have borrowed money from each other <->
230 Greedy Minimum Cost to cut a board into squares <->
231 Greedy Check if it is possible to survive on Island <->
232 Greedy Find maximum meetings in one room <->
233 Greedy Maximum product subset of an array <->
234 Greedy Maximize array sum after K negations <->
235 Greedy Maximize the sum of arr[i]*i yes
236 Greedy Maximum sum of absolute difference of an array yes
237 Greedy Maximize sum of consecutive differences in a circular array <->
238 Greedy Minimum sum of absolute difference of pairs of two arrays <->
239 Greedy Program for Shortest Job First (or SJF) CPU Scheduling <->
240 Greedy Program for Least Recently Used (LRU) Page Replacement algorithm <->
241 Greedy Smallest subset with sum greater than all other elements <->
242 Greedy Chocolate Distribution Problem yes
243 Greedy DEFKIN -Defense of a Kingdom <->
244 Greedy DIEHARD -DIE HARD <->
245 Greedy GERGOVIA -Wine trading in Gergovia <->
246 Greedy Picking Up Chicks <->
247 Greedy CHOCOLA –Chocolate <->
248 Greedy ARRANGE -Arranging Amplifiers <->
249 Greedy K Centers Problem <->
250 Greedy Minimum Cost of ropes <->
251 Greedy Find smallest number with given number of digits and sum of digits <->
252 Greedy Rearrange characters in a string such that no two adjacent are same <->
253 Greedy Find maximum sum possible equal sum of three stacks <->

254 BackTracking Rat in a maze Problem <->


255 BackTracking Printing all solutions in N-Queen Problem <->
256 BackTracking Word Break Problem using Backtracking <->
257 BackTracking Remove Invalid Parentheses <->
258 BackTracking Sudoku Solver <->
259 BackTracking m Coloring Problem <->
260 BackTracking Print all palindromic partitions of a string <->
261 BackTracking Subset Sum Problem <->
262 BackTracking The Knight’s tour problem <->
263 BackTracking Tug of War <->
264 BackTracking Find shortest safe route in a path with landmines <->
265 BackTracking Combinational Sum <->
266 BackTracking Find Maximum number possible by doing at-most K swaps <->
267 BackTracking Print all permutations of a string <->
268 BackTracking Find if there is a path of more than k length from a source <->
269 BackTracking Longest Possible Route in a Matrix with Hurdles <->
270 BackTracking Print all possible paths from top left to bottom right of a mXn matrix <->
271 BackTracking Partition of a set intoK subsets with equal sum <->
272 BackTracking Find the K-th Permutation Sequence of first N natural numbers <->

273 Stacks & Queues Implement Stack from Scratch <->


274 Stacks & Queues Implement Queue from Scratch <->/done
275 Stacks & Queues Implement 2 stack in an array <->/done
276 Stacks & Queues find the middle element of a stack <->/done
277 Stacks & Queues Implement "N" stacks in an Array <->
278 Stacks & Queues Check the expression has valid or Balanced parenthesis or not. <->/done
279 Stacks & Queues Reverse a String using Stack <->/done
280 Stacks & Queues Design a Stack that supports getMin() in O(1) time and O(1) extra space. <->/done
281 Stacks & Queues Find the next Greater element <->
282 Stacks & Queues The celebrity Problem <->/done
283 Stacks & Queues Arithmetic Expression evaluation <->
284 Stacks & Queues Evaluation of Postfix expression <->
285 Stacks & Queues Implement a method to insert an element at its bottom without using any other data structure. <->
286 Stacks & Queues Reverse a stack using recursion <->/done
287 Stacks & Queues Sort a Stack using recursion <->/done
288 Stacks & Queues Merge Overlapping Intervals <->
289 Stacks & Queues Largest rectangular Area in Histogram <->
290 Stacks & Queues Length of the Longest Valid Substring <->
291 Stacks & Queues Expression contains redundant bracket or not <->
292 Stacks & Queues Implement Stack using Queue <->
293 Stacks & Queues Implement Stack using Deque <->
294 Stacks & Queues Stack Permutations (Check if an array is stack permutation of other) <->
295 Stacks & Queues Implement Queue using Stack <->
296 Stacks & Queues Implement "n" queue in an array <->
297 Stacks & Queues Implement a Circular queue <->
298 Stacks & Queues LRU Cache Implementationa <->
299 Stacks & Queues Reverse a Queue using recursion <->
300 Stacks & Queues Reverse the first “K” elements of a queue <->
301 Stacks & Queues Interleave the first half of the queue with second half <->
302 Stacks & Queues Find the first circular tour that visits all Petrol Pumps <->
303 Stacks & Queues Minimum time required to rot all oranges <->
304 Stacks & Queues Distance of nearest cell having 1 in a binary matrix <->
305 Stacks & Queues First negative integer in every window of size “k” <->
306 Stacks & Queues Check if all levels of two trees are anagrams or not. <->
307 Stacks & Queues Sum of minimum and maximum elements of all subarrays of size “k”. <->
308 Stacks & Queues Minimum sum of squares of character counts in a given string after removing “k” characters. <->
309 Stacks & Queues Queue based approach or first non-repeating character in a stream. <->
310 Stacks & Queues Next Smaller Element <->

311 Heap Implement a Maxheap/MinHeap using arrays and recursion. <->


312 Heap Sort an Array using heap. (HeapSort) no yes heapify
313 Heap Maximum of all subarrays of size k. no yes deque
314 Heap “k” largest element in an array yes
315 Heap Kth smallest and largest element in an unsorted array yes
316 Heap Merge “K” sorted arrays. [ IMP ] <->
317 Heap Merge 2 Binary Max Heaps yes
318 Heap Kth largest sum continuous subarrays yes simple heap
319 Heap Leetcode- reorganize strings <->
320 Heap Merge “K” Sorted Linked Lists [V.IMP] <->
321 Heap Smallest range in “K” Lists <->
322 Heap Median in a stream of Integers <->
323 Heap Check if a Binary Tree is Heap <->
324 Heap Connect “n” ropes with minimum cost <->
325 Heap Convert BST to Min Heap <->
326 Heap Convert min heap to max heap <->
327 Heap Rearrange characters in a string such that no two adjacent are same. <->
328 Heap Minimum sum of two numbers formed from digits of an array <->

329 Graph Create a Graph, print it <->/done


330 Graph Implement BFS algorithm yes/done use q to store adjency node and pop ech and traverse// need queue,visited,ansvector
331 Graph Implement DFS Algo yes/done first node se suru kro fir us node ka adjency list dekho jo visited nhi h uske liye dfs func call r do//stack ka use se v kr skte h//jis node ke liye call aye dfs call me usko visited mark kr dena h fir uska adj ke liye check krna h call kr skte h ya nhi
332 Graph Detect Cycle in Directed Graph using BFS/DFS Algo <->/done isme parent pata hone se nhi chalega qki directed h to ho skta h kav visited mil jaye pr wo parent nhi ho// isliye do visited list rkhenge ek parmanet visited list jo ki hmesa krte h pr ek rhega dfs call visited list ye dfs call ke andar call hote jayega to visited mark hote jayega pr jab dfs call se lotega to false mark kr dega , taki hoga ye ki jb adj list me koi parmanent visted me visited milta h to check krega ki
333 Graph Detect Cycle in UnDirected Graph using BFS/DFS Algo yes/done dfs anf bfs dono se kr skte h bs ye dekhna h ki koi v node visited milne pr check krna h ki jiska adj list ka node visited h kya wo parant to nhi h // bfs need= queue,visited,parent//dfs need paratent list visited list
334 Graph Search in a Maze yes/done no dfs on a matrix//ek visited list rkho fir matrix ke according xheck kro left move,right move ,down move up move kr skte h ya nhi move kr skte h to fir se khud ko call kr do(dfs call/recursion) . base case =agar whi destination h to ans list me push kr do//ans by reference pass kro //visted v by reference pass kr skta h pr usme
check for invalid conditions
335 Graph Minimum Step by Knight yes/done bfs kro qki ye level wla h so jese hi wo level pahuch jawo jaha destination ho to return kr do
336 Graph flood fill algo yes/done yes dfs on a matrix
337 Graph Clone a graph <->/done
338 Graph Making wired Connections yes/done no of islands and connections
339 Graph word Ladder no
340 Graph Dijkstra algo yes/done koi v source node se kisi v node tk ka distace pata kr skte h ///level /bfs se //isme krna ye h ki koi v node se neighbor node ka distance parent node ka dis+weight of edge b/w parent and child se jyada h chil ka distace to child ka distace parent +weigt dis kro qki ye man lo ki jb parebnt ke bad tk ka node check kr rhe h mtlb parent ka source ka dist min hi hoga //issme basicaly array ban jayega jiska index
341 Graph Implement Topological Sort NO/done yes kahn's algo// dfs search kro and jab dfs call se return anelagega to ans me node ko push kr dena jis node ka dfs call hoga//qki acyclic h to loop me dfs fasega nhi means recursion se back ayega hi and last se lot ke a rha h to chil hamesa hi phle push kiya hoga parent se //so traverse ke bad reverse kr lo taki parent phle ho child se //and isse kav v child parent se phle nhi a payega pr directed and acyclic
342 Graph Minimum time taken by each job to be completed given by a Directed Acyclic Graph yes use top sort
43 Graph Find whether it is possible to finish all tasks or not from given dependencies <->/done indirectly question bol rha tha ki ye ek directed grapgh h and find kro ki cycle h ki nhi //cycle h to false return kro nhi to true
345 Graph Find the no. of Isalnds yes/done no simple dfs + SCC//bfs ya dfs traverse kro and mark kr do har 1 ko visited,6 direction me chek krke// n*m traverse krke dekho koi 1 wka not visited h kya to dfs/bfs call kro and count ++ kr do //call islye h ki jo v us 1 se touched hoga wo sb visited ho jayega jo ki gris travesrse krne time dobara nhi count kr paye//means grid y=trsverse me disconnected land milne pr hi dfs/bfs call kr paye
346 Graph Given a sorted Dictionary of an Alien Language, find order of characters <->/done qki sorted dict h to suru se last tk har pre curr word ko check kro kon sa char ke karan pre curr se phle ata h //isse ek grapgh bana do (pre char ==curr char h to mtlb dono kanext char check kro jaha diff aye to pre char adj list ka u hoga and curr char v hoga) //fir grapgh ban gya h to toppo sorst kr do//bas dhyan dena h ki adj list ke time char ko intme kr do but toppo ort me ans me push char bana ke
347 Graph Implement Kruksal’sAlgorithm yes
348 Graph Implement Prim’s Algorithm <->
349 Graph Total no. of Spanning tree in a graph <->
350 Graph Implement Bellman Ford Algorithm yes yes negative weight cycle
351 Graph Implement Floyd warshallAlgorithm yes
352 Graph Travelling Salesman Problem <->
353 Graph Graph ColouringProblem <->
354 Graph Snake and Ladders Problem <->
355 Graph Find bridge in a graph <->
356 Graph Count Strongly connected Components(Kosaraju Algo) <->
357 Graph Check whether a graph is Bipartite or Not yes std algorithm
358 Graph Detect Negative cycle in a graph yes std algorithm
359 Graph Longest path in a Directed Acyclic Graph <->
360 Graph Journey to the Moon yes no slight variation of count of islands
361 Graph Cheapest Flights Within K Stops no BFS+priority queue+directed graph
362 Graph Oliver and the Game <->
363 Graph Water Jug problem using BFS <->
364 Graph Water Jug problem using BFS <->
365 Graph Find if there is a path of more thank length from a source <->
366 Graph M-ColouringProblem <->
367 Graph Minimum edges to reverse o make path from source to destination <->
368 Graph Paths to travel each nodes using each edge(Seven Bridges) <->
369 Graph Vertex Cover Problem <->
370 Graph Chinese Postman or Route Inspection <->
371 Graph Number of Triangles in a Directed and Undirected Graph yes in directed graph/3 ; in undirected graph /(6)
372 Graph Minimise the cashflow among a given set of friends who have borrowed money from each other <->
373 Graph Two Clique Problem <->

374 Trie Construct a trie from scratch <->


375 Trie Find shortest unique prefix for every word in a given list <->
376 Trie Word Break Problem | (Trie solution) <->
377 Trie Given a sequence of words, print all anagrams together <->
378 Trie Implement a Phone Directory <->
379 Trie Print unique rows in a given boolean matrix <->

380 Dynamic Programming Coin ChangeProblem yes/done ek bar sum=sum-coin[i] kro and i wahi rhne do or ek bat skip kro just like i+1 kr do bina sum ko decrease kiye//fir dp me change kro
381 Dynamic Programming Knapsack Problem yes/done ek bar pick kro agar bag bag me jagah h to or ek bar skip kro fir max nikalo skip nd pick me or max ko return kro
382 Dynamic Programming Binomial CoefficientProblem <->/done recusion use kro // ncr(n,r)=ncr(n-1,r-1)+ncr(n-1,r) jb tk ki n==r ya r==0 na ho ajye hone pr 1 return kro
383 Dynamic Programming Permutation CoefficientProblem <->
384 Dynamic Programming Program for nth Catalan Number <->/done for loop lagawo 0 se n-1 tk fir har bar solve(i) +solve(n-i-1) ko ans me add krte jawo
385 Dynamic Programming Matrix Chain Multiplication yes
386 Dynamic Programming Edit Distance yes/done tino kamkro fir jo min ayega usko return kro
387 Dynamic Programming Subset Sum Problem yes/done include exclud kro
388 Dynamic Programming Friends Pairing Problem yes yes 2cases possible 1)mai akela baaki tu log dekh le ; 2)mai n-1 bando me kisi ek se pair up ho jaunga baaki tum n-2 log dekh lo
389 Dynamic Programming Gold Mine Problem yes/done no 3 cases possible as we are moving up down and same level
390 Dynamic Programming Assembly Line SchedulingProblem no yes
391 Dynamic Programming Painting the Fenceproblem NO/done recursion se // same color ke liye solve(n-2)*(k-1) and diff ke liye solve(n-1)*(k-1) fir dono ko plus kro// base case-n=1 me k 1nd n=2 me k*k;
392 Dynamic Programming Maximize The Cut Segments yes/done yes Three cases are possible Cut with x or y or z
393 Dynamic Programming Longest Common Subsequence yes/done i j ke incease krte jawo agar s1[i]==s2[j] h to nhi to ek bar i ko increase kro or ek bar j ko kro fir dono mese jiska ans max hoga usko return kro //s1[i]==s2[j] ka case me return kr dena h 1 plus i+1,j+1 ka solution
394 Dynamic Programming Longest Repeated Subsequence <->
395 Dynamic Programming Longest Increasing Subsequence yes yes 2 options are availabel either take it and increase length by 1 or don’t take it and keep the length same
396 Dynamic Programming Space Optimized Solution of LCS <->
397 Dynamic Programming LCS (Longest Common Subsequence) of three strings yes/done LCS + 1 more state// include and exclude wla method
398 Dynamic Programming Maximum Sum Increasing Subsequence <->/done pick and skip krna h //bus isme item ko add krte jana h afar strictly incresing mila to jese count me sift 1+ krte the wha
399 Dynamic Programming Count all subsequences having product less than K yes yes top down
400 Dynamic Programming Longest subsequence such that difference between adjacent is one <->
401 Dynamic Programming Maximum subsequence sum such that no three are consecutive <->
402 Dynamic Programming Egg Dropping Problem yes yes memoization
403 Dynamic Programming Maximum Length Chain of Pairs <->
404 Dynamic Programming Maximum size square sub-matrix with all 1s no yes tle with memoization
405 Dynamic Programming Maximum sum of pairs with specific difference no yes there's both a dp and a greedy solution, since we have to maximize the sum sort the array in descending order and traverse from the back. We'll have two options we can either take the i-1 th item or don’t take it
406 Dynamic Programming Min Cost PathProblem yes no 3 cases possible as we are moving left right and center level
407 Dynamic Programming Maximum difference of zeros and ones in binary string yes yes variation of kadane's
408 Dynamic Programming Minimum number of jumps to reach end <->
409 Dynamic Programming Minimum cost to fill given weight in a bag yes no variation of knapsack
410 Dynamic Programming Minimum removals from array to make max –min <= K <->
411 Dynamic Programming Longest Common Substring yes if no two characters atch then length will be zero. So lets fill the table with zero. If 2 characters matches then increment it with 1 else do nothing
412 Dynamic Programming Count number of ways to reacha given score in a game yes Choices are 3
413 Dynamic Programming Count Balanced Binary Trees of Height h no formula count(h-1)*count(h-1)+2*count(h-2)*count(h-1)
414 Dynamic Programming LargestSum Contiguous Subarray [V>V>V>V IMP ] yes no
415 Dynamic Programming Smallest sum contiguous subarray yes no variation of kadane's
416 Dynamic Programming Unbounded Knapsack (Repetition of items allowed) yes
417 Dynamic Programming Word Break Problem no
418 Dynamic Programming Largest Independent Set Problem <->
419 Dynamic Programming Partition problem yes
420 Dynamic Programming Longest Palindromic Subsequence yes yes LPS(a)=LCS(a,reverse(a))
421 Dynamic Programming Count All Palindromic Subsequence in a given String <->
422 Dynamic Programming Longest Palindromic Substring yes slight variation of LPS
423 Dynamic Programming Longest alternating subsequence no yes
424 Dynamic Programming Weighted Job Scheduling no std algorithm
425 Dynamic Programming Coin game winner where every player has three choices <->
426 Dynamic Programming Count Derangements (Permutation such that no element appears in its original position) [ IMPORTANT ] no yes countDer(n) = (n - 1) * [countDer(n - 1) + countDer(n - 2)]
427 Dynamic Programming Maximum profit by buying and selling a share at most twice [ IMP ] <->
428 Dynamic Programming Optimal Strategy for a Game <->
429 Dynamic Programming Optimal Binary Search Tree <->
430 Dynamic Programming Palindrome PartitioningProblem no
431 Dynamic Programming Word Wrap Problem yes yes
432 Dynamic Programming Mobile Numeric Keypad Problem [ IMP ] <->
433 Dynamic Programming Boolean Parenthesization Problem <->
434 Dynamic Programming Largest rectangular sub-matrix whose sum is 0 <->
435 Dynamic Programming Largest area rectangular sub-matrix with equal number of 1’s and 0’s [ IMP ] <->
436 Dynamic Programming Maximum sum rectangle in a 2D matrix yes kadanes
437 Dynamic Programming Maximum profit by buying and selling a share at most k times <->
438 Dynamic Programming Find if a string is interleaved of two other strings <->
439 Dynamic Programming Maximum Length of Pair Chain yes Greedy

440 Bit Manipulation Count set bits in an integer yes


441 Bit Manipulation Find the two non-repeating elements in an array of repeating elements yes
442 Bit Manipulation Count number of bits to be flipped to convert A to B yes
443 Bit Manipulation Count total set bits in all numbers from 1 to n TLE yes use recursion
444 Bit Manipulation Program to find whether a no is power of two yes
445 Bit Manipulation Find position of the only set bit yes
446 Bit Manipulation Copy set bits in a range yes yes maskLength=(1<<(r-l+1))-1; mask=((maskLength)<<(l-1))&y;x=x|mask
447 Bit Manipulation Divide two integers without using multiplication, division and mod operator yes
448 Bit Manipulation Calculate square of a number without using *, / and pow() yes
449 Bit Manipulation Power Set yes yes (1<<j)&i is non zero only then for the string by appending
last tk nhi pahuch pata h iska mtlb ki requied value bacha hi nhi h so baki wese ke wese hi chhor do qki requied value ka index first loop suru se hi khoj rha tha pr nhi mila //sice outofplace ko 2 se increment kiye h so is bat v requied value whi hoga jo ki nhi milne hoga isse phle isliye loop khatam ho gya

krne ke bad v repeat krne lageta reverse me

fir 3rd me dalne se phle 2 milna chahiye tha//esa hota h to hi freq ++ krenge nhi to fayada nhi h qki wo kisi me to miss tha
phle check krenge ki koi list phle hi null to nhi pahuch ja rha ,phuch jata h to usko dusre list ke head se suru kra denge (means tmphead1=head2) taki phla wala dusre se just dono ka diff utana pi6e rhega isse kya hoga ki jb dusra null milne pr jb head1 se suru krega to phla just intersection se utna hi duru me rhga jitna ki av dursa hoga so is bar ek ek move me dono intersection me liyega hi.
head1 ka
jayega to is case me last item ko second me dal dena h or fist me decreament krte rhna h qki agar head2 null h mtlb head1 ka last jarur sorted ya max h qki usi ko partition to kiye h isliye max h to second list dal do taki endless loop me na jaye

pata h kth dist ke ander hi hmko shi item mil jayega to isliye k+1 ha heap leneg or har ek pop krne pr ek bacha huwa node dalte jayenge isse logk ho jayega compl //so total complexity O(nlongk) hoga

sbme krke random set kr lenge fir next ko v sudhar dende nextkanext krke

hoga ans since reverse chahiye to final list ko last se traverse krenge final list ke andar ke list ko fisrt se hi traverse krenge
number line me 0 me rkhna h or left jane pr -1 krna h and right jane pr +1 krna h

left ko phle callkrenge fir right ko


push ho jaye ye v dhyan rkhna h

dono= h ya nhi and dono true h ya nhi sb shi rha to wo level and true return kr denge

ayega usko return kr dena h


dfsvisited me visited h ya nhu or usme v milta h matlb cycle h,qki dfs us call se nikla hi nhi or fir mil gya wo ,,nikalta to wo false mark kiya rhta pr esa nhi mila so cycle to h hi //need dfsvisited,parmanentvisited list

index node ko indicate krega and ith value uska source us node ka dist hoga
acyclic hona chahiye //directed isliye ki pata cjhale parent kon chil kon and cyclic isliye ki infinite recursion na ho jaye
krna h//char to int and vis versa krna asan h qki bola h first K char use krega means int=char-'a' wla tarika

You might also like