Unique Binary Search Trees LeetCode Solution


Frequently asked in Adobe Amazon Apple Bloomberg ByteDance Facebook Google Microsoft SnapchatViews 1
Unique Binary Search Trees LeetCode Solution says that – Given an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n.

Example 1:

Unique Binary Search Trees LeetCode SolutionPinInput:

 n = 3

Output:

 5

Example 2:

Input:

 n = 1

Output:

 1

Constraints:

  • 1 <= n <= 19

Algorithm Of Unique Binary Search Trees LeetCode Solution –

IDEA –

In this problem, we are asked to get the number of trees and not necessarily to return all trees, only the number. Here we can use the idea of dynamic programming, let dp[n] be the number of unique Binary Search Trees with n nodes. How can we evaluate them: we need to choose the number of nodes in the left subtree and the number of nodes in the right subtree, for example n=5, then we have options:

  1. The left subtree has 0 nodes, root = 1, and the right subtree has 4 nodes, a number of options f[0]*f[4]
  2. The left subtree has 1 node, root = 2, and the right subtree has 3 nodes, a number of options f[1]*f[3]
  3. The left subtree has 2 nodes, root = 3, and the right subtree has 2 nodes, number of options f[2]*f[2]
  4. The left subtree has 3 nodes, root = 4, and the right subtree has 1 node, number of options f[3]*f[1]
  5. The left subtree has 4 nodes, root = 5, and the right subtree has 0 nodes, number of options f[4]*f[0]

So, in total f[5] = f[0]*f[4] + f[1]*f[3] + f[2]*f[2] + f[3]*f[1] + f[4]*f[0], and in general:
f[n] = f[0]*f[n-1] + f[1]*f[n-2] + ... + f[n-2]*f[1] + f[n-1]*f[0].

  • In order to find Unique Binary Search Trees. we will use the concept of the Catalan numbers in this question we will use formulas like – C2 = C0*C1 + C1*C0.

C3 = C0*C2 + C1*C1 + C2*C0.

C4 = C0*C3 + C1*C2 + C2*C1 + C3*C0.

  • At last, we will return the C-th number. we will use the Catalan number in this question to find the unique number of BST. There are lots of applications for Catalan numbers.

APPROACH –

  • At first, we will create one array of length n+1 and initially, the value of the first index will be 1.
  • After that, we will run a loop from 1 to n+1 and within the loop, we will run a nested loop from 0 to i.
  • Within the loop, we will update the i-th position of the array by adding the multiplication of the respective index and at last, we will return the value of the nth index of the array.
  • Hence we will find the Unique Binary Search Tree.

IMAGE OF THE SOLUTION –

Unique Binary Search Trees LeetCode SolutionPin

 

class Solution {
    public int numTrees(int n) {
        int[] res = new int[n+1];
        res[0]= 1;
        for(int i=1; i <=n; i++)
            for(int j = 0; j<i; j++)
                res[i] += res[j]*res[i-j-1];
        return res[n];
    }
}
class Solution:
    def numTrees(self, n: int) -> int:
        res = [0]*(n+1)
        res[0] = 1
        for i in range(1,n+1):
            for j in range(i):
                res[i] += res[j]*res[i-j-1]
        return res[n]

TIME COMPLEXITY – O(N^2), As we have used a nested loop here.

SPACE COMPLEXITY – O(N), As we have created one array on length ‘n’.

SIMILAR QUESTIONS – https://www.tutorialcup.com/leetcode-solutions/unique-paths-leetcode-solution.htm

