Longest Common Subsequence LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon DoorDash eBay Facebook Google Indeed MicrosoftViews 68

Problem Statement

Longest Common Subsequence LeetCode Solution – Given two strings text1 and text2, return the length of their longest common subsequenceIf there is no common subsequence, return 0.

subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

  • For example, "ace" is a subsequence of "abcde".

common subsequence of two strings is a subsequence that is common to both strings.

 

Longest Common Subsequence LeetCode SolutionPin

Example 1:

Input: text1 = "abcde", text2 = "ace" 
Output: 3  
Explanation: The longest common subsequence is "ace" and its length is 3.


Example 2:

Input: text1 = "abc", text2 = "abc"
Output: 3
Explanation: The longest common subsequence is "abc" and its length is 3.


Example 3:

Input: text1 = "abc", text2 = "def"
Output: 0
Explanation: There is no such common subsequence, so the result is 0.

Explanation

  • The idea is to use dynamic programming.
  • Create a 2D DP array of n+1*m+1 dimensions
  •  I am using the bottom up dp approach so i have iterated from text1.length()-1 to 0 and text2.length()-1 to 0
  • if the characters match,we do 1+ the diagnal value dp[i+1][j+1]
  • else we find the max between left and bottom value max(dp[i][j+1],dp[i+1][j])
  • return the dp[0][0] as it will have the value for longest common Subsequence

Code

Longest Common Subsequence Leetcode Java Solution:

class Solution {
    public int longestCommonSubsequence(String text1, String text2) {
        int [][]dp = new int[text1.length()+1][text2.length()+1];    
        for(int i= text1.length()-1;i>=0;i--){
            for(int j = text2.length()-1;j>=0;j--){
                char ch1 = text1.charAt(i);
                char ch2 = text2.charAt(j);
                if(ch1==ch2) // diagnal
                dp[i][j]= 1+dp[i+1][j+1];
                else// left,down
                    dp[i][j] = Math.max(dp[i][j+1],dp[i+1][j]);
                    
            }
        }
        return dp[0][0];
    }
}

C++ Solution:

class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        
//         // base case
//         if( text1.length() == 0 || text2.length() == 0) return 0;
        
//         // recursive call
//         if( text1[0] == text2[0]) return 1 + longestCommonSubsequence( text1.substr(1) , text2.substr(1) );
        
//         else return max(  longestCommonSubsequence( text1.substr(1) , text2  ) ,  longestCommonSubsequence( text1  , text2.substr(1) ));
        
        
        int n = text1.length();
        int m = text2.length();
        
        int dp[n+1][m+1];
        
        for( int i = 0 ; i <= m ; i++) dp[0][i] = 0;
        for( int i = 0 ; i <= n ; i++) dp[i][0] = 0;
        
        for(int i = 1 ; i <= n ; i++){
            
            for( int j = 1 ; j <= m ; j++){
                
                if( text1[i-1] == text2[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
                
                else dp[i][j] = max( dp[i][j-1] , dp[i-1][j]) ;
            }
        }
        
        return dp[n][m];
        
        
    }
};