– https://leetcode.com/problems/unique-binary-search-trees-ii/

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2829
2Java program to find the number of Nodes in a Binary Tree2508
3Reverse a string without affecting special characters2468
4Delete a node of a linked list at given position1982
5Palindrome using Recursion1881
6Insert nodes in a linked list in a sorted way (Ascending Order)1668
7Find elements pair from array whose sum equal to number1655
8Sort Elements by Frequency of Occurrences1638
9Write a program to print all permutations of a given string1613
10Find Minimum Distance Between Two Numbers in an Array1479
11Create a Doubly Linked List1453
12Quick Sort1425
13Reverse an Array1417
14Smallest window in a string containing all characters of another string1401
15Find a Triplet That Sum to a Given Value1364
16Recursively remove all adjacent duplicates1361
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1325
19Sum of numbers in String1324
20Smallest Positive Number Missing in an Unsorted Array1291
21Check if the Elements of an Array are Consecutive1260
22Detect a loop in the Linked List1245
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1221
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1208
27Recursive function to do substring search1204
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1130
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1112
32Maximum Subarray Sum using Divide and Conquer1107
33Remove characters from first string which are in second1075
34Find Leaders in an Array1064
35Swap nodes in the linked list1041
36Find the Number Occurring Odd Number of Times in an Array1008
37Arrange given Numbers to Form the Biggest Number II996
38Find the second most frequent character992
39Given a string find its first non-repeating character975
40Find Triplet in Array With a Given Sum968
41Given a sorted array and a number x, find the pair in array whose sum is closest to x959
42Total number of occurrences of a given item in the linked list959
43A Program to check if strings are rotations of each other or not952
44Print all possible words from phone digits939
45Find the Missing Number929
46Rearrange Positive and Negative Numbers Alternatively in Array925
47Longest Palindromic Substring909
48Segregate even and odd nodes in a linked list891
49Print Longest common subsequence887
50Union and Intersection of Two Linked Lists879
51Transform one string to another using minimum number of given operations873
52Check rearranged string can form a palindrome854
53Rearrange given Array in Maximum Minimum Form851
54Count Possible Triangles824
55Iterative Implementation of Quick Sort823
56Multiplication of Two Matrices808
57Check if the linked list is palindrome801
58Count of Triplets With Sum Less than Given Value800
59Rotate a Linked List799
60Stock Buy Sell to Maximize Profit797
61Concatenation of two strings768
62Tug of War766
63Print all duplicates in the input string762
64Count Number of Substrings with K Distinct Character’s761
65Find Nearest Greater and Smaller Element750
66Find Pythagorean Triplets from Array742
67The Celebrity Problem742
68Reverse String Without Temporary Variable736
69Remove ‘b’ and ‘ac’ from a given string736
70Find all Common Elements in Given Three Sorted Arrays734
71Remove all duplicates in an unsorted linked list714
72Find the Row with Maximum Number of 1’s712
73Find the Peak Element from an Array704
74Find the subarray whose sum is equal to a given number X700
75Remove Minimum Characters so that Two Strings Become Anagrams696
76Find Smallest Missing Number in a Sorted Array691
77Addition of Two Matrices691
78A Product Array Puzzle689
79Insertion Sort689
80Implement Two Stacks in an Array681
81Generate all Binary Strings Without Consecutive 1’s681
82Maximum Sum of Non Consecutive Elements674
83Maximum Product Subarray II661
84Lexicographic rank of string660
85Check if Two given Matrices are Identical653
86Multiplication of Previous and Next652
87Subtraction of Two Matrices640
88Merge K Sorted Arrays and Print Sorted Output636
89Move All the Zeros to the End of the Given Array635
90Divide a string in N equal parts629
91Form Minimum Number from Given Sequence of D’s and I’s628
92Online Algorithm for Checking Palindrome in a Stream628
93Remove recurring digits in a given number622
94Check whether two strings are anagram of each other621
95Maximum Circular Subarray Sum616
96Sort a stack using a temporary stack613
97Sort a linked list that is sorted alternating ascending and descending613
98Find the Minimum Element in a Sorted and Rotated Array610
99Move last element of the Linked List at first place608
100Subarray and Subsequence605
101First Circular Tour to Visit all the Petrol Bunks603
102Largest Subarray with Equal Number of 0’s and 1’s602
103Flattening a linked list599
104Compare two strings(linked lists)599
105Maximum Element in an Array which is Increasing and then Decreasing595
106Palindrome Permutations of a String591
107Elements Appear more than N/K times in Array584
108Palindromes in a given range583
109Run length encoding582
110Majority Element581
111Print all permutations with repetition579
112Pangram Checking576
113Minimum insertions to form a shortest palindrome576
114Minimum Characters to be Added at Front to Make String Palindrome570
115Merge a linked list into another at alternate positions570
116Remove all duplicates in a sorted linked list569
117Most repeating character in a string568
118Rearrange a given linked list in-place567
119Minimum number of Merge Operations to make an Array Palindrome567
120Rotate string to get lexicographically minimum string563
121Repeated Subsequence of Length Two or More561
122Print all anagrams together in a sequence of words558
123Reorder an Array According to the Given Indexes556
124Pancake Sorting Problem546
125Two Sum Leetcode Solution543
126Merge Overlapping Intervals II542
127Clone a Linked List with next and random pointer541
1283Sum Leetcode Solution539
129Transpose of a Matrix533
130Size of The Subarray With Maximum Sum530
131Remove Extra Spaces from a String529
132Removing Spaces from a String using stringstream527
133Remove duplicates from a string525
134Smallest Palindrome after Replacement523
135Partition Problem523
136Check if a given string is a rotation of a palindrome523
137Maximum Sum Increasing Subsequence522
138Longest Palindrome can be Formed by Removing or Rearranging Characters520
139Check whether Strings are K Distance Apart or Not512
140Generate all Binary Strings from Given Pattern509
141Length of Longest valid Substring506
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized506
143Insert Node in the Sorted Linked List505
144Delete Last Occurrence504
145Check if Two given Strings are Isomorphic to each other500
146Maximum difference between two elements such as larger element comes after smaller494
147Program to Toggle all Characters in a String492
148Given string is interleaving of two other strings or not489
149Count Minimum Steps to Get the given Array484
150Merge sort better than quick sort for linked lists482
151Number of Smaller Elements on Right Side481
152Check length of a String is Equal to the Number Appended at its Last479
153Find Pair with Given Difference478
154Check if all Rows of a Matrix are Circular Rotations of Each Other477
155Longest Common Prefix using Divide and Conquer474
156Find nth node of the Linked list from the end473
157Find a Fixed Point in a Given Array467
158Sort 0s 1s and 2s in an Array466
159Print all interleavings of given two strings464
160Compare Two Version Numbers463
161Reverse words in a given string462
162Find the Subarray of given length with Least Average461
163Reorder Array Using Given Indexes459
164Merge two sorted linked lists such that merged list is in reverse order458
165Print Reverse of a string (Recursion)457
166Split linked list using alternate nodes457
167Median of Two Sorted Arrays LeetCode Solution456
168Print string of odd length in ‘X’ format445
169Find K Length Subarray of Maximum Average440
170Find Element Using Binary Search in Sorted Array439
171Print all Palindromic Partitions of a String438
172Swap Kth Node from beginning with Kth Node from End437
173Find Duplicates in an Array in Most Efficient Way432
174print all palindromic partitions425
175Flatten a multilevel linked list423
176Maximum Length of Chain Pairs420
177Shortest Superstring Problem420
178Check if String Follows Order of Characters by a Pattern or not417
179Sorting a K Sorted Array413
180Sort a String According to Another String410
181Longest Span with same Sum in two Binary Arrays II404
182Reverse a Linked List in groups401
183Find a Sorted Subsequence of size 3400
184Recursively print all the sentences that can be formed from list of word lists397
185Program to add two binary digits397
186Find the two Numbers with Odd Occurrences in an Unsorted Array393
187Longest Common Prefix Using Binary Search II390
188Reverse a Singly Linked List (Iterative/Non-Recursive)389
189Caesar Cipher387
190Kth Non-repeating Character385
191Rearrange a linked list in Zig-Zag384
192Check if String can Become Empty by Recursively Deleting given Substring383
193Rotate Image by 90 degrees380
194Longest Common Prefix Word by Word Matching380
195Pancake Sorting380
196Permutations of a Given String Using STL373
197Perfect Reversible String371
198Merging Two Sorted Arrays368
199Increasing Subsequence of Length three with Maximum Product368
200Sort a linked list with 0s, 1s and 2s365
2011`s and 2`s complement of binary number365
202Find First non-repeating character in a string365
203Find the point where a monotonically increasing function becomes positive first time364
204Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes363
205Four Elements that Sum to Given362
206List items containing all characters of a given word358
207Delete N nodes after M357
208Longest Common Prefix using Character by Character Matching353
209Count Number of Occurrences in a Sorted Array351
210Palindrome string (number)347
211Split a string347
212Minimum Characters to be Removed to Make a Binary String Alternate343
213Recursive Implementation of atoi()341
214Check if a Linked list of Strings form a Palindrome339
215Print All Distinct Elements of the Array337
216Even Substring Count336
217Sorting the array of strings336
218Convert a String that is Repetition of a Substring of Length K333
219Maximum occurring character in a string332
220Valid Parentheses LeetCode Solution332
221Find the first Repeating Number in a Given Array331
222Reverse a singly linked list recursively331
223Print Shortest Path to Print a String on Screen329
224Can we reverse a linked list in less than O(n) time ?327
225Binary Tree to Doubly linked list326
226wildcard character matching325
227Convert string1 to string2 in one edit325
228Reverse a String using Stack324
229Nth Character in Concatenated Decimal String323
230Maximum Subarray Leetcode Solution321
231Sort Elements by Frequency II321
232Lower Case To Upper Case318
233Count the number of words318
234Merge Two Sorted Arrays315
235Split Four Distinct Strings315
236Find the Lost Element From a Duplicated Array313
237Find middle of the Linked List311
238Longest Common Subsequence with Permutations309
239Count the Pairs at Same Distance as in English Alphabets306
240Matrix Chain Multiplication using Dynamic Programming302
241Next Greater Element in an Array300
242Palindrome Permutation294
243Roman to Integer Leetcode Solution291
244Find All Pairs With a Given Difference290
245Find Nth Node288
246Triplet from three linked lists with given sum286
247Searching a node in a Binary Search Tree285
248Delete a Tree283
249String(represents an integer) to value283
250Reverse a String282
251Word Search Leetcode Solution281
252Reverse Bits281
253Print all Possible Ways to Break a String in Bracket Form280
254Delete a node under given conditions280
255Change Gender of a given String278
256Binary Tree278
257Sort an array of strings275
258How to Efficiently Implement k Stacks in a Single Array?275
259First non Repeating Element274
260Longest Common Extension271
261Count Pairs With Given Sum271
262Meeting Rooms II LeetCode Solution271
263Toeplitz Matrix270
264Number of sub-strings which recursively add up to 9270
265Remove middle points in a linked list of line segments270
266Repeated Substring Pattern269
267Move all negative elements to one side of array267
268Longest Palindromic Substring LeetCode Solution266
269Remove spaces from a string266
270N queen problem265
271Shuffle a given Array264
272Min Stack262
273Cuckoo sequence program259
274Number of Islands LeetCode Solution258
275Dijkstra Algorithm257
276Max stack256
277Most Frequent Element in an Array254
278Find, second, frequent, character254
279House Robber Leetcode Solution254
280Minimize the maximum difference between the heights253
281Clone a linked list with next and random pointer (Hashing)252
282Search Insert Position Leetcode Solution251
283Fibonacci numbers250
284Expression Evaluation250
285Sort linked which is sorted on absolute values249
286Valid Palindrome Leetcode Solution247
287Sudoku Solver247
288Plus One Leetcode Solution246
289Subset Leetcode246
290KMP Algorithm246
291Number Of 1 bits245
292How to Delete a Linked List244
293Combination Sum Leetcode Solution244
294Reverse words in a string244
295Min Stack Leetcode Solution243
296Evaluation of Postfix Expression242
297Word Search241
298Backspace String Compare238
299Set Matrix Zeroes237
300Sqrt(x) Leetcode Solution236
301Merge Sorted Arrays Leetcode Solution235
302Reversing a Queue234
303Rabin Karp Algorithm234
304Pair of Positive Negative Values in an Array234
305Subarray with 0 sum233
306Common elements in all rows of a given matrix232
307Tower Of Hanoi230
308Contains Duplicate II Leetcode Solution230
309Delete middle element of a stack230
310Product of array except self229
311Combination Sum228
312Integer to Roman Leetcode Solution227
313Pascal Triangle Leetcode227
314Intersection of Two Arrays II Leetcode Solution227
315String Compression227
316Count subarrays with equal number of 1’s and 0’s225
317Reverse individual words225
318Count of index pairs with equal elements in an array224
319Bellman Ford Algorithm224
320Minimum swaps required to bring all elements less than or equal to k together224
321Sliding Window Technique223
322Find Top K (or Most Frequent) Numbers in a Stream222
323Construct Binary Tree from Given Inorder and Preorder Traversals222
324Single Number Leetcode Solution222
325Implementation of Deque using Doubly Linked List222
326Arithmetic Expression Evaluation221
327Add Binary Leetcode Solution221
328Minimum Value to Get Positive Step by Step Sum Leetcode Solution220
329Contains Duplicate220
330Second Most Repeated Word in a Sequence219
331Segregate even and odd numbers219
332Palindrome Linked List Leetcode Solution219
333Sort elements by frequency219
334Page Replacement Algorithms in Operating Systems219
335Postfix to Infix Conversion218
336Find sum of non-repeating elements (distinct) elements in an array218
337Pow(x, n) Leetcode Solution218
338Design a stack that supports getMin() in O(1) time and O(1) extra space217
339Group Words With Same Set of Characters217
340Kruskal Algorithm216
341Maximum Number of Balloons Leetcode Solution216
342Count Odd Numbers in an Interval Range Leetcode Solution216
343Next Permutation216
344Third Maximum Number Leetcode Solution215
345Smallest Subarray with k Distinct Numbers214
346Sum of minimum and maximum elements of all subarrays of size k213
347Permutations Leetcode Solution213
348Convex Hull Algorithm213
349Longest Substring Without Repeating Characters LeetCode Solution213
350Top K Frequent Words213
351K-th Smallest Element in a Sorted Matrix212
352Find Lucky Integer in an Array Leetcode Solution212
353Sorting array using Stacks211
354Find the Town Judge Leetcode Solution211
355Majority Element Leetcode Solution210
356Maximum Subarray210
357Find Numbers with Even Number of Digits Leetcode Solution210
358Scramble String210
359Longest Common Prefix Leetcode Solution210
360Count subarrays having total distinct elements same as original array209
361First element occurring k times in an array209
362Minimum operation to make all elements equal in array209
363Evaluate Division208
364Spiral Matrix LeetCode Solution208
365Special Number207
366Huffman Coding207
367Given two unsorted arrays find all pairs whose sum is x207
368Swap Nodes in Pairs Leetcode Solutions207
369Minimum Path Sum206
370Check if two arrays are equal or not206
371Pascal’s Triangle II Leetcode Solution206
372Prefix to Infix Conversion206
373Missing Number Leetcode Solution206
374Number of Good Pairs Leetcode Solution206
375Search in Rotated Sorted Array Leetcode Solution205
376Best Time to Buy and Sell Stock  II Leetcode Solution205
377Count Primes Leetcode Solutions205
378Merge Two Sorted Lists Leetcode Solutions205
379Reversing the First K elements of a Queue204
380Single Number204
381Reverse a Number Using Stack204
382Sort Array by Increasing Frequency Leetcode Solution204
383Find duplicates in a given array when elements are not limited to a range204
384Maximal Square203
385Group Anagrams203
386Minimum Absolute Difference Leetcode Solution203
387Power of Two Leetcode Solution202
388Top K Frequent Elements202
389Find All Numbers Disappeared in an Array Leetcode Solution202
390Minimum Steps to reach target by a Knight202
391House Robber II Leetcode Solution202
392Matrix Diagonal Sum Leetcode Solution201
393Running Sum of 1d Array Leetcode Solution201
394Unique Paths Leetcode Solution201
395Maximum possible difference of two subsets of an array201
396Sorting using trivial hash function201
397Fizz Buzz Leetcode201
398Maximum Distance Between two Occurrences of Same Element in Array201
399Find Minimum In Rotated Sorted Array200
400Range Sum Query 2D – Immutable Leetcode Solution199
401Expression Contains Redundant Bracket or Not199
402How to Implement Stack Using Priority Queue or Heap?199
403How Many Numbers Are Smaller Than the Current Number Leetcode Solution199
404Convert String To Int199
405Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution199
406Zigzag Conversion199
407Find the Closest Palindrome number198
408Subarray Sum Equals k198
409Unique Paths198
410Sort Integers by The Number of 1 Bit Leetcode Solution198
411Leetcode Permutations198
412Happy Number Leetcode Solution198
413Max Consecutive Ones Leetcode Solution198
414Coin Change 2 Leetcode Solution198
415Difference between highest and least frequencies in an array197
416Find Number of Employees Under every Employee197
417Find the first repeating element in an array of integers197
418Smallest Element Repeated Exactly K Times197
419Letter Case Permutation197
420Cumulative Frequency of Count of Each Element in an Unsorted Array197
421Decode String197
422Subarray Sum Equals K LeetCode Solution196
423Length of the largest subarray with contiguous elements196
424Reverse Integer196
425Remove Duplicates from Sorted Array Leetcode Solution196
426Palindrome Substring Queries196
427Find Winner on a Tic Tac Toe Game Leetcode Solution196
428Subset sum problem196
429Check if Array Contains Contiguous Integers With Duplicates Allowed196
430Find top three repeated in array195
431Monotonic Array LeetCode Solution195
432Implement Stack and Queue using Deque195
433Sort a stack using recursion195
434Reverse Vowels of a String Leetcode Solution194
435Best Time to Buy and Sell Stock III Leetcode Solution194
436Count Substrings with equal number of 0s, 1s and 2s194
437Fibonacci Number LeetCode Solution194
438Nth Catalan Number194
439Capacity To Ship Packages Within D Days Leetcode Solution194
440Reverse Words in a String III LeetCode Solution193
441Reverse a Stack Using Recursion193
442Print All Distinct Elements of a Given Integer Array193
443Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
444Find Median from data Stream193
445Sum of Subarray Ranges Leetcode Solution193
446Find The Duplicate Number193
447Maximum Depth of Binary Tree Leetcode Solution193
448LRU Cache Implementation192
449Trapping Rain Water Leetcode Solution192
450Check If N and Its Double Exist Leetcode Solution192
451Bipartite Graph192
452Prim’s Algorithm192
453Delete a Node from linked list without head pointer192
454Shuffle the Array Leetcode Solution192
455Merge Two Sorted Linked Lists191
456Find the Duplicate Element191
457Subarrays with distinct elements191
458Integer to English words191
459Generate a String With Characters That Have Odd Counts Leetcode Solution191
460Priority Queue Using Singly Linked List190
461Find Common Characters Leetcode Solution190
462Sorting a Queue without Extra Space190
463Kth largest element in an Array Leetcode Solutions190
464Reverse a String190
465Target Sum190
466Excel Sheet Column Number Leetcode Solution190
467Find all pairs (a, b) in an array such that a % b = k189
468Iterative Tower of Hanoi189
469Print all subarrays with 0 sum189
470Longest Common Subsequence189
471Balanced Binary Tree Leetcode Solution189
472Fizz Buzz188
473Count pairs from two linked lists whose sum is equal to a given value188
474Kids With the Greatest Number of Candies Leetcode Solution188
475Minimum Moves to Equal Array Elements Leetcode Solution188
476Concatenation of Array LeetCode Solution188
477Edit Distance188
478Find the Difference Leetcode Solution188
479Word Ladder LeetCode Solution187
480Remove Minimum Number of Elements Such That no Common Element Exist in both Array187
481The K Weakest Rows in a Matrix Leetcode Solution187
482Find First and Last Position of Element in Sorted Array Leetcode Solution187
483Find elements which are present in first array and not in second187
484Floyd Warshall Algorithm187
485Kth Largest Element in a Stream Leetcode Solution187
486Count and Say186
487Next Greater Element I Leetcode Solution186
488Design Parking System Leetcode Solution186
489Number of Steps to Reduce a Number to Zero Leetcode Solution186
490Degree of an array186
491Find subarray with given sum (Handles Negative Numbers)186
492Text Justification LeetCode Solution186
493Longest Common Prefix using Trie186
494Merge Overlapping Intervals185
495MiniMax Algorithm185
496Multiply Strings Leetcode Solution185
497Zigzag Conversion LeetCode Solution185
498Count and Say Leetcode Solution185
499Flood Fill LeetCode185
500Prefix to Postfix Conversion185
501Shortest Palindrome184
502Reverse a linked list184
503Jump Game Leetcode Solution183
504Longest subarray not having more than K distinct elements183
505Peak Index in a Mountain Array183
506Recursion183
507Length of Last Word Leetcode Solution183
508Move Zeroes LeetCode Solution183
509Slowest Key Leetcode Solution183
510Convert array into Zig-Zag fashion183
511Top View of Binary Tree183
512The Stock Span Problem183
513Mobile Numeric Keypad Problem183
514Substring With Concatenation Of All Words183
515Priority Queue in C++183
516Next Greater Frequency Element183
517Max Area of Island183
518Find N Unique Integers Sum up to Zero Leetcode Solution183
519Pair with given product183
520Valid Parenthesis String183
521Find four elements that sum to a given value (Hashmap)183
522Implement a stack using single queue182
523Shuffle String Leetcode Solution182
524Check if a given array contains duplicate elements within k distance from each other182
525Iterative Inorder Traversal of a Binary Tree182
526Find distinct elements common to all rows of a matrix182
527Longest Common Prefix using Sorting182
528Intersection of Two Arrays182
529Find any one of the multiple repeating elements in read only array181
530Count number of triplets with product equal to given number181
531Find Index of Closing Bracket for a Given Opening Bracket in an Expression181
532Postfix to Prefix Conversion181
533Find missing elements of a range181
534Last Stone Weight181
535Contiguous Array Leetcode180
536Relative Sort Array Leetcode Solution180
537Koko Eating Bananas Leetcode Solution180
538Delete Node in a Linked List Leetcode Solution180
539N-th Tribonacci Number Leetcode Solution179
540Smallest Subarray With all Occurrences of a Most Frequent Element179
541Convert a normal BST to Balanced BST179
542Implement Stack using Queues179
543Excel Sheet Column Title Leetcode Solution179
544Change the Array into Permutation of Numbers From 1 to N178
545Best Time to Buy and Sell Stock178
546Container with Most Water178
547Isomorphic Strings Leetcode Solution178
548Linked List Cycle II LeetCode Solution178
549Build Array From Permutation Leetcode Solution177
550First negative integer in every window of size k177
551Minimum Operations to convert X to Y177
552Implementation of Deque using circular array177
553Rearrange a binary string as alternate x and y occurrences177
554Largest Perimeter Triangle Leetcode Solution177
555Find Words That Can Be Formed by Characters Leetcode Solution177
556Group Multiple Occurrence of Array Elements Ordered by first Occurrence177
557Valid Anagrams177
558Convert Sorted Array to Binary Search Tree Leetcode Solution177
559Check for Balanced Parentheses in an Expression177
560Assign Cookies Leetcode Solution177
561Is Subsequence Leetcode Solution177
562Jewels and Stones Leetcode Solution177
563Minimum Bracket Reversals177
564Integer to Roman176
565Island Perimeter Leetcode Solution176
566Hamming Distance176
567Valid Sudoku176
568Arrange given numbers to form the biggest number176
569Remove Linked List Elements Leetcode Solution176
570Sum of Left Leaves Leetcode Solutions176
571Combinations Leetcode Solution176
572Distribute Candies to People Leetcode Solution176
573Gold Mine Problem176
574Shuffle an Array176
575K-th Distinct Element in an Array176
576Unique Binary Search Trees175
57701 Matrix LeetCode Solution175
578Largest Sum Contiguous Subarray175
579Minimum Knight Moves LeetCode Solution175
580Summary Ranges Leetcode Solution175
581Rotate List Leetcode Solution175
582Minimum Delete Operations to make all Elements of Array Same175
583Maximum sum rectangle in a 2D matrix174
584Count all subsequences having product less than K174
585LRU Cache LeetCode Solution174
586Count the number of nodes at given level in a tree using BFS174
587Decode Ways174
588The Knapsack Problem174
589Find the smallest positive integer value that cannot be represented as sum of any subset of a given array173
5903Sum Closest LeetCode Solution173
591Distance Between Bus Stops Leetcode Solution173
592Shortest Path in a Grid with Obstacles Elimination LeetCode Solution173
593Maximum path sum in a triangle173
594Maximum Number of Chocolates to be Distributed Equally Among k Students173
595Insert Interval Leetcode Solution173
596Minimum number of distinct elements after removing m items172
597Maximum Distance in Array172
598Trapping Rain Water LeetCode Solution172
599Rotate Image LeetCode Solution171
600Minimum number of subsets with distinct elements171
601How to check if two given sets are disjoint?171
602Sort Characters By Frequency LeetCode Solution171
603Frog Jump Leetcode Solution170
604Permutation in String Leetcode Solution170
605Sieve of Eratosthenes170
606K Empty Slots LeetCode170
607Sort Array By Parity LeetCode Solution170
608Stone Game LeetCode170
609Same Tree LeetCode Solution170
610Find minimum difference between any two elements170
611Word Pattern170
612Remove All Occurrences of a Substring LeetCode Solution169
613XOR Operation in an Array Leetcode Solution169
614Find if an Expression has Duplicate Parenthesis or Not169
615Minimum insertions to form a palindrome with permutations allowed169
616Distance of nearest cell having 1 in a binary matrix169
617Printing brackets in Matrix Chain Multiplication Problem169
618Replace Elements with Greatest Element on Right Side Leetcode Solution169
619Isomorphic Strings169
620Applications of Breadth First Search and Depth First Search169
621Painting Fence Algorithm169
622Minimum Depth of Binary Tree Leetcode Solution169
623Best Time to Buy and Sell Stock LeetCode Solution169
624Smallest Good Base169
625Word Wrap Problem168
626License Key Formatting Leetcode Solution168
627House Robber168
628Reverse a stack without using extra space in O(n)168
629Longest Substring with At Most K Distinct Characters LeetCode Solution168
630Segregate 0s and 1s in an Array168
631Minimum Cost to Hire K Workers168
632Defanging an IP Address Leetcode Solution168
633Find Sum of all unique sub-array sum for a given array168
634Maximum Consecutive Numbers Present in an Array168
635Find the Duplicate Number LeetCode Solution168
636Tracking current Maximum Element in a Stack168
637Count Good Nodes in Binary Tree Leetcode Solution167
638Coin Change Problem167
639Binary Tree Zigzag Level Order Traversal LeetCode Solution167
640Maximum difference between first and last indexes of an element in array167
641Iterative Method to find Height of Binary Tree167
642Wiggle Sort167
643GCD Of Two Numbers166
644Check If It Is a Straight Line Leetcode Solution166
645Optimal Account Balancing LeetCode Solution166
646Kth Missing Positive Number Leetcode Solution166
647Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions166
648Sum of All Odd Length Subarrays Leetcode Solution166
649Queries for counts of array elements with values in given range166
650Find Maximum Level sum in Binary Tree166
651Valid Palindrome II Leetcode Solution166
652Maximum Number of Occurrences of a Substring Leetcode Solution166
653Merge Two Balanced Binary Search Trees166
654Non-overlapping sum of two sets166
655Best Time to Buy and Sell Stock with Cooldown Leetcode Solution166
656How to Create Mergable Stack?166
657Find the Distance Value Between Two Arrays Leetcode Solution165
658Moving Average from Data Stream Leetcode Solution165
659Find Largest d in Array such that a + b + c = d165
660Path With Maximum Minimum Value LeetCode Solution165
661Flipping an Image LeetCode Solution165
662Longest Increasing Subsequence165
663Convert an array to reduced form165
664Longest Substring with At Least K Repeating Characters LeetCode Solution165
665Employee Free Time LeetCode Solution165
666Strobogrammatic Number LeetCode Solution165
667Valid Palindrome165
668Partition Labels LeetCode Solution164
669Find pairs with given sum such that elements of pair are in different rows164
670Maximum Number of Coins You Can Get Leetcode Solution164
671Delete consecutive same words in a sequence164
672Letter Combinations of a Phone Number164
673Reorganize String164
674Number of Provinces Leetcode Solution164
675Reducing Dishes LeetCode Solution163
676Number of Dice Rolls With Target Sum LeetCode Solution163
677Recover Binary Search Tree163
678Valid Perfect Square Leetcode Solution163
679Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest163
680Longest Increasing Path in a Matrix LeetCode Solution163
681Print the Fibonacci numbers in reverse order163
682Edit Distance LeetCode Solution163
683Populating Next Right Pointers in Each Node163
684Permutation Sequence LeetCode Solution163
685Power of Four Leetcode Solution163
686Construct BST from given Preorder Traversal162
687Sort Array by Increasing Frequency Leetcode Solution162
688Form minimum number from given sequence162
689K Empty Slots162
690Check If Two String Arrays are Equivalent Leetcode Solution162
691BFS vs DFS for Binary Tree162
692Lucky Numbers in a Matrix Leetcode Solution162
693Partition Array Into Three Parts With Equal Sum Leetcode Solution162
694Check if a queue can be sorted into another queue using a stack162
695Robot Room Cleaner Leetcode Solution161
696Reservoir Sampling161
697Reversing a Queue using Recursion161
698Binary Tree zigzag level order Traversal161
699Factorial Trailing Zeroes Leetcode Solution161
700To Lower Case Leetcode Solution161
701Merge Two Binary Trees LeetCode Solution161
702Dynamic Programming Basics161
703Ugly Number Leetcode Solution161
704Convert a Number to Hexadecimal Leetcode Solution161
705Find whether an array is subset of another array161
706Maximum Product of Two Elements in an Array Leetcode Solution161
707String to Integer (atoi) LeetCode Solution161
708Inorder Successor of a node in Binary Tree161
709Remove Invalid Parentheses Leetcode Solution161
710Increasing Decreasing String Leetcode Solution160
711Reverse Only Letters LeetCode Solution160
712Binomial Coefficient160
713Find Leaves of Binary Tree LeetCode Solution160
714Keyboard Row Leetcode Solution160
715Delete Nth node from the end of the given linked list160
716Subset Sum Leetcode160
717Majority Element II Leetcode Solution160
718Restore IP Addresses Leetcode Solution160
719Bulb Switcher LeetCode Solution159
720Decompress Run-Length Encoded List Leetcode Solution159
721Add and Search Word – Data structure design LeetCode159
722Find the Smallest Divisor given a Threshold Leetcode Solution159
723Find the largest multiple of 3159
724Unique Paths II Leetcode Solution159
725Find Pair with Greatest Product in Array158
726Find the node with minimum value in a Binary Search Tree158
727Minimum Cost For Tickets Leetcode Solution158
728Maximum Product of Three Numbers LeetCode Solution158
729Morris Traversal158
730Finding K closest element158
731Maximum 69 Number Leetcode Solution158
732Perform String Shifts Leetcode158
733Sum of f(a[i], a[j]) over all pairs in an array of n integers157
734First Unique Character in a String LeetCode Solution157
735Minimum Distance Between BST Nodes Leetcode Solution157
736Merge K Sorted Linked Lists157
737Sorted Linked List to Balanced BST157
738Numbers with prime frequencies greater than or equal to k157
739Invert Binary Tree LeetCode Solution157
740Number of Islands II LeetCode Solution157
741Find Maximum Depth of Nested Parenthesis in a String157
742Hamming Distance Leetcode Solution156
743Find All Duplicates in an Array LeetCode Solution156
744Maximum Depth of N-ary Tree Leetcode Solution156
745Queue based approach for first non-repeating character in a stream156
746Student Attendance Record I Leetcode Solution156
747Longest Span with same Sum in two Binary arrays156
748Bubble sort using two Stacks156
749Find unique character in a string156
750Special Array With X Elements Greater Than or Equal X Leetcode Solution156
751Word Pattern LeetCode Solution156
752Rank Transform of an Array Leetcode Solution156
753Check If Array Pairs Are Divisible by k LeetCode Solution156
754String Compression LeetCode Solution156
755Generate all possible sorted arrays from alternate elements of two given sorted arrays156
756Non-decreasing Array LeetCode Solution156
757Minimum Height Trees156
758Diagonal Traversal of Binary Tree156
759Tiling Problem156
760Largest subarray with equal number of 0s and 1s156
761Final Prices With a Special Discount in a Shop Leetcode Solution155
762Largest rectangular sub-matrix whose sum is 0155
763Search a 2D Matrix II Leetcode Solution155
764Find Median from Data Stream LeetCode Solution155
765Jump Game155
766Stack Permutations (Check if an array is stack permutation of other)155
767Largest Rectangle in Histogram LeetCode Solution155
768Elements to be added so that all elements of a range are present in array155
769Maximum Length of a Concatenated String with Unique Characters Leetcode Solution155
770Minimum time required to rot all oranges155
771Kth ancestor of a node in binary tree155
772Evaluate Reverse Polish Notation LeetCode Solution155
773Find if Path Exists in Graph Leetcode Solution155
774Symmetric Tree Leetcode Solution155
775Binary Tree Maximum Path Sum LeetCode Solution155
776Best Meeting Point LeetCode Solution155
777Remove brackets from an algebraic string containing + and – operators154
778k-th missing element in increasing sequence which is not present in a given sequence154
779Maximum Difference Between Increasing Elements LeetCode Solution154
780Race Car LeetCode Solution154
781Minimize Maximum Pair Sum in Array LeetCode Solution154
782Split a String in Balanced Strings Leetcode Solution154
783Remove Nth Node From End of List Leetcode Solution154
784Program for Bridge and Torch problem154
785Snakes and Ladders LeetCode Solution154
786Transpose Graph154
787Number of NGEs to the Right153
788Sort an array according to the order defined by another array153
789N-Queens LeetCode Solution153
790Minimum Jumps to Reach Home LeetCode Solution153
791Deletion in a Binary Tree153
792Partition to K Equal Sum Subsets Leetcode Solution153
793Last Stone Weight II LeetCode Solution153
794Count quadruples from four sorted arrays whose sum is equal to a given value x153
795Linked List Cycle153
796Search in a Binary Search Tree Leetcode Solution153
797Valid Number153
798Count items common to both the lists but with different prices153
799Remove Duplicates from Sorted List LeetCode Solution152
800A Space Optimized DP solution for 0-1 Knapsack Problem152
801Interval Tree152
802Check if Two Expressions With Brackets are Same152
803Minimum number of jumps to reach end152
804Check for Palindrome after every character replacement Query152
805Course Schedule II – LeetCode152
806Get Maximum in Generated Array Leetcode Solution152
807Remove Duplicates from Sorted List II152
808Number Complement Leetcode Solution152
809Minimum swaps to make sequences increasing152
810Reorder Data in Log Files LeetCode Solution152
811Nearest Exit from Entrance in Maze LeetCode Solution152
812Minimum Time Visiting All Points Leetcode Solution152
813Priority Queue using doubly linked list152
814Print a Binary Tree in Vertical Order152
815String comparison containing wildcards151
816Maximum Profit in Job Scheduling Leetcode Solution151
817Total Numbers With no Repeated Digits in a Range151
818Sort Array By Parity II Leetcode Solution151
819Relative Ranks Leetcode Solution151
820Base 7 Leetcode Solution151
821Maximum size subarray sum equals k151
822Growable array based stack151
823Iterative Preorder Traversal151
824Spiral Matrix II Leetcode Solution151
825One Edit Distance LeetCode Solution151
826Subarray Product Less Than K LeetCode Solution151
827Find all triplets with zero sum151
828Crawler Log Folder Leetcode Solution151
829Nested List Weight Sum II LeetCode Solution151
830Regular Expression Matching150
831Convert BST to Min Heap150
832Given an Array of Pairs Find all Symmetric Pairs in it150
833Circular Queue150
834Form Minimum Number From Given Sequence150
835Merge Sorted Array LeetCode Solution150
836Brick Wall LeetCode Solution150
837Alien Dictionary LeetCode Solution150
838Maximum Nesting Depth of the Parentheses Leetcode Solution150
839Minimum Number of Taps to Open to Water a Garden LeetCode Solution149
840Find All Possible Recipes from Given Supplies LeetCode Solution149
841Clone Graph LeetCode Solution149
842Check whether a given Binary Tree is Complete or not149
843Sort Colors149
844Valid Parentheses Leetcode Solution149
845Longest Subarray Having Count of 1s One More than Count of 0s149
846Partition List Leetcode Solution149
847Can Place Flowers LeetCode Solution149
848Subsequence of Size K With the Largest Even Sum LeetCode Solution149
849Top K Frequent Words LeetCode Solution149
850Path with maximum average value149
851Friends Pairing Problem149
852Insert into a Binary Search Tree Leetcode Solution149
853Find the subarray with least average149
854Check if a given array can represent Preorder Traversal of Binary Search Tree149
855Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution149
856Count Distinct Elements in Every Window of Size K148
857Find Maximum Sum Possible Equal Sum of Three Stacks148
858Design a Stack With Increment Operation Leetcode Solution148
859Matrix Chain Multiplication148
860Binary Search Tree Search and Insertion148
861Level order Traversal in Spiral Form148
862Permutation Coefficient148
863Sequences of given length where every element is more than or equal to twice of previous148
864Subset with sum divisible by m148
865Find the Only Repetitive Element Between 1 to N-1148
866Guess Number Higher or Lower LeetCode Solution148
867Water Bottles Leetcode Solution147
868Sum of nearest smaller and greater number147
869Balanced Expression with Replacement147
870Distinct adjacent elements in an array147
871Repeated Substring Pattern LeetCode Solution147
872Design Browser History LeetCode Solution147
873Minimum Sum Path in a Triangle147
874Tree Traversal (Preorder, Inorder & Postorder)147
875Count Negative Numbers in a Sorted Matrix LeetCode Solution147
876LCS (Longest Common Subsequence) of three strings146
877Brightest Position on Street LeetCode Solution146
878Sorted Array to Balanced BST146
879BFS for Disconnected Graph146
880Union and Intersection of two Linked Lists146
881An Interesting Method to generate Binary Numbers from 1 to n146
882GCDs of given index ranges in an array146
883Daily Temperatures Leetcode Solution146
884Missing Element in Sorted Array LeetCode Solution146
885Range LCM Queries146
886Rearrange an Array Such that arr[i] is equal to i146
887Identify and Mark Unmatched Parenthesis in an Expression146
888Minimum sum of multiplications of n numbers146
889Shortest Word Distance Leetcode Solution146
890K’th Largest Element in BST when modification to BST is not allowed146
891Number of Days Between Two Dates LeetCode Solution146
892Maximum Score After Splitting a String Leetcode Solution146
893Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution146
894Diagonal Traversal LeetCode Solution146
895Diagonal Traverse LeetCode Solution146
896Three way partitioning of an array around a given range146
897Minimum Swaps to Make Strings Equal Leetcode Solution145
898Find distance between two nodes of a Binary Tree145
899Convert Sorted List to Binary Search Tree145
900Check if stack elements are pairwise consecutive145
901Check if an Array is Stack Sortable145
902Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i145
903Delete And Earn145
904Destination City Leetcode Solution145
905Insert Delete GetRandom145
906Least Number of Unique Integers after K Removals Leetcode Solution145
907Check if the given array can represent Level Order Traversal of Binary Search Tree145
908Lemonade Change Leetcode Solution145
909Range sum queries without updates145
910Count ways to reach the nth stair using step 1, 2 or 3145
911Guess Number Higher or Lower II145
912Robot Bounded In Circle LeetCode Solution145
913Vertical sum in a given binary tree144
914Rearrange Spaces Between Words Leetcode Solution144
915Print Fibonacci sequence using 2 variables144
916Palindrome Partitioning Leetcode Solution144
9174Sum144
918Merge Two Sorted Lists Leetcode144
919Spiral Matrix III LeetCode Solution144
920Time Based Key-Value Store LeetCode Solution143
921Alien Dictionary143
922Maximum Frequency Stack Leetcode Solution143
923Split Array Into Consecutive Subsequences143
924Minimum Height Trees LeetCode Solution143
925Construct the Rectangle Leetcode Solution143
9263 Sum143
927Special Positions in a Binary Matrix Leetcode Solution143
928Construct Complete Binary Tree from its Linked List Representation143
929A program to check if a binary tree is BST or not143
930Queries for GCD of all numbers of an array except elements in a given range142
931Infix to Postfix142
932Number of Distinct Islands Leetcode Solution142
933Check if any two intervals overlap among a given set of intervals142
934Iterative Postorder Traversal Using Two Stacks142
935Find Common Characters Leetcode Solution142
936Construct BST from its given Level Order Traversal142
937Longest Palindromic Subsequence142
938Averages of Levels in Binary Tree142
939Difference Array | Range update query in O(1)142
940Stone Game II Leetcode142
941Trim a Binary Search Tree142
942Set Matrix Zeroes Leetcode Solution142
943Lexicographical Numbers Leetcode Solution142
944Remove Duplicates from Sorted List II LeetCode Solution142
945Binary Tree Longest Consecutive Sequence LeetCode Solution142
946All Unique Triplets that Sum up to a Given Value141
947Count Subarrays with Same Even and Odd Elements141
948Strongly Connected Component141
949Analyze User Website Visit Pattern LeetCode Solution141
950Find all permuted rows of a given row in a matrix141
951Largest area rectangular sub-matrix with equal number of 1’s and 0’s141
952Queue using Stacks141
953Unique Paths II141
954Collect maximum points in a grid using two traversals141
955Binary array after M range toggle operations141
956Can Make Arithmetic Progression From Sequence Leetcode Solution140
957Count subarrays where second highest lie before highest140
958Sliding Window Maximum140
959Find postorder traversal of BST from preorder traversal140
960Number of Equivalent Domino Pairs Leetcode Solution140
961Intersection of Two Linked Lists LeetCode Solution140
962Pattern Occurrences using Stack140
963Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space140
964Reverse Nodes in K-Group140
965Word Break140
966Count Submatrices With All Ones LeetCode Solution140
967Three Consecutive Odds Leetcode Solution140
968Create Maximum Number140
969Minesweeper LeetCode Solution140
970Merging Intervals140
971Length of Longest Fibonacci Subsequence139
972Level Order Traversal of Binary Tree139
973Binary Search Tree Delete Operation139
974Find the Difference Leetcode Solution139
975Height of a generic tree from parent array139
976Kth Smallest Element in a BST Leetcode Solution139
977Maximum Product Subarray139
978Palindrome Partitioning139
979Maximum Subarray Sum Excluding Certain Elements139
980Dividing Array into Pairs With Sum Divisible by K139
981Longest Nice Substring LeetCode Solution139
982Newman-Conway Sequence139
983Count pair with Given Sum139
984Count Primes in Ranges139
985Product of Array Except Self LeetCode Solution139
986K Closest Points to Origin Leetcode Solution138
987Median of Two Sorted Arrays138
988Asteroid Collision LeetCode Solution138
989Maximize Sum of Array after K Negations Leetcode Solution138
990Sign of the Product of an Array LeetCode Solution138
991Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution138
992My Calendar I LeetCode Solution138
993Symmetric Tree138
994Find the First Circular Tour that visits all the Petrol Pumps137
995The Maze III LeetCode Solution137
996Climbing stairs137
997Find Duplicate Subtrees137
998Friends Of Appropriate Ages LeetCode Solution137
999Double the first element and move zero to end137
1000Find Maximum of Minimum for Every Window Size in a Given Array137
1001Number Of Longest Increasing Subsequence137
1002Maximum Length of Repeated Subarray137
1003Largest divisible pairs subset137
1004Valid Boomerang Leetcode Solution137
1005Boundary Traversal of binary tree137
1006Segment Tree137
1007Maximum Product of Indexes of Next Greater on Left and Right137
1008First missing positive136
1009Boolean Parenthesization Problem136
1010Maximum weight transformation of a given string136
1011Partition Equal Subset Sum136
1012Depth First Search (DFS) for a Graph136
1013Make The String Great Leetcode Solution136
1014Largest Number Leetcode Solution136
1015Construction of Longest Increasing Subsequence (N log N)136
1016Level order traversal using two Queues136
1017Insertion in a Binary Tree136
1018Breadth First Search (BFS) for a Graph136
1019Largest Substring Between Two Equal Characters Leetcode Solution136
1020Serialize and Deserialize Binary Tree136
1021Compute nCr % p136
1022Construct Binary Tree from given Parent Array representation136
1023Maximum subsequence sum such that no three are consecutive136
1024The Painter’s Partition Problem136
1025Morris Inorder Traversal136
1026String Matching in an Array Leetcode Solution136
1027Shortest Completing Word Leetcode Solution135
1028Binary Search Tree135
1029Kill Process LeetCode Solution135
1030Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’135
1031Minimum Index Sum of Two Lists135
1032Maximum Number of Ways to Partition an Array LeetCode Solution135
1033Next Greater Element III LeetCode Solution135
1034Graph Valid Tree LeetCode Solution135
1035Decrypt String from Alphabet to Integer Mapping Leetcode Solution135
1036Longest subsequence such that difference between adjacents is one135
1037Ugly Numbers134
1038Design Hit Counter LeetCode Solution134
1039Build an Array With Stack Operations Leetcode Solution134
1040Rearrange array such that even positioned are greater than odd134
1041Number of palindromic paths in a matrix134
1042Custom Sort String Leetcode Solution134
1043Validate Binary Search Tree134
1044Advantages of BST over Hash Table134
1045Maximum Sum of 3 Non-Overlapping Subarrays134
1046K maximum sums of overlapping contiguous sub-arrays134
1047Scramble String LeetCode Solution134
1048Find number of pairs in an array such that their XOR is 0134
1049Available Captures for Rook Leetcode Solution133
1050Invalid Transactions LeetCode Solution133
1051Defanging an IP Address LeetCode Solution133
1052Ugly Number II LeetCode Solution133
1053Balanced Binary Tree133
1054Bitwise AND of Numbers Range LeetCode Solution133
1055Iterative Depth First Traversal of Graph132
1056Super Ugly Number132
1057Maximum length subsequence with difference between adjacent elements as either 0 or 1132
1058Recover Binary Search Tree Leetcode Solution132
1059Move all negative elements to end in order with extra space allowed132
1060Search in Sorted Rotated Array132
1061Employee Importance LeetCode Solution132
1062Add two numbers132
1063Implement Trie (Prefix Tree) Leetcode Solution132
1064Count minimum steps to get the given desired array132
1065Lowest Common Ancestor132
1066Path Sum II LeetCode Solution132
1067Count pairs from two sorted arrays whose sum is equal to a given value x132
1068Maximum difference between frequency of two elements such that element having greater frequency is also greater131
1069Number of Students Doing Homework at a Given Time Leetcode Solution131
1070Remove Duplicates from Sorted Array II Leetcode Solution131
1071Generate Parentheses Leetcode Solution131
1072Find a Peak Element II LeetCode Solution131
1073Find Peak Element131
1074Largest BST Subtree LeetCode Solution131
1075Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution131
1076Regular Expression Matching Regular Expression Matching LeetCode Solution131
1077Binary Tree Right Side View LeetCode Solution131
1078Day of the Year Leetcode Solution130
1079Find whether a subarray is in form of a mountain or not130
1080Subarrays with K Different Integers Leetcode Solution130
1081Populating Next Right Pointers in Each Node Leetcode Solution130
1082Longest Bitonic Subsequence130
1083Kth Smallest Element in a Sorted Matrix LeetCode Solution130
1084Clone a Binary Tree with Random Pointers130
1085Rearrange array such that even index elements are smaller and odd index elements are greater130
1086Combination Sum IV LeetCode Solution130
1087Root to Leaf path with target sum Leetcode Solutions130
1088Number of Closed Islands Leetcode Solution130
1089Smallest Common Region Leetcode Solution130
1090Consecutive Characters LeetCode Solution129
1091Find Smallest Range Containing Elements from k Lists129
1092Serialize and Deserialize Binary Tree LeetCode Solution129
1093Maximize Distance to Closest Person LeetCode Solution129
1094Find the minimum distance between two numbers129
1095Kth Smallest Product of Two Sorted Arrays LeetCode Solution129
1096Remove Palindromic Subsequences Leetcode Solution129
1097Convert BST into a Min-Heap without using array129
1098Minimum Size Subarray Sum129
1099Number of siblings of a given Node in n-ary Tree129
1100Binary Tree Data Structure129
1101Level of Each node in a Tree from source node129
1102Distinct Subsequences129
1103Next Permutation Leetcode Solution129
1104Increasing Triplet Subsequence LeetCode Solution129
1105Types of Binary Tree129
1106Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution128
1107Print all triplets in sorted array that form AP128
1108Find maximum difference between nearest left and right smaller elements128
1109Path Sum128
1110Remove duplicates from sorted array128
1111Find Three Element From Different Three Arrays Such That a + b + c = sum128
1112Count Largest Group Leetcode Solution128
1113Iterative method to find ancestors of a given binary tree128
1114Divisible Pairs Counting128
1115Constant time range add operation on an array128
1116Maximum Product Subarray127
1117Cutting a Rod127
1118Sum of Even Numbers After Queries127
1119Prime Palindrome LeetCode Solution127
1120Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1121Third Maximum Number Leetcode Solution127
1122Palindrome Permutation LeetCode Solution126
1123Mean of Array After Removing Some Elements Leetcode Solution126
1124Minimum Absolute Difference in BST Leetcode Solution126
1125Print Right View of a Binary Tree126
1126Print Next Greater Number of Q queries126
1127Reformat The String Leetcode Solution126
1128Bottom View of a Binary Tree126
1129Cells with Odd Values in a Matrix LeetCode Solution126
1130Valid Tic-Tac-Toe State LeetCode Solution126
1131Minimum Score Triangulation of Polygon Leetcode Solution126
1132Products of ranges in an array126
1133Topological Sorting125
1134Search Insert Position125
1135Write Code to Determine if Two Trees are Identical125
1136Delete Nodes and Return Forest Leetcode Solution125
1137Moser-de Bruijn Sequence125
1138Search an Element in Sorted Rotated Array125
1139Thousand Separator Leetcode Solution124
1140Merge two BSTs with limited extra space124
1141Maximum Binary Tree124
1142Swap Nodes In Pairs124
1143Subset Sum Problem in O(sum) space124
1144Closest Binary Search Tree Value Leetcode Solution124
1145Construct K Palindrome Strings LeetCode Solution124
1146Palindromic Substrings Leetcode Solution124
1147Print modified array after executing the commands of addition and subtraction123
1148Diameter of N-Ary Tree LeetCode Solution123
1149Golomb sequence123
1150Possible Bipartition LeetCode Solution123
1151Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution123
1152Longest Increasing Consecutive Subsequence123
1153Bus Routes Leetcode Solution123
1154Check Array Formation Through Concatenation Leetcode Solution123
1155Minimum sum of squares of character counts in a given string after removing k characters123
1156Transform a BST to Greater sum Tree122
1157Minimum Sideway Jumps LeetCode Solution122
1158Kth Smallest Number in Multiplication Table Leetcode Solution122
1159Maximize sum of consecutive differences in a circular array122
1160Find Largest Value in Each Tree Row LeetCode Solution122
1161Search Suggestions System LeetCode Solution122
1162Find a sorted subsequence of size 3 in linear time122
1163Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution122
1164Red-Black Tree Introduction122
1165Maximum Product of Splitted Binary Tree LeetCode Solution122
1166Queries for Number of Distinct Elements in a Subarray122
1167Find maximum length Snake sequence122
1168Priority Queue122
1169Compare Strings by Frequency of the Smallest Character Leetcode Solution121
1170Count even length binary sequences with same sum of first and second half bits121
1171Find the smallest binary digit multiple of given number121
1172Decision Tree121
1173Longest Repeated Subsequence121
1174Binary Tree to Binary Search Tree Conversion121
1175Swapping Nodes in a Linked List Leetcode Solution120
1176Factorial Trailing Zeroes LeetCode Solution120
1177Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1178First Bad Version120
1179Rotate Array120
1180Matchsticks to Square Leetcode Solution120
1181Web Crawler LeetCode Solution120
1182Lowest Common Ancestor in Binary Search Tree120
1183Decrease Elements To Make Array Zigzag LeetCode Solution119
1184Number of Orders in the Backlog Leetcode Solution119
1185Reverse a Path in BST using Queue119
1186Maximum sum bitonic subarray119
1187Minimum Cost to Move Chips to The Same Position LeetCode Solution119
1188K’th Largest element in BST using constant extra space119
1189Queue Reconstruction by Height119
1190Sum of Left Leaves LeetCode Solution118
1191Closest Leaf in a Binary Tree LeetCode Solution118
1192Graph and its representation118
1193Minimum Moves to Equal Array Elements LeetCode Solution118
1194Valid Triangle Number118
1195Moving Stones Until Consecutive Leetcode Solution118
1196Given a binary tree, how do you remove all the half nodes?118
1197Reformat Date LeetCode Solution118
1198Maximum number of segments of lengths a, b and c118
1199Contiguous Array LeetCode Solution118
1200Maximum sum of pairs with specific difference118
1201Count Pairs Whose Products Exist in Array118
1202Range Queries for Longest Correct Bracket Subsequence118
1203How to print maximum number of A’s using given four keys117
1204Guess The Word117
1205Array Queries for multiply replacements and product117
1206Kth Smallest Element in a BST117
1207Replace two consecutive equal values with one greater116
1208Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution116
1209Lowest Common Ancestor of a Binary Tree Leetcode Solution116
1210Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution116
1211Champagne Tower LeetCode Solution116
1212Path Crossing Leetcode Solution116
1213Arithmetic Slices II – Subsequence LeetCode Solution115
1214Minimum Swaps To Make Sequences Increasing LeetCode Solution115
1215Concatenation of Array LeetCode Solution115
1216Integer Break LeetCode Solution115
1217Perfect Squares LeetCode Solution115
1218Maximum Depth Of Binary Tree114
1219Power of Two114
1220Range Sum Query using Sparse Table114
1221Flatten 2D Vector LeetCode Solution114
1222Write a function to get the intersection point of two Linked Lists114
1223Check Completeness of a Binary Tree LeetCode Solution114
1224Design Skiplist LeetCode Solution114
1225Merge Sort114
1226LRU Cache Leetcode Solution114
1227The kth Factor of n Leetcode Solution114
1228Divide Two Integers Leetcode Solution114
1229Maximum sum of a path in a Right Number Triangle114
1230Check for Identical BSTs without building the trees113
1231BST to a Tree with Sum of all Smaller Keys113
1232Largest Plus Sign Leetcode Solution113
1233Maximize Elements Using Another Array113
1234New 21 Game113
1235Queries on Probability of Even or Odd Number in given Ranges113
1236Longest Common Prefix Using Word by Word Matching113
1237Contiguous Array113
1238Valid Perfect Square LeetCode Solution113
1239Print modified array after multiple array range increment operations113
1240Check if all levels of two Binary Tree are anagrams or not113
1241Mean of range in array113
1242Find Minimum in Rotated Sorted Array II LeetCode Solution113
1243Check if each internal node of a BST has exactly one child112
1244Maximum Value at a Given Index in a Bounded Array LeetCode Solution112
1245Parallel Courses II LeetCode Solution112
1246Print n terms of Newman-Conway Sequence112
1247Sliding Window Median Leetcode Solution112
1248Print Ancestors of a Given Binary Tree Node Without Recursion112
1249Bold Words in String LeetCode Solution112
1250Graph Cloning111
1251Merge k Sorted Lists Leetcode Solution111
1252Count Subsets Having Distinct Even Numbers111
1253Find k-th smallest element in BST (Order Statistics in BST)111
1254Find minimum number of merge operations to make an array palindrome111
1255Symmetric Tree LeetCode Solution Leetcode Solution111
1256Maximum Array from Two given Arrays Keeping Order Same111
1257Missing Number110
1258Minimum Remove to Make Valid Parentheses LeetCode Solution110
1259Count and Toggle Queries on a Binary Array110
1260Maximum Product Subarray110
1261Check if two nodes are on the same path in a Tree110
1262Smallest Range II Leetcode Solution110
1263Verify Preorder Serialization of a Binary Tree109
1264Number of elements less than or equal to a given number in a given subarray109
1265Check If a String Can Break Another String Leetcode Solution108
1266Excel Sheet Column Title LeetCode Solution108
1267Next greater element108
1268Image Overlap LeetCode Solution108
1269Min Cost Climbing Stairs LeetCode Solution107
1270Orderly Queue LeetCode Solution107
1271Koko Eating Bananas LeetCode Solution107
1272Palindrome Partitioning107
1273Minimum Time to Collect All Apples in a Tree LeetCode Solution106
1274Different Ways to Add Parentheses Leetcode Solution106
1275Check if X can give change to every person in the Queue105
1276Peeking Iterator LeetCode Solution105
1277Longest Substring Without Repeating Characters Leetcode Solution104
1278Merge Sorted Array103
1279Newman–Shanks–Williams prime103
1280Check in binary array the number represented by a subarray is odd or even103
1281Array Nesting Leetcode Solution102
1282Largest Submatrix With Rearrangements LeetCode Solution102
1283Range Minimum Query (Square Root Decomposition and Sparse Table)102
1284Arranging Coins Leetcode Solution101
1285Maximum Sum Increasing Subsequence100
1286Find maximum average subarray of k length100
1287Encoded String With Shortest Length LeetCode Solution100
1288Maximum product of an increasing subsequence99
1289Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1290Queries for Decimal Values of Subarrays of a Binary Array99
1291Number of indexes with equal elements in given range99
1292Convert to Base -2 LeetCode Solution98
1293Minimum Number of People to Teach LeetCode Solution98
1294Convert a BST to a Binary Tree such that sum of all greater keys is added to every key97
1295Random Pick Index LeetCode Solution97
1296Binary Tree to Binary Search Tree Conversion using STL set96
1297Continuous Subarray Sum LeetCode Solution96
1298Find the Winner of the Circular Game LeetCode Solution96
1299Vertical Order Traversal of Binary Tree LeetCode Solution96
1300Add Two Numbers II Leetcode Solution96
1301Reach a Number LeetCode Solution96
1302Queries on XOR of greatest odd divisor of the range95
1303Palindrome Number LeetCode Solution95
1304Check given array of size n can represent BST of n levels or not95
1305Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1306Jump Game IV LeetCode Solution94
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution94
1308Insert Delete GetRandom O(1) Leetcode Solution93
1309Design Underground System Leetcode Solution90
1310Print Maximum Length Chain of Pairs89
1311Detect Capital Leetcode Solution87
1312Design A Leaderboard Leetcode Solution86
1313Top K Frequent Elements LeetCode Solution83
1314Minimum Swaps to Group All 1’s Together Leetcode Solution83
1315Substring with Concatenation of All Words Leetcode Solution83
1316Minimum Path Sum Leetcode Solution80
1317Count Sub Islands LeetCode Solution80
1318Binary Tree Inorder Traversal LeetCode Solution80
1319Shifting Letters LeetCode Solution79
1320Odd Even Linked List Leetcode Solution77
1321Longest Common Subsequence LeetCode Solution77
1322Best Meeting Point LeetCode Solution76
1323Find the Town Judge LeetCode Solution76
1324Find the Town Judge LeetCode Solution75
1325Decode String Leetcode Solution75
1326Maximum Population Year LeetCode Solution74
1327Shortest Unsorted Continuous Subarray LeetCode Solution72
1328Sum Root to Leaf Numbers LeetCode Solution71
1329Maximum Population Year LeetCode Solution71
1330Design Add and Search Words Data Structure LeetCode Solution70
1331Rectangle Overlap LeetCode Solution70
1332Stone Game IV LeetCode Solution67
1333Flatten Binary Tree to Linked List LeetCode Solution67
1334Range Sum Query 2D – Immutable LeetCode Solution66
1335Score of Parenthesis LeetCode Solution66
1336Insert into a Sorted Circular Linked List LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution63
1338Is Graph Bipartite? LeetCode Solution62
1339Valid Triangle Number LeetCode Solution62
1340Divide Chocolate LeetCode Solution53
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution48
1342Range Sum of BST LeetCode Solution45
1343Reverse Integer Leetcode Solution43
1344Sort Colors LeetCode Solution42
1345Find K Closest Elements LeetCode Solution40
1346Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution38
1347Rotate String LeetCode Solution37
1348Excel Sheet Column Number LeetCode Solution37
1349Maximum Size Subarray Sum Equals k Leetcode Solution19
1350High Five LeetCode Solution18
1351H-Index Leetcode Solution18
1352Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution6
1353Unique Binary Search Trees LeetCode Solution1
Translate »