Complexity Analysis:

  • Time Complexity: o(nm) 
  • Space Complexity :o(nm)

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2819
2Java program to find the number of Nodes in a Binary Tree2500
3Reverse a string without affecting special characters2460
4Delete a node of a linked list at given position1976
5Palindrome using Recursion1779
6Insert nodes in a linked list in a sorted way (Ascending Order)1662
7Find elements pair from array whose sum equal to number1645
8Sort Elements by Frequency of Occurrences1631
9Write a program to print all permutations of a given string1605
10Find Minimum Distance Between Two Numbers in an Array1473
11Create a Doubly Linked List1444
12Quick Sort1420
13Reverse an Array1414
14Smallest window in a string containing all characters of another string1395
15Find a Triplet That Sum to a Given Value1356
16Recursively remove all adjacent duplicates1353
17First Repeating Element1337
18Arrange Even and Odd number such that Odd comes after Even1320
19Sum of numbers in String1316
20Smallest Positive Number Missing in an Unsorted Array1283
21Check if the Elements of an Array are Consecutive1253
22Detect a loop in the Linked List1237
23Largest Sum Contiguous Subarray1230
24Quick Sort on SIngly Linked List1214
25Subarray with Given Sum1212
26Print all Possible Combinations of R Elements in a given Array of size N1205
27Recursive function to do substring search1197
28Find the Maximum Repeating Number in Array1155
29Binary Tree Level order traversal in Java1124
30Find the First and Second Smallest Elements1120
31Check if two linked lists are identical1103
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1070
34Find Leaders in an Array1061
35Swap nodes in the linked list1036
36Find the Number Occurring Odd Number of Times in an Array1001
37Arrange given Numbers to Form the Biggest Number II993
38Find the second most frequent character990
39Given a string find its first non-repeating character970
40Find Triplet in Array With a Given Sum964
41Given a sorted array and a number x, find the pair in array whose sum is closest to x954
42Total number of occurrences of a given item in the linked list951
43A Program to check if strings are rotations of each other or not943
44Print all possible words from phone digits934
45Find the Missing Number926
46Rearrange Positive and Negative Numbers Alternatively in Array920
47Longest Palindromic Substring905
48Segregate even and odd nodes in a linked list883
49Print Longest common subsequence882
50Union and Intersection of Two Linked Lists871
51Transform one string to another using minimum number of given operations867
52Rearrange given Array in Maximum Minimum Form846
53Check rearranged string can form a palindrome844
54Count Possible Triangles819
55Iterative Implementation of Quick Sort816
56Multiplication of Two Matrices802
57Check if the linked list is palindrome795
58Count of Triplets With Sum Less than Given Value791
59Rotate a Linked List790
60Stock Buy Sell to Maximize Profit788
61Concatenation of two strings761
62Tug of War760
63Count Number of Substrings with K Distinct Character’s758
64Print all duplicates in the input string753
65Find Nearest Greater and Smaller Element746
66Find Pythagorean Triplets from Array736
67The Celebrity Problem736
68Reverse String Without Temporary Variable734
69Remove ‘b’ and ‘ac’ from a given string728
70Find all Common Elements in Given Three Sorted Arrays727
71Remove all duplicates in an unsorted linked list709
72Find the Row with Maximum Number of 1’s706
73Find the Peak Element from an Array699
74Find the subarray whose sum is equal to a given number X696
75Remove Minimum Characters so that Two Strings Become Anagrams689
76Find Smallest Missing Number in a Sorted Array687
77Insertion Sort686
78A Product Array Puzzle685
79Addition of Two Matrices682
80Implement Two Stacks in an Array676
81Generate all Binary Strings Without Consecutive 1’s672
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II658
84Lexicographic rank of string652
85Check if Two given Matrices are Identical644
86Multiplication of Previous and Next644
87Subtraction of Two Matrices632
88Merge K Sorted Arrays and Print Sorted Output631
89Move All the Zeros to the End of the Given Array627
90Online Algorithm for Checking Palindrome in a Stream624
91Form Minimum Number from Given Sequence of D’s and I’s622
92Divide a string in N equal parts622
93Check whether two strings are anagram of each other614
94Maximum Circular Subarray Sum613
95Remove recurring digits in a given number609
96Sort a stack using a temporary stack608
97Sort a linked list that is sorted alternating ascending and descending607
98Find the Minimum Element in a Sorted and Rotated Array604
99Move last element of the Linked List at first place601
100Subarray and Subsequence599
101First Circular Tour to Visit all the Petrol Bunks599
102Largest Subarray with Equal Number of 0’s and 1’s597
103Compare two strings(linked lists)592
104Flattening a linked list590
105Maximum Element in an Array which is Increasing and then Decreasing589
106Palindrome Permutations of a String584
107Elements Appear more than N/K times in Array581
108Majority Element576
109Run length encoding574
110Minimum insertions to form a shortest palindrome573
111Print all permutations with repetition572
112Palindromes in a given range571
113Pangram Checking570
114Merge a linked list into another at alternate positions568
115Minimum Characters to be Added at Front to Make String Palindrome564
116Remove all duplicates in a sorted linked list563
117Rearrange a given linked list in-place562
118Minimum number of Merge Operations to make an Array Palindrome560
119Most repeating character in a string558
120Rotate string to get lexicographically minimum string557
121Repeated Subsequence of Length Two or More556
122Print all anagrams together in a sequence of words552
123Reorder an Array According to the Given Indexes550
124Pancake Sorting Problem542
125Merge Overlapping Intervals II539
126Two Sum Leetcode Solution539
127Clone a Linked List with next and random pointer536
128Size of The Subarray With Maximum Sum528
129Transpose of a Matrix524
130Removing Spaces from a String using stringstream521
131Remove Extra Spaces from a String520
132Remove duplicates from a string519
133Check if a given string is a rotation of a palindrome519
134Smallest Palindrome after Replacement518
135Partition Problem517
136Maximum Sum Increasing Subsequence514
137Longest Palindrome can be Formed by Removing or Rearranging Characters513
138Check whether Strings are K Distance Apart or Not502
139Generate all Binary Strings from Given Pattern502
140Delete Last Occurrence501
141Length of Longest valid Substring499
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized499
143Insert Node in the Sorted Linked List498
1443Sum Leetcode Solution498
145Check if Two given Strings are Isomorphic to each other494
146Maximum difference between two elements such as larger element comes after smaller487
147Program to Toggle all Characters in a String483
148Given string is interleaving of two other strings or not482
149Count Minimum Steps to Get the given Array480
150Number of Smaller Elements on Right Side477
151Merge sort better than quick sort for linked lists477
152Find Pair with Given Difference472
153Check if all Rows of a Matrix are Circular Rotations of Each Other471
154Check length of a String is Equal to the Number Appended at its Last470
155Longest Common Prefix using Divide and Conquer468
156Find nth node of the Linked list from the end466
157Find a Fixed Point in a Given Array463
158Sort 0s 1s and 2s in an Array458
159Print all interleavings of given two strings457
160Compare Two Version Numbers456
161Reverse words in a given string455
162Merge two sorted linked lists such that merged list is in reverse order453
163Find the Subarray of given length with Least Average452
164Reorder Array Using Given Indexes451
165Split linked list using alternate nodes450
166Median of Two Sorted Arrays LeetCode Solution450
167Print Reverse of a string (Recursion)448
168Find K Length Subarray of Maximum Average439
169Print string of odd length in ‘X’ format436
170Find Element Using Binary Search in Sorted Array433
171Swap Kth Node from beginning with Kth Node from End432
172Print all Palindromic Partitions of a String430
173Find Duplicates in an Array in Most Efficient Way428
174print all palindromic partitions421
175Maximum Length of Chain Pairs417
176Flatten a multilevel linked list415
177Shortest Superstring Problem415
178Check if String Follows Order of Characters by a Pattern or not412
179Sorting a K Sorted Array409
180Sort a String According to Another String404
181Longest Span with same Sum in two Binary Arrays II398
182Reverse a Linked List in groups395
183Find a Sorted Subsequence of size 3393
184Program to add two binary digits390
185Recursively print all the sentences that can be formed from list of word lists388
186Find the two Numbers with Odd Occurrences in an Unsorted Array387
187Longest Common Prefix Using Binary Search II385
188Reverse a Singly Linked List (Iterative/Non-Recursive)382
189Caesar Cipher378
190Check if String can Become Empty by Recursively Deleting given Substring377
191Rearrange a linked list in Zig-Zag377
192Kth Non-repeating Character377
193Pancake Sorting373
194Rotate Image by 90 degrees371
195Longest Common Prefix Word by Word Matching370
196Perfect Reversible String366
197Permutations of a Given String Using STL364
198Merging Two Sorted Arrays362
199Find the point where a monotonically increasing function becomes positive first time361
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes361
201Increasing Subsequence of Length three with Maximum Product361
202Find First non-repeating character in a string358
2031`s and 2`s complement of binary number357
204Sort a linked list with 0s, 1s and 2s357
205Four Elements that Sum to Given353
206List items containing all characters of a given word352
207Delete N nodes after M351
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Split a string342
211Palindrome string (number)342
212Minimum Characters to be Removed to Make a Binary String Alternate340
213Recursive Implementation of atoi()333
214Check if a Linked list of Strings form a Palindrome333
215Print All Distinct Elements of the Array332
216Sorting the array of strings330
217Convert a String that is Repetition of a Substring of Length K330
218Even Substring Count326
219Maximum occurring character in a string326
220Find the first Repeating Number in a Given Array326
221Valid Parentheses LeetCode Solution326
222Reverse a singly linked list recursively325
223Binary Tree to Doubly linked list323
224Can we reverse a linked list in less than O(n) time ?323
225Print Shortest Path to Print a String on Screen322
226Convert string1 to string2 in one edit319
227Maximum Subarray Leetcode Solution319
228Reverse a String using Stack318
229Nth Character in Concatenated Decimal String318
230wildcard character matching318
231Sort Elements by Frequency II317
232Lower Case To Upper Case314
233Count the number of words313
234Merge Two Sorted Arrays311
235Find the Lost Element From a Duplicated Array310
236Split Four Distinct Strings309
237Find middle of the Linked List307
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets301
240Matrix Chain Multiplication using Dynamic Programming297
241Next Greater Element in an Array294
242Palindrome Permutation290
243Roman to Integer Leetcode Solution285
244Find Nth Node285
245Find All Pairs With a Given Difference283
246Searching a node in a Binary Search Tree283
247Delete a Tree280
248Triplet from three linked lists with given sum280
249String(represents an integer) to value278
250Print all Possible Ways to Break a String in Bracket Form277
251Reverse a String276
252Reverse Bits275
253Binary Tree273
254Word Search Leetcode Solution273
255Delete a node under given conditions272
256How to Efficiently Implement k Stacks in a Single Array?272
257Change Gender of a given String271
258Sort an array of strings270
259Count Pairs With Given Sum269
260Meeting Rooms II LeetCode Solution268
261Number of sub-strings which recursively add up to 9268
262Longest Common Extension267
263First non Repeating Element267
264Remove middle points in a linked list of line segments265
265Toeplitz Matrix263
266Repeated Substring Pattern263
267Remove spaces from a string262
268Longest Palindromic Substring LeetCode Solution262
269Move all negative elements to one side of array262
270Shuffle a given Array258
271N queen problem257
272Min Stack256
273Number of Islands LeetCode Solution252
274Find, second, frequent, character251
275Dijkstra Algorithm251
276House Robber Leetcode Solution250
277Cuckoo sequence program250
278Clone a linked list with next and random pointer (Hashing)248
279Max stack248
280Most Frequent Element in an Array247
281Search Insert Position Leetcode Solution246
282Sort linked which is sorted on absolute values245
283Minimize the maximum difference between the heights245
284Expression Evaluation244
285Subset Leetcode242
286KMP Algorithm241
287Valid Palindrome Leetcode Solution241
288Plus One Leetcode Solution241
289Evaluation of Postfix Expression240
290Fibonacci numbers240
291Word Search239
292Min Stack Leetcode Solution239
293Sudoku Solver239
294Reverse words in a string239
295How to Delete a Linked List238
296Combination Sum Leetcode Solution236
297Number Of 1 bits236
298Merge Sorted Arrays Leetcode Solution233
299Backspace String Compare230
300Subarray with 0 sum230
301Set Matrix Zeroes230
302Sqrt(x) Leetcode Solution230
303Rabin Karp Algorithm228
304Contains Duplicate II Leetcode Solution228
305Pair of Positive Negative Values in an Array227
306Reversing a Queue227
307Product of array except self225
308Tower Of Hanoi225
309Combination Sum224
310Integer to Roman Leetcode Solution223
311Common elements in all rows of a given matrix223
312Pascal Triangle Leetcode223
313String Compression222
314Delete middle element of a stack222
315Intersection of Two Arrays II Leetcode Solution220
316Minimum swaps required to bring all elements less than or equal to k together220
317Count subarrays with equal number of 1’s and 0’s220
318Reverse individual words218
319Pow(x, n) Leetcode Solution217
320Sliding Window Technique217
321Implementation of Deque using Doubly Linked List217
322Single Number Leetcode Solution217
323Add Binary Leetcode Solution217
324Segregate even and odd numbers217
325Arithmetic Expression Evaluation217
326Find Top K (or Most Frequent) Numbers in a Stream216
327Second Most Repeated Word in a Sequence216
328Construct Binary Tree from Given Inorder and Preorder Traversals216
329Bellman Ford Algorithm215
330Palindrome Linked List Leetcode Solution214
331Next Permutation213
332Count of index pairs with equal elements in an array213
333Design a stack that supports getMin() in O(1) time and O(1) extra space213
334Count Odd Numbers in an Interval Range Leetcode Solution213
335Maximum Number of Balloons Leetcode Solution212
336Contains Duplicate212
337Third Maximum Number Leetcode Solution211
338Kruskal Algorithm211
339Page Replacement Algorithms in Operating Systems211
340Minimum Value to Get Positive Step by Step Sum Leetcode Solution211
341Sort elements by frequency210
342Postfix to Infix Conversion210
343Find sum of non-repeating elements (distinct) elements in an array209
344Find Lucky Integer in an Array Leetcode Solution208
345Permutations Leetcode Solution208
346Longest Common Prefix Leetcode Solution208
347K-th Smallest Element in a Sorted Matrix208
348Convex Hull Algorithm207
349Find the Town Judge Leetcode Solution207
350Group Words With Same Set of Characters207
351Sum of minimum and maximum elements of all subarrays of size k206
352Maximum Subarray206
353Find Numbers with Even Number of Digits Leetcode Solution206
354Majority Element Leetcode Solution206
355Longest Substring Without Repeating Characters LeetCode Solution205
356Spiral Matrix LeetCode Solution204
357Swap Nodes in Pairs Leetcode Solutions204
358Minimum operation to make all elements equal in array204
359Sorting array using Stacks204
360Scramble String204
361First element occurring k times in an array203
362Top K Frequent Words203
363Count Primes Leetcode Solutions203
364Smallest Subarray with k Distinct Numbers203
365Count subarrays having total distinct elements same as original array202
366Given two unsorted arrays find all pairs whose sum is x201
367Check if two arrays are equal or not201
368Evaluate Division201
369Merge Two Sorted Lists Leetcode Solutions200
370Prefix to Infix Conversion200
371Minimum Path Sum200
372Best Time to Buy and Sell Stock  II Leetcode Solution200
373Special Number200
374Power of Two Leetcode Solution200
375Reverse a Number Using Stack199
376Fizz Buzz Leetcode199
377Pascal’s Triangle II Leetcode Solution198
378Reversing the First K elements of a Queue198
379Search in Rotated Sorted Array Leetcode Solution198
380Number of Good Pairs Leetcode Solution198
381Group Anagrams198
382House Robber II Leetcode Solution198
383Find duplicates in a given array when elements are not limited to a range197
384Minimum Steps to reach target by a Knight197
385Maximal Square197
386Missing Number Leetcode Solution197
387Find All Numbers Disappeared in an Array Leetcode Solution197
388Minimum Absolute Difference Leetcode Solution196
389Matrix Diagonal Sum Leetcode Solution196
390Leetcode Permutations196
391Huffman Coding196
392Maximum possible difference of two subsets of an array196
393Running Sum of 1d Array Leetcode Solution195
394How to Implement Stack Using Priority Queue or Heap?195
395Maximum Distance Between two Occurrences of Same Element in Array195
396Unique Paths Leetcode Solution195
397Top K Frequent Elements195
398Check if Array Contains Contiguous Integers With Duplicates Allowed194
399Coin Change 2 Leetcode Solution194
400Sorting using trivial hash function193
401Expression Contains Redundant Bracket or Not193
402Find The Duplicate Number193
403Single Number193
404Max Consecutive Ones Leetcode Solution193
405Remove Duplicates from Sorted Array Leetcode Solution193
406How Many Numbers Are Smaller Than the Current Number Leetcode Solution192
407Range Sum Query 2D – Immutable Leetcode Solution192
408Sort Integers by The Number of 1 Bit Leetcode Solution192
409Subarray Sum Equals k192
410Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution192
411Sort Array by Increasing Frequency Leetcode Solution192
412Find Number of Employees Under every Employee191
413Decode String191
414Unique Paths191
415Fibonacci Number LeetCode Solution191
416Subarray Sum Equals K LeetCode Solution191
417Smallest Element Repeated Exactly K Times191
418Happy Number Leetcode Solution191
419Reverse Vowels of a String Leetcode Solution190
420Zigzag Conversion190
421Find the Closest Palindrome number190
422Reverse Integer190
423Find Median from data Stream190
424Monotonic Array LeetCode Solution190
425Subtract the Product and Sum of Digits of an Integer Leetcode Solution190
426Find Winner on a Tic Tac Toe Game Leetcode Solution190
427Subset sum problem189
428Nth Catalan Number189
429Delete a Node from linked list without head pointer189
430Difference between highest and least frequencies in an array189
431Cumulative Frequency of Count of Each Element in an Unsorted Array189
432Shuffle the Array Leetcode Solution189
433Count Substrings with equal number of 0s, 1s and 2s188
434Best Time to Buy and Sell Stock III Leetcode Solution188
435LRU Cache Implementation188
436Implement Stack and Queue using Deque188
437Palindrome Substring Queries188
438Trapping Rain Water Leetcode Solution188
439Length of the largest subarray with contiguous elements188
440Letter Case Permutation187
441Print All Distinct Elements of a Given Integer Array187
442Check If N and Its Double Exist Leetcode Solution187
443Find top three repeated in array187
444Reverse Words in a String III LeetCode Solution187
445Subarrays with distinct elements187
446Maximum Depth of Binary Tree Leetcode Solution187
447Convert String To Int187
448Capacity To Ship Packages Within D Days Leetcode Solution186
449Find all pairs (a, b) in an array such that a % b = k186
450Find the Duplicate Element186
451Sort a stack using recursion186
452Minimum Moves to Equal Array Elements Leetcode Solution186
453Integer to English words186
454The K Weakest Rows in a Matrix Leetcode Solution186
455Kth largest element in an Array Leetcode Solutions186
456Iterative Tower of Hanoi185
457Reverse a Stack Using Recursion185
458Bipartite Graph185
459Excel Sheet Column Number Leetcode Solution185
460Find the first repeating element in an array of integers185
461Merge Two Sorted Linked Lists184
462Generate a String With Characters That Have Odd Counts Leetcode Solution184
463Find Minimum In Rotated Sorted Array184
464Concatenation of Array LeetCode Solution184
465Sorting a Queue without Extra Space184
466Prim’s Algorithm184
467Count pairs from two linked lists whose sum is equal to a given value184
468Find First and Last Position of Element in Sorted Array Leetcode Solution183
469Priority Queue Using Singly Linked List183
470Find the Difference Leetcode Solution183
471Floyd Warshall Algorithm183
472Multiply Strings Leetcode Solution182
473Move Zeroes LeetCode Solution182
474Kth Largest Element in a Stream Leetcode Solution182
475Find Common Characters Leetcode Solution182
476Sum of Subarray Ranges Leetcode Solution182
477Reverse a String182
478Slowest Key Leetcode Solution182
479Flood Fill LeetCode182
480Next Greater Element I Leetcode Solution182
481Longest Common Subsequence182
482Edit Distance182
483Text Justification LeetCode Solution181
484Word Ladder LeetCode Solution181
485Number of Steps to Reduce a Number to Zero Leetcode Solution181
486Count and Say181
487Merge Overlapping Intervals181
488Remove Minimum Number of Elements Such That no Common Element Exist in both Array181
489Find elements which are present in first array and not in second181
490Fizz Buzz181
491Print all subarrays with 0 sum180
492Zigzag Conversion LeetCode Solution180
493Balanced Binary Tree Leetcode Solution180
494MiniMax Algorithm180
495Kids With the Greatest Number of Candies Leetcode Solution180
496Longest Common Prefix using Trie180
497Target Sum180
498Degree of an array180
499Reverse a linked list180
500Top View of Binary Tree180
501Jump Game Leetcode Solution179
502Design Parking System Leetcode Solution179
503Convert array into Zig-Zag fashion179
504Longest subarray not having more than K distinct elements178
505Find subarray with given sum (Handles Negative Numbers)178
506Pair with given product178
507Intersection of Two Arrays178
508Peak Index in a Mountain Array178
509Length of Last Word Leetcode Solution177
510Check if a given array contains duplicate elements within k distance from each other177
511Valid Parenthesis String177
512Priority Queue in C++177
513Max Area of Island177
514Count and Say Leetcode Solution177
515Last Stone Weight177
516Shortest Palindrome176
517Find four elements that sum to a given value (Hashmap)176
518Shuffle String Leetcode Solution176
519Find missing elements of a range176
520Koko Eating Bananas Leetcode Solution176
521Find Index of Closing Bracket for a Given Opening Bracket in an Expression176
522The Stock Span Problem176
523Postfix to Prefix Conversion176
524Prefix to Postfix Conversion176
525Find N Unique Integers Sum up to Zero Leetcode Solution176
526Longest Common Prefix using Sorting175
527Mobile Numeric Keypad Problem175
528Relative Sort Array Leetcode Solution174
529N-th Tribonacci Number Leetcode Solution174
530Find distinct elements common to all rows of a matrix174
531Count number of triplets with product equal to given number174
532Implementation of Deque using circular array174
533Find any one of the multiple repeating elements in read only array174
534Smallest Subarray With all Occurrences of a Most Frequent Element174
535Contiguous Array Leetcode174
536Recursion174
537Implement a stack using single queue174
538Iterative Inorder Traversal of a Binary Tree174
539K-th Distinct Element in an Array174
540Substring With Concatenation Of All Words174
541Excel Sheet Column Title Leetcode Solution173
542Valid Sudoku173
543Best Time to Buy and Sell Stock173
544Implement Stack using Queues173
545Container with Most Water173
546Largest Perimeter Triangle Leetcode Solution173
547Delete Node in a Linked List Leetcode Solution173
548Build Array From Permutation Leetcode Solution173
549Valid Anagrams173
550Is Subsequence Leetcode Solution173
551Minimum Operations to convert X to Y173
552Jewels and Stones Leetcode Solution172
553Next Greater Frequency Element172
554Maximum sum rectangle in a 2D matrix172
555First negative integer in every window of size k172
556Sum of Left Leaves Leetcode Solutions172
557Linked List Cycle II LeetCode Solution172
558Island Perimeter Leetcode Solution172
559Isomorphic Strings Leetcode Solution172
56001 Matrix LeetCode Solution172
561Distribute Candies to People Leetcode Solution171
562Trapping Rain Water LeetCode Solution171
563Remove Linked List Elements Leetcode Solution171
564Find Words That Can Be Formed by Characters Leetcode Solution171
565Minimum Delete Operations to make all Elements of Array Same171
566Convert Sorted Array to Binary Search Tree Leetcode Solution171
567Convert a normal BST to Balanced BST171
568Arrange given numbers to form the biggest number170
569Shuffle an Array170
570Hamming Distance170
571Assign Cookies Leetcode Solution170
572Rearrange a binary string as alternate x and y occurrences170
573Count the number of nodes at given level in a tree using BFS170
574Minimum Bracket Reversals170
575The Knapsack Problem169
576Insert Interval Leetcode Solution169
577Check for Balanced Parentheses in an Expression169
578Gold Mine Problem169
5793Sum Closest LeetCode Solution169
580Count all subsequences having product less than K169
581Integer to Roman169
582Maximum path sum in a triangle169
583Minimum Knight Moves LeetCode Solution168
584Find the smallest positive integer value that cannot be represented as sum of any subset of a given array168
585Change the Array into Permutation of Numbers From 1 to N168
586Group Multiple Occurrence of Array Elements Ordered by first Occurrence168
587Summary Ranges Leetcode Solution168
588Shortest Path in a Grid with Obstacles Elimination LeetCode Solution168
589Minimum number of distinct elements after removing m items168
590How to check if two given sets are disjoint?167
591XOR Operation in an Array Leetcode Solution167
592Permutation in String Leetcode Solution167
593K Empty Slots LeetCode167
594Unique Binary Search Trees167
595LRU Cache LeetCode Solution167
596Rotate List Leetcode Solution167
597Decode Ways167
598Same Tree LeetCode Solution166
599Rotate Image LeetCode Solution166
600Sieve of Eratosthenes166
601Maximum Distance in Array166
602Combinations Leetcode Solution166
603Distance Between Bus Stops Leetcode Solution166
604Stone Game LeetCode165
605Printing brackets in Matrix Chain Multiplication Problem165
606Word Pattern165
607Find if an Expression has Duplicate Parenthesis or Not165
608Sort Characters By Frequency LeetCode Solution165
609Find minimum difference between any two elements165
610Maximum difference between first and last indexes of an element in array165
611Remove All Occurrences of a Substring LeetCode Solution165
612License Key Formatting Leetcode Solution165
613Frog Jump Leetcode Solution165
614Find Sum of all unique sub-array sum for a given array164
615Minimum number of subsets with distinct elements164
616Painting Fence Algorithm164
617Segregate 0s and 1s in an Array164
618Best Time to Buy and Sell Stock LeetCode Solution164
619Word Wrap Problem164
620Minimum insertions to form a palindrome with permutations allowed164
621Replace Elements with Greatest Element on Right Side Leetcode Solution164
622Sort Array By Parity LeetCode Solution163
623Applications of Breadth First Search and Depth First Search163
624Minimum Depth of Binary Tree Leetcode Solution163
625Smallest Good Base163
626Defanging an IP Address Leetcode Solution163
627Maximum Number of Chocolates to be Distributed Equally Among k Students163
628Find Maximum Level sum in Binary Tree162
629Find the Duplicate Number LeetCode Solution162
630Distance of nearest cell having 1 in a binary matrix162
631Kth Missing Positive Number Leetcode Solution162
632House Robber162
633Coin Change Problem162
634Valid Palindrome II Leetcode Solution161
635Minimum Cost to Hire K Workers161
636Longest Substring with At Most K Distinct Characters LeetCode Solution161
637Iterative Method to find Height of Binary Tree161
638Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
639Tracking current Maximum Element in a Stack161
640Longest Increasing Subsequence160
641Isomorphic Strings160
642GCD Of Two Numbers160
643Delete consecutive same words in a sequence160
644Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions160
645Optimal Account Balancing LeetCode Solution160
646Sum of All Odd Length Subarrays Leetcode Solution160
647Count Good Nodes in Binary Tree Leetcode Solution160
648Maximum Consecutive Numbers Present in an Array160
649Non-overlapping sum of two sets160
650Binary Tree Zigzag Level Order Traversal LeetCode Solution160
651Power of Four Leetcode Solution160
652Best Time to Buy and Sell Stock with Cooldown Leetcode Solution159
653Check If It Is a Straight Line Leetcode Solution159
654K Empty Slots159
655Merge Two Balanced Binary Search Trees159
656Ugly Number Leetcode Solution159
657Number of Provinces Leetcode Solution159
658Moving Average from Data Stream Leetcode Solution159
659Reverse a stack without using extra space in O(n)159
660Check if a queue can be sorted into another queue using a stack158
661Wiggle Sort158
662Check If Two String Arrays are Equivalent Leetcode Solution158
663Number of Dice Rolls With Target Sum LeetCode Solution158
664Queries for counts of array elements with values in given range158
665String to Integer (atoi) LeetCode Solution158
666Strobogrammatic Number LeetCode Solution158
667Letter Combinations of a Phone Number158
668Convert an array to reduced form158
669Largest Sum Contiguous Subarray158
670Reverse Only Letters LeetCode Solution158
671Maximum Number of Coins You Can Get Leetcode Solution158
672Reorganize String157
673Inorder Successor of a node in Binary Tree157
674Longest Increasing Path in a Matrix LeetCode Solution157
675Construct BST from given Preorder Traversal157
676Increasing Decreasing String Leetcode Solution157
677Subset Sum Leetcode157
678Sum of f(a[i], a[j]) over all pairs in an array of n integers157
679Employee Free Time LeetCode Solution157
680Form minimum number from given sequence157
681To Lower Case Leetcode Solution157
682How to Create Mergable Stack?157
683Find Largest d in Array such that a + b + c = d157
684Reducing Dishes LeetCode Solution157
685Find the Smallest Divisor given a Threshold Leetcode Solution157
686Path With Maximum Minimum Value LeetCode Solution157
687Lucky Numbers in a Matrix Leetcode Solution157
688Longest Substring with At Least K Repeating Characters LeetCode Solution157
689Flipping an Image LeetCode Solution157
690Print the Fibonacci numbers in reverse order157
691Partition Labels LeetCode Solution157
692Unique Paths II Leetcode Solution156
693Reversing a Queue using Recursion156
694Maximum Number of Occurrences of a Substring Leetcode Solution156
695Find the Distance Value Between Two Arrays Leetcode Solution156
696Valid Perfect Square Leetcode Solution156
697Find Leaves of Binary Tree LeetCode Solution156
698Find whether an array is subset of another array156
699Valid Palindrome156
700Edit Distance LeetCode Solution155
701Maximum Product of Two Elements in an Array Leetcode Solution155
702Merge Two Binary Trees LeetCode Solution155
703Dynamic Programming Basics155
704Delete Nth node from the end of the given linked list155
705Remove Invalid Parentheses Leetcode Solution155
706BFS vs DFS for Binary Tree155
707Reservoir Sampling155
708Permutation Sequence LeetCode Solution155
709Partition Array Into Three Parts With Equal Sum Leetcode Solution155
710Binary Tree zigzag level order Traversal155
711Majority Element II Leetcode Solution155
712Populating Next Right Pointers in Each Node155
713Robot Room Cleaner Leetcode Solution155
714Recover Binary Search Tree155
715Keyboard Row Leetcode Solution154
716Rank Transform of an Array Leetcode Solution154
717Find pairs with given sum such that elements of pair are in different rows154
718Decompress Run-Length Encoded List Leetcode Solution154
719Find the node with minimum value in a Binary Search Tree154
720Restore IP Addresses Leetcode Solution154
721Add and Search Word – Data structure design LeetCode154
722Hamming Distance Leetcode Solution154
723Maximum Product of Three Numbers LeetCode Solution154
724Sort Array by Increasing Frequency Leetcode Solution154
725Numbers with prime frequencies greater than or equal to k153
726Convert a Number to Hexadecimal Leetcode Solution153
727Factorial Trailing Zeroes Leetcode Solution153
728Stack Permutations (Check if an array is stack permutation of other)152
729Best Meeting Point LeetCode Solution152
730Bulb Switcher LeetCode Solution152
731String Compression LeetCode Solution152
732Longest Span with same Sum in two Binary arrays152
733Deletion in a Binary Tree152
734Find unique character in a string152
735Queue based approach for first non-repeating character in a stream152
736Check If Array Pairs Are Divisible by k LeetCode Solution151
737Search in a Binary Search Tree Leetcode Solution151
738Minimum Height Trees151
739Race Car LeetCode Solution151
740Word Pattern LeetCode Solution151
741Generate all possible sorted arrays from alternate elements of two given sorted arrays151
742Symmetric Tree Leetcode Solution151
743Binomial Coefficient151
744Maximum 69 Number Leetcode Solution151
745Non-decreasing Array LeetCode Solution151
746Find the largest multiple of 3151
747Find Median from Data Stream LeetCode Solution151
748Minimum Distance Between BST Nodes Leetcode Solution151
749Find Maximum Depth of Nested Parenthesis in a String151
750Binary Tree Maximum Path Sum LeetCode Solution151
751Finding K closest element151
752Largest subarray with equal number of 0s and 1s151
753Find All Duplicates in an Array LeetCode Solution151
754Sorted Linked List to Balanced BST151
755Invert Binary Tree LeetCode Solution151
756Linked List Cycle151
757Count quadruples from four sorted arrays whose sum is equal to a given value x150
758Perform String Shifts Leetcode150
759Minimum Cost For Tickets Leetcode Solution150
760Find if Path Exists in Graph Leetcode Solution150
761Maximum Length of a Concatenated String with Unique Characters Leetcode Solution150
762Find Pair with Greatest Product in Array150
763k-th missing element in increasing sequence which is not present in a given sequence150
764Minimize Maximum Pair Sum in Array LeetCode Solution150
765Remove Nth Node From End of List Leetcode Solution150
766N-Queens LeetCode Solution150
767First Unique Character in a String LeetCode Solution150
768Bubble sort using two Stacks150
769Number of Islands II LeetCode Solution150
770Remove Duplicates from Sorted List LeetCode Solution150
771Student Attendance Record I Leetcode Solution150
772Largest rectangular sub-matrix whose sum is 0149
773Kth ancestor of a node in binary tree149
774Split a String in Balanced Strings Leetcode Solution149
775Merge K Sorted Linked Lists149
776Morris Traversal149
777Search a 2D Matrix II Leetcode Solution149
778Elements to be added so that all elements of a range are present in array149
779Maximum Depth of N-ary Tree Leetcode Solution149
780Maximum Difference Between Increasing Elements LeetCode Solution149
781Growable array based stack149
782Jump Game149
783Evaluate Reverse Polish Notation LeetCode Solution149
784Diagonal Traversal of Binary Tree149
785Valid Number148
786Number Complement Leetcode Solution148
787Minimum time required to rot all oranges148
788Program for Bridge and Torch problem148
789Minimum Time Visiting All Points Leetcode Solution148
790Snakes and Ladders LeetCode Solution148
791Remove brackets from an algebraic string containing + and – operators148
792Relative Ranks Leetcode Solution147
793Minimum number of jumps to reach end147
794Final Prices With a Special Discount in a Shop Leetcode Solution147
795Get Maximum in Generated Array Leetcode Solution147
796Special Array With X Elements Greater Than or Equal X Leetcode Solution147
797Check if Two Expressions With Brackets are Same147
798Number of NGEs to the Right147
799Merge Sorted Array LeetCode Solution147
800Count items common to both the lists but with different prices147
801Sort an array according to the order defined by another array147
802Transpose Graph147
803Largest Rectangle in Histogram LeetCode Solution147
804Nearest Exit from Entrance in Maze LeetCode Solution147
805Check for Palindrome after every character replacement Query147
806Remove Duplicates from Sorted List II147
807Nested List Weight Sum II LeetCode Solution147
808Convert BST to Min Heap146
809Reorder Data in Log Files LeetCode Solution146
810Crawler Log Folder Leetcode Solution146
811One Edit Distance LeetCode Solution146
812Print a Binary Tree in Vertical Order146
813Minimum Number of Taps to Open to Water a Garden LeetCode Solution146
814Tiling Problem146
815Regular Expression Matching146
816Sort Colors146
817Friends Pairing Problem146
818Longest Subarray Having Count of 1s One More than Count of 0s146
819Minimum Jumps to Reach Home LeetCode Solution146
820String comparison containing wildcards146
821Base 7 Leetcode Solution146
822A Space Optimized DP solution for 0-1 Knapsack Problem146
823Sort Array By Parity II Leetcode Solution146
824Interval Tree146
825Circular Queue146
826Partition to K Equal Sum Subsets Leetcode Solution146
827Clone Graph LeetCode Solution145
828Alien Dictionary LeetCode Solution145
829Subsequence of Size K With the Largest Even Sum LeetCode Solution145
830Find the subarray with least average145
831Minimum swaps to make sequences increasing145
832Maximum Profit in Job Scheduling Leetcode Solution145
833Sorted Array to Balanced BST145
834Path with maximum average value145
835Check if a given array can represent Preorder Traversal of Binary Search Tree145
836Subarray Product Less Than K LeetCode Solution145
837Priority Queue using doubly linked list144
838Total Numbers With no Repeated Digits in a Range144
839Insert into a Binary Search Tree Leetcode Solution144
840Find the Only Repetitive Element Between 1 to N-1144
841Level order Traversal in Spiral Form144
842Partition List Leetcode Solution144
843Course Schedule II – LeetCode144
844Minimum Swaps to Make Strings Equal Leetcode Solution144
845Guess Number Higher or Lower LeetCode Solution144
846Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution144
847Last Stone Weight II LeetCode Solution144
848Count Distinct Elements in Every Window of Size K144
849Brightest Position on Street LeetCode Solution144
850Maximum size subarray sum equals k144
851Design a Stack With Increment Operation Leetcode Solution144
852Iterative Preorder Traversal144
853Repeated Substring Pattern LeetCode Solution143
854Find all triplets with zero sum143
855Permutation Coefficient143
856Top K Frequent Words LeetCode Solution143
857Subset with sum divisible by m143
858Union and Intersection of two Linked Lists143
859Maximum Nesting Depth of the Parentheses Leetcode Solution143
860Can Place Flowers LeetCode Solution143
861Valid Parentheses Leetcode Solution143
862Minimum Sum Path in a Triangle143
863Water Bottles Leetcode Solution142
864Lemonade Change Leetcode Solution142
865Given an Array of Pairs Find all Symmetric Pairs in it142
866Find All Possible Recipes from Given Supplies LeetCode Solution142
867Brick Wall LeetCode Solution142
868Three way partitioning of an array around a given range142
869Check if an Array is Stack Sortable142
870Check whether a given Binary Tree is Complete or not142
871Least Number of Unique Integers after K Removals Leetcode Solution141
872GCDs of given index ranges in an array141
873Daily Temperatures Leetcode Solution141
874Rearrange Spaces Between Words Leetcode Solution141
875Range sum queries without updates141
876Design Browser History LeetCode Solution141
877Binary Search Tree Search and Insertion141
878Sum of nearest smaller and greater number141
879Tree Traversal (Preorder, Inorder & Postorder)141
880Spiral Matrix II Leetcode Solution141
8814Sum141
882Form Minimum Number From Given Sequence141
883Balanced Expression with Replacement141
884Matrix Chain Multiplication141
885Count ways to reach the nth stair using step 1, 2 or 3141
886Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution141
887LCS (Longest Common Subsequence) of three strings141
888Missing Element in Sorted Array LeetCode Solution140
889Sequences of given length where every element is more than or equal to twice of previous140
890Special Positions in a Binary Matrix Leetcode Solution140
891Diagonal Traversal LeetCode Solution140
892BFS for Disconnected Graph140
893Robot Bounded In Circle LeetCode Solution140
894Construct Complete Binary Tree from its Linked List Representation140
895Distinct adjacent elements in an array140
896Identify and Mark Unmatched Parenthesis in an Expression140
897Count Negative Numbers in a Sorted Matrix LeetCode Solution140
898Delete And Earn140
899Find all permuted rows of a given row in a matrix140
900Count Subarrays with Same Even and Odd Elements140
901Destination City Leetcode Solution140
902Maximum Score After Splitting a String Leetcode Solution140
903Insert Delete GetRandom140
904Shortest Word Distance Leetcode Solution140
905Queries for GCD of all numbers of an array except elements in a given range140
906Guess Number Higher or Lower II140
907Number of Days Between Two Dates LeetCode Solution140
908An Interesting Method to generate Binary Numbers from 1 to n140
909Check if stack elements are pairwise consecutive139
910Find Maximum Sum Possible Equal Sum of Three Stacks139
911Convert Sorted List to Binary Search Tree139
912Rearrange an Array Such that arr[i] is equal to i139
913Check if the given array can represent Level Order Traversal of Binary Search Tree139
914Time Based Key-Value Store LeetCode Solution139
915A program to check if a binary tree is BST or not139
916Minimum sum of multiplications of n numbers139
917Alien Dictionary139
918Set Matrix Zeroes Leetcode Solution139
919Range LCM Queries138
920Find distance between two nodes of a Binary Tree138
921Palindrome Partitioning Leetcode Solution138
922Number of Distinct Islands Leetcode Solution138
923Analyze User Website Visit Pattern LeetCode Solution138
924Diagonal Traverse LeetCode Solution138
925Find Common Characters Leetcode Solution138
926Vertical sum in a given binary tree138
927Spiral Matrix III LeetCode Solution137
928Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i137
929Longest Palindromic Subsequence137
930Stone Game II Leetcode137
931Merge Two Sorted Lists Leetcode137
932Remove Duplicates from Sorted List II LeetCode Solution137
933Merging Intervals137
934Maximize Sum of Array after K Negations Leetcode Solution136
935Intersection of Two Linked Lists LeetCode Solution136
936Maximum Frequency Stack Leetcode Solution136
937Infix to Postfix136
938Sliding Window Maximum136
939Construct the Rectangle Leetcode Solution136
940Maximum Subarray Sum Excluding Certain Elements136
941Strongly Connected Component136
942Word Break136
943K’th Largest Element in BST when modification to BST is not allowed136
944Queue using Stacks136
945Averages of Levels in Binary Tree136
9463 Sum136
947Number of Equivalent Domino Pairs Leetcode Solution136
948Lexicographical Numbers Leetcode Solution136
949Can Make Arithmetic Progression From Sequence Leetcode Solution136
950Print Fibonacci sequence using 2 variables136
951Three Consecutive Odds Leetcode Solution136
952Check if any two intervals overlap among a given set of intervals135
953Largest area rectangular sub-matrix with equal number of 1’s and 0’s135
954Breadth First Search (BFS) for a Graph135
955Minimum Height Trees LeetCode Solution135
956Reverse Nodes in K-Group135
957Count Submatrices With All Ones LeetCode Solution135
958Trim a Binary Search Tree135
959Dividing Array into Pairs With Sum Divisible by K135
960Construct BST from its given Level Order Traversal135
961Difference Array | Range update query in O(1)135
962Binary array after M range toggle operations135
963Binary Tree Longest Consecutive Sequence LeetCode Solution135
964All Unique Triplets that Sum up to a Given Value135
965Pattern Occurrences using Stack135
966Median of Two Sorted Arrays135
967Find postorder traversal of BST from preorder traversal134
968Largest Substring Between Two Equal Characters Leetcode Solution134
969Height of a generic tree from parent array134
970Palindrome Partitioning134
971Split Array Into Consecutive Subsequences134
972Newman-Conway Sequence134
973Count Primes in Ranges134
974Find Maximum of Minimum for Every Window Size in a Given Array134
975Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution134
976Symmetric Tree134
977Largest divisible pairs subset134
978Sign of the Product of an Array LeetCode Solution133
979Find Duplicate Subtrees133
980Maximum Product Subarray133
981Create Maximum Number133
982Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space133
983Kth Smallest Element in a BST Leetcode Solution133
984Binary Search Tree Delete Operation133
985Iterative Postorder Traversal Using Two Stacks133
986Segment Tree133
987First missing positive133
988Minesweeper LeetCode Solution133
989Depth First Search (DFS) for a Graph133
990Count pair with Given Sum133
991Product of Array Except Self LeetCode Solution133
992Climbing stairs132
993Find the First Circular Tour that visits all the Petrol Pumps132
994Rearrange array such that even positioned are greater than odd132
995The Maze III LeetCode Solution132
996Level Order Traversal of Binary Tree132
997The Painter’s Partition Problem132
998Boundary Traversal of binary tree132
999Kill Process LeetCode Solution132
1000Maximum subsequence sum such that no three are consecutive132
1001Unique Paths II132
1002Find the Difference Leetcode Solution132
1003Length of Longest Fibonacci Subsequence132
1004My Calendar I LeetCode Solution132
1005Serialize and Deserialize Binary Tree132
1006Asteroid Collision LeetCode Solution132
1007Longest Nice Substring LeetCode Solution131
1008Count subarrays where second highest lie before highest131
1009Partition Equal Subset Sum131
1010Next Greater Element III LeetCode Solution131
1011Longest subsequence such that difference between adjacents is one131
1012Build an Array With Stack Operations Leetcode Solution131
1013Double the first element and move zero to end131
1014Make The String Great Leetcode Solution131
1015K Closest Points to Origin Leetcode Solution131
1016Maximum Number of Ways to Partition an Array LeetCode Solution131
1017Decrypt String from Alphabet to Integer Mapping Leetcode Solution131
1018Find number of pairs in an array such that their XOR is 0130
1019Largest Number Leetcode Solution130
1020Collect maximum points in a grid using two traversals130
1021Level order traversal using two Queues130
1022Insertion in a Binary Tree130
1023Maximum Length of Repeated Subarray130
1024Valid Boomerang Leetcode Solution130
1025Graph Valid Tree LeetCode Solution130
1026Boolean Parenthesization Problem130
1027Shortest Completing Word Leetcode Solution130
1028Super Ugly Number130
1029Ugly Number II LeetCode Solution129
1030Advantages of BST over Hash Table129
1031Number Of Longest Increasing Subsequence129
1032Balanced Binary Tree129
1033Binary Search Tree129
1034Compute nCr % p129
1035Recover Binary Search Tree Leetcode Solution129
1036String Matching in an Array Leetcode Solution129
1037Friends Of Appropriate Ages LeetCode Solution129
1038Design Hit Counter LeetCode Solution129
1039Employee Importance LeetCode Solution128
1040Invalid Transactions LeetCode Solution128
1041Defanging an IP Address LeetCode Solution128
1042Implement Trie (Prefix Tree) Leetcode Solution128
1043Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’128
1044Kth Smallest Element in a Sorted Matrix LeetCode Solution128
1045Ugly Numbers128
1046Number of palindromic paths in a matrix128
1047Scramble String LeetCode Solution128
1048Construct Binary Tree from given Parent Array representation128
1049Construction of Longest Increasing Subsequence (N log N)128
1050Minimum Size Subarray Sum128
1051Move all negative elements to end in order with extra space allowed128
1052Maximum Product of Indexes of Next Greater on Left and Right128
1053Available Captures for Rook Leetcode Solution128
1054Morris Inorder Traversal128
1055Count minimum steps to get the given desired array127
1056Find whether a subarray is in form of a mountain or not127
1057Longest Bitonic Subsequence127
1058Find Peak Element127
1059Iterative Depth First Traversal of Graph127
1060Add two numbers127
1061Maximum Sum of 3 Non-Overlapping Subarrays127
1062Minimum Index Sum of Two Lists127
1063Populating Next Right Pointers in Each Node Leetcode Solution127
1064Validate Binary Search Tree127
1065Maximum difference between frequency of two elements such that element having greater frequency is also greater127
1066Regular Expression Matching Regular Expression Matching LeetCode Solution127
1067Maximum weight transformation of a given string127
1068Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1069Generate Parentheses Leetcode Solution126
1070Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution126
1071Custom Sort String Leetcode Solution126
1072Find the minimum distance between two numbers126
1073Remove Duplicates from Sorted Array II Leetcode Solution126
1074Divisible Pairs Counting126
1075Find a Peak Element II LeetCode Solution126
1076Clone a Binary Tree with Random Pointers126
1077Bitwise AND of Numbers Range LeetCode Solution126
1078Lowest Common Ancestor126
1079Increasing Triplet Subsequence LeetCode Solution126
1080Combination Sum IV LeetCode Solution126
1081Day of the Year Leetcode Solution125
1082Search in Sorted Rotated Array125
1083Maximize Distance to Closest Person LeetCode Solution125
1084Smallest Common Region Leetcode Solution125
1085Path Sum II LeetCode Solution125
1086Path Sum125
1087Binary Tree Right Side View LeetCode Solution125
1088Largest BST Subtree LeetCode Solution125
1089Binary Tree Data Structure125
1090Number of Closed Islands Leetcode Solution125
1091Consecutive Characters LeetCode Solution124
1092Remove Palindromic Subsequences Leetcode Solution124
1093Print all triplets in sorted array that form AP124
1094Kth Smallest Product of Two Sorted Arrays LeetCode Solution124
1095Number of siblings of a given Node in n-ary Tree124
1096Number of Students Doing Homework at a Given Time Leetcode Solution124
1097Count pairs from two sorted arrays whose sum is equal to a given value x124
1098Subarrays with K Different Integers Leetcode Solution124
1099Print Next Greater Number of Q queries124
1100Next Permutation Leetcode Solution124
1101Types of Binary Tree124
1102Rearrange array such that even index elements are smaller and odd index elements are greater124
1103Level of Each node in a Tree from source node124
1104Find Smallest Range Containing Elements from k Lists124
1105Find maximum difference between nearest left and right smaller elements123
1106Serialize and Deserialize Binary Tree LeetCode Solution123
1107Topological Sorting123
1108Distinct Subsequences123
1109Find Three Element From Different Three Arrays Such That a + b + c = sum123
1110Third Maximum Number Leetcode Solution122
1111Cutting a Rod122
1112Root to Leaf path with target sum Leetcode Solutions122
1113Bottom View of a Binary Tree122
1114Remove duplicates from sorted array122
1115Write Code to Determine if Two Trees are Identical122
1116Constant time range add operation on an array122
1117Convert BST into a Min-Heap without using array122
1118Maximum Product Subarray122
1119Reformat The String Leetcode Solution121
1120Count Largest Group Leetcode Solution121
1121Minimum Score Triangulation of Polygon Leetcode Solution121
1122Maximum Binary Tree121
1123Print Right View of a Binary Tree121
1124Cells with Odd Values in a Matrix LeetCode Solution121
1125Valid Tic-Tac-Toe State LeetCode Solution121
1126Mean of Array After Removing Some Elements Leetcode Solution121
1127Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution121
1128Iterative method to find ancestors of a given binary tree120
1129Thousand Separator Leetcode Solution120
1130Search Insert Position120
1131Queries for Number of Distinct Elements in a Subarray120
1132Construct K Palindrome Strings LeetCode Solution120
1133Palindrome Permutation LeetCode Solution120
1134Minimum Absolute Difference in BST Leetcode Solution120
1135Products of ranges in an array120
1136Search an Element in Sorted Rotated Array120
1137Longest Subarray of 1’s After Deleting One Element LeetCode Solution120
1138Closest Binary Search Tree Value Leetcode Solution120
1139Minimum sum of squares of character counts in a given string after removing k characters120
1140Golomb sequence120
1141Moser-de Bruijn Sequence119
1142Longest Increasing Consecutive Subsequence119
1143Prime Palindrome LeetCode Solution119
1144Find a sorted subsequence of size 3 in linear time119
1145Red-Black Tree Introduction119
1146Sum of Even Numbers After Queries119
1147Print modified array after executing the commands of addition and subtraction119
1148Factorial Trailing Zeroes LeetCode Solution118
1149Bus Routes Leetcode Solution118
1150Binary Tree to Binary Search Tree Conversion118
1151Maximum Product of Splitted Binary Tree LeetCode Solution118
1152Delete Nodes and Return Forest Leetcode Solution118
1153Subset Sum Problem in O(sum) space118
1154Transform a BST to Greater sum Tree118
1155Find maximum length Snake sequence118
1156Merge two BSTs with limited extra space118
1157Find the smallest binary digit multiple of given number117
1158Kth Smallest Number in Multiplication Table Leetcode Solution117
1159Longest Repeated Subsequence117
1160Swapping Nodes in a Linked List Leetcode Solution117
1161Number of Orders in the Backlog Leetcode Solution117
1162Possible Bipartition LeetCode Solution117
1163K maximum sums of overlapping contiguous sub-arrays117
1164Count even length binary sequences with same sum of first and second half bits117
1165Decision Tree117
1166Check Array Formation Through Concatenation Leetcode Solution117
1167Swap Nodes In Pairs117
1168K’th Largest element in BST using constant extra space117
1169Palindromic Substrings Leetcode Solution117
1170Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1171Minimum Cost to Move Chips to The Same Position LeetCode Solution116
1172Minimum Moves to Equal Array Elements LeetCode Solution116
1173Web Crawler LeetCode Solution116
1174Rotate Array116
1175Compare Strings by Frequency of the Smallest Character Leetcode Solution116
1176Maximize sum of consecutive differences in a circular array116
1177Priority Queue116
1178Minimum Sideway Jumps LeetCode Solution116
1179Search Suggestions System LeetCode Solution115
1180Find Largest Value in Each Tree Row LeetCode Solution115
1181Count Pairs Whose Products Exist in Array115
1182Closest Leaf in a Binary Tree LeetCode Solution115
1183First Bad Version115
1184Decrease Elements To Make Array Zigzag LeetCode Solution115
1185Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1186Diameter of N-Ary Tree LeetCode Solution114
1187Moving Stones Until Consecutive Leetcode Solution114
1188Given a binary tree, how do you remove all the half nodes?114
1189Contiguous Array LeetCode Solution114
1190Queue Reconstruction by Height114
1191Maximum number of segments of lengths a, b and c113
1192How to print maximum number of A’s using given four keys113
1193Matchsticks to Square Leetcode Solution113
1194Convert Sorted Array to Binary Search Tree LeetCode Solutions113
1195Reverse a Path in BST using Queue113
1196Kth Smallest Element in a BST113
1197Integer Break LeetCode Solution112
1198Valid Triangle Number112
1199Write a function to get the intersection point of two Linked Lists112
1200Maximum Depth Of Binary Tree112
1201Lowest Common Ancestor in Binary Search Tree112
1202Sum of Left Leaves LeetCode Solution112
1203Longest Common Prefix Using Word by Word Matching112
1204Divide Two Integers Leetcode Solution112
1205Reformat Date LeetCode Solution112
1206Champagne Tower LeetCode Solution112
1207Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution112
1208Array Queries for multiply replacements and product112
1209Maximum sum bitonic subarray112
1210Maximum sum of pairs with specific difference111
1211Guess The Word111
1212Range Sum Query using Sparse Table111
1213Range Queries for Longest Correct Bracket Subsequence111
1214New 21 Game111
1215Replace two consecutive equal values with one greater111
1216Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution110
1217Path Crossing Leetcode Solution110
1218Design Skiplist LeetCode Solution110
1219Valid Perfect Square LeetCode Solution110
1220Print modified array after multiple array range increment operations110
1221Concatenation of Array LeetCode Solution110
1222Graph and its representation110
1223Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1224Symmetric Tree LeetCode Solution Leetcode Solution110
1225Check for Identical BSTs without building the trees109
1226Merge Sort109
1227Perfect Squares LeetCode Solution109
1228Check if each internal node of a BST has exactly one child109
1229Arithmetic Slices II – Subsequence LeetCode Solution109
1230Lowest Common Ancestor of a Binary Tree Leetcode Solution109
1231Check Completeness of a Binary Tree LeetCode Solution109
1232Minimum Swaps To Make Sequences Increasing LeetCode Solution109
1233BST to a Tree with Sum of all Smaller Keys109
1234Flatten 2D Vector LeetCode Solution109
1235Maximum sum of a path in a Right Number Triangle109
1236The kth Factor of n Leetcode Solution109
1237Sliding Window Median Leetcode Solution108
1238Check if all levels of two Binary Tree are anagrams or not108
1239Maximum Array from Two given Arrays Keeping Order Same108
1240Queries on Probability of Even or Odd Number in given Ranges108
1241Power of Two108
1242Mean of range in array108
1243Parallel Courses II LeetCode Solution108
1244Count Subsets Having Distinct Even Numbers108
1245LRU Cache Leetcode Solution108
1246Missing Number107
1247Find Minimum in Rotated Sorted Array II LeetCode Solution107
1248Contiguous Array107
1249Image Overlap LeetCode Solution107
1250Print n terms of Newman-Conway Sequence107
1251Graph Cloning107
1252Maximize Elements Using Another Array107
1253Largest Plus Sign Leetcode Solution107
1254Count and Toggle Queries on a Binary Array107
1255Maximum Product Subarray107
1256Find minimum number of merge operations to make an array palindrome106
1257Bold Words in String LeetCode Solution106
1258Check If a String Can Break Another String Leetcode Solution106
1259Verify Preorder Serialization of a Binary Tree105
1260Find k-th smallest element in BST (Order Statistics in BST)105
1261Minimum Remove to Make Valid Parentheses LeetCode Solution105
1262Excel Sheet Column Title LeetCode Solution105
1263Merge k Sorted Lists Leetcode Solution104
1264Print Ancestors of a Given Binary Tree Node Without Recursion104
1265Next greater element104
1266Min Cost Climbing Stairs LeetCode Solution103
1267Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1268Palindrome Partitioning103
1269Smallest Range II Leetcode Solution103
1270Check if two nodes are on the same path in a Tree102
1271Merge Sorted Array101
1272Orderly Queue LeetCode Solution101
1273Check in binary array the number represented by a subarray is odd or even101
1274Koko Eating Bananas LeetCode Solution100
1275Peeking Iterator LeetCode Solution100
1276Different Ways to Add Parentheses Leetcode Solution100
1277Check if X can give change to every person in the Queue99
1278Newman–Shanks–Williams prime99
1279Number of elements less than or equal to a given number in a given subarray99
1280Longest Substring Without Repeating Characters Leetcode Solution97
1281Largest Submatrix With Rearrangements LeetCode Solution97
1282Find maximum average subarray of k length97
1283Maximum Sum Increasing Subsequence97
1284Range Minimum Query (Square Root Decomposition and Sparse Table)97
1285Number of indexes with equal elements in given range96
1286Queries for Decimal Values of Subarrays of a Binary Array96
1287Array Nesting Leetcode Solution95
1288Maximum product of an increasing subsequence95
1289Minimum Total Space Wasted With K Resizing Operations LeetCode Solution95
1290Minimum Number of People to Teach LeetCode Solution94
1291Binary Tree to Binary Search Tree Conversion using STL set94
1292Check given array of size n can represent BST of n levels or not94
1293Arranging Coins Leetcode Solution93
1294Random Pick Index LeetCode Solution93
1295Jump Game IV LeetCode Solution92
1296Find the Winner of the Circular Game LeetCode Solution92
1297Reach a Number LeetCode Solution92
1298Encoded String With Shortest Length LeetCode Solution92
1299Convert to Base -2 LeetCode Solution92
1300Queries on XOR of greatest odd divisor of the range92
1301Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution91
1302Convert a BST to a Binary Tree such that sum of all greater keys is added to every key91
1303Add Two Numbers II Leetcode Solution90
1304Insert Delete GetRandom O(1) Leetcode Solution90
1305Palindrome Number LeetCode Solution88
1306Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution88
1307Vertical Order Traversal of Binary Tree LeetCode Solution87
1308Design Underground System Leetcode Solution86
1309Continuous Subarray Sum LeetCode Solution85
1310Print Maximum Length Chain of Pairs84
1311Detect Capital Leetcode Solution82
1312Design A Leaderboard Leetcode Solution81
1313Top K Frequent Elements LeetCode Solution79
1314Substring with Concatenation of All Words Leetcode Solution78
1315Minimum Swaps to Group All 1’s Together Leetcode Solution77
1316Minimum Path Sum Leetcode Solution75
1317Decode String Leetcode Solution74
1318Count Sub Islands LeetCode Solution72
1319Odd Even Linked List Leetcode Solution72
1320Binary Tree Inorder Traversal LeetCode Solution72
1321Shifting Letters LeetCode Solution71
1322Best Meeting Point LeetCode Solution71
1323Shortest Unsorted Continuous Subarray LeetCode Solution71
1324Maximum Population Year LeetCode Solution71
1325Find the Town Judge LeetCode Solution70
1326Sum Root to Leaf Numbers LeetCode Solution70
1327Longest Common Subsequence LeetCode Solution68
1328Find the Town Judge LeetCode Solution68
1329Design Add and Search Words Data Structure LeetCode Solution67
1330Rectangle Overlap LeetCode Solution66
1331Score of Parenthesis LeetCode Solution65
1332Maximum Population Year LeetCode Solution65
1333Insert into a Sorted Circular Linked List LeetCode Solution63
1334Stone Game IV LeetCode Solution62
1335Flatten Binary Tree to Linked List LeetCode Solution62
1336Is Graph Bipartite? LeetCode Solution60
1337Range Sum Query 2D – Immutable LeetCode Solution60
1338Valid Triangle Number LeetCode Solution59
1339Reveal Cards In Increasing Order Leetcode Solution55
1340Divide Chocolate LeetCode Solution51
1341Range Sum of BST LeetCode Solution43
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution42
1343Reverse Integer Leetcode Solution41
1344Sort Colors LeetCode Solution37
1345Find K Closest Elements LeetCode Solution36
1346Excel Sheet Column Number LeetCode Solution34
1347Rotate String LeetCode Solution32
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution31
Translate »
1