Flatten Binary Tree to Linked List LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon Apple Bloomberg ByteDance Facebook Goldman Sachs Google Microsoft Salesforce UberViews 2

Problem Statement:

Flatten Binary Tree to Linked List LeetCode Solution: Given the root of a binary tree, flatten the tree into a “linked list”:

  • The “linked list” should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.
  • The “linked list” should be in the same order as a pre-order traversal of the binary tree.

Examples:

Example 1:

Input:

 root = [1,2,5,3,4,null,6]

Output:

 [1,null,2,null,3,null,4,null,5,null,6]

Approach:

Idea:

The idea is to flatten the tree in a recursive manner. We will flatten all the left and right subtrees recursively and will keep a pointer to keep track of the recently flattened subtree. the idea is, that the bottom right-most node of the current left node should point to the current right node and the current right node should point to the current left node and the current left should point to null.
if there is no current left then move to curr to the current’s right.Check out the code for a better understanding.

  1. Flatten the left subtree of the root node into a linked list;
  2. Flatten the right subtree of the root node into a linked list;
  3. Let the right subtree of step 2 be the right child of the furthest right node of the left subtree of step 1.

Obviously, that’s a recursive process.

Flatten Binary Tree to Linked List LeetCode SolutionPin

Code:

Flatten Binary Tree to Linked List C++ Solution:

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* prev = NULL;
    void helper(TreeNode* root){
        if(!root)
            return;
        helper(root->right);
        helper(root->left);
        
        root->right = prev;
        root->left = NULL;
        prev = root;
    }
    
    void flatten(TreeNode* root){
        helper(root);
    }
};

Complexity Analysis of Flatten Binary Tree to Linked List LeetCode Solution:

  • Time Complexity: The time complexity of the above code is O(n).
  • Space ComplexityThe space complexity of the above code is O(n), occupied by the recursion stack.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2831
2Java program to find the number of Nodes in a Binary Tree2509
3Reverse a string without affecting special characters2470
4Delete a node of a linked list at given position1983
5Palindrome using Recursion1884
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 Occurrences1641
9Quick Sort1627
10Write a program to print all permutations of a given string1615
11Find Minimum Distance Between Two Numbers in an Array1479
12Create a Doubly Linked List1455
13Reverse an Array1417
14Smallest window in a string containing all characters of another string1402
15Find a Triplet That Sum to a Given Value1365
16Recursively remove all adjacent duplicates1363
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1328
19Sum of numbers in String1324
20Smallest Positive Number Missing in an Unsorted Array1292
21Check if the Elements of an Array are Consecutive1261
22Detect a loop in the Linked List1247
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1225
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1210
27Recursive function to do substring search1206
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1132
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1112
32Maximum Subarray Sum using Divide and Conquer1110
33Remove characters from first string which are in second1077
34Find Leaders in an Array1065
35Swap nodes in the linked list1044
36Find the Number Occurring Odd Number of Times in an Array1009
37Arrange given Numbers to Form the Biggest Number II997
38Find the second most frequent character996
39Given a string find its first non-repeating character976
40Find Triplet in Array With a Given Sum968
41Total number of occurrences of a given item in the linked list960
42Given a sorted array and a number x, find the pair in array whose sum is closest to x959
43A Program to check if strings are rotations of each other or not956
44Print all possible words from phone digits940
45Find the Missing Number932
46Rearrange Positive and Negative Numbers Alternatively in Array926
47Longest Palindromic Substring910
48Segregate even and odd nodes in a linked list893
49Print Longest common subsequence889
50Union and Intersection of Two Linked Lists879
51Transform one string to another using minimum number of given operations874
52Check rearranged string can form a palindrome857
53Rearrange given Array in Maximum Minimum Form852
54Iterative Implementation of Quick Sort841
55Count Possible Triangles828
56Multiplication of Two Matrices809
57Check if the linked list is palindrome803
58Count of Triplets With Sum Less than Given Value802
59Rotate a Linked List801
60Stock Buy Sell to Maximize Profit797
61Insertion Sort773
62Concatenation of two strings768
63Tug of War767
64Count Number of Substrings with K Distinct Character’s763
65Print all duplicates in the input string762
66Find Nearest Greater and Smaller Element751
67The Celebrity Problem745
68Find Pythagorean Triplets from Array744
69Reverse String Without Temporary Variable738
70Remove ‘b’ and ‘ac’ from a given string738
71Find all Common Elements in Given Three Sorted Arrays735
72Remove all duplicates in an unsorted linked list716
73Find the Row with Maximum Number of 1’s712
74Find the subarray whose sum is equal to a given number X705
75Find the Peak Element from an Array705
76Remove Minimum Characters so that Two Strings Become Anagrams697
77Addition of Two Matrices692
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s685
81Implement Two Stacks in an Array682
82Maximum Sum of Non Consecutive Elements679
83Maximum Product Subarray II665
84Lexicographic rank of string662
85Multiplication of Previous and Next653
86Check if Two given Matrices are Identical653
87Subtraction of Two Matrices642
88Merge K Sorted Arrays and Print Sorted Output639
89Move All the Zeros to the End of the Given Array637
90Divide a string in N equal parts634
91Online Algorithm for Checking Palindrome in a Stream629
92Form Minimum Number from Given Sequence of D’s and I’s628
93Check whether two strings are anagram of each other624
94Remove recurring digits in a given number622
95Sort a linked list that is sorted alternating ascending and descending617
96Maximum Circular Subarray Sum616
97Sort a stack using a temporary stack614
98Find the Minimum Element in a Sorted and Rotated Array610
99Move last element of the Linked List at first place610
100Subarray and Subsequence607
101First Circular Tour to Visit all the Petrol Bunks605
102Largest Subarray with Equal Number of 0’s and 1’s602
103Compare two strings(linked lists)601
104Flattening a linked list599
105Maximum Element in an Array which is Increasing and then Decreasing598
106Palindrome Permutations of a String594
107Elements Appear more than N/K times in Array587
108Palindromes in a given range585
109Print all permutations with repetition583
110Majority Element582
111Run length encoding582
112Minimum insertions to form a shortest palindrome580
113Pangram Checking580
114Rearrange a given linked list in-place572
115Minimum Characters to be Added at Front to Make String Palindrome572
116Remove all duplicates in a sorted linked list571
117Merge a linked list into another at alternate positions570
118Most repeating character in a string569
119Rotate string to get lexicographically minimum string568
120Minimum number of Merge Operations to make an Array Palindrome567
121Repeated Subsequence of Length Two or More564
122Print all anagrams together in a sequence of words560
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem548
125Two Sum Leetcode Solution545
126Clone a Linked List with next and random pointer543
127Merge Overlapping Intervals II543
1283Sum Leetcode Solution542
129Transpose of a Matrix533
130Size of The Subarray With Maximum Sum533
131Remove Extra Spaces from a String530
132Removing Spaces from a String using stringstream528
133Remove duplicates from a string526
134Check if a given string is a rotation of a palindrome526
135Longest Palindrome can be Formed by Removing or Rearranging Characters525
136Partition Problem524
137Smallest Palindrome after Replacement524
138Maximum Sum Increasing Subsequence523
139Check whether Strings are K Distance Apart or Not515
140Generate all Binary Strings from Given Pattern515
141Length of Longest valid Substring510
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized507
143Insert Node in the Sorted Linked List507
144Delete Last Occurrence505
145Check if Two given Strings are Isomorphic to each other501
146Maximum difference between two elements such as larger element comes after smaller494
147Program to Toggle all Characters in a String493
148Given string is interleaving of two other strings or not489
149Count Minimum Steps to Get the given Array486
150Merge sort better than quick sort for linked lists484
151Number of Smaller Elements on Right Side483
152Check length of a String is Equal to the Number Appended at its Last481
153Find Pair with Given Difference480
154Check if all Rows of a Matrix are Circular Rotations of Each Other479
155Find nth node of the Linked list from the end476
156Longest Common Prefix using Divide and Conquer476
157Sort 0s 1s and 2s in an Array468
158Find a Fixed Point in a Given Array467
159Print all interleavings of given two strings467
160Compare Two Version Numbers465
161Reverse words in a given string462
162Merge two sorted linked lists such that merged list is in reverse order462
163Find the Subarray of given length with Least Average461
164Reorder Array Using Given Indexes460
165Print Reverse of a string (Recursion)459
166Median of Two Sorted Arrays LeetCode Solution459
167Split linked list using alternate nodes458
168Print string of odd length in ‘X’ format445
169Print all Palindromic Partitions of a String441
170Find K Length Subarray of Maximum Average440
171Swap Kth Node from beginning with Kth Node from End440
172Find Element Using Binary Search in Sorted Array439
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions426
175Flatten a multilevel linked list424
176Maximum Length of Chain Pairs421
177Shortest Superstring Problem421
178Check if String Follows Order of Characters by a Pattern or not420
179Sorting a K Sorted Array415
180Sort a String According to Another String413
181Longest Span with same Sum in two Binary Arrays II404
182Reverse a Linked List in groups402
183Find a Sorted Subsequence of size 3401
184Recursively print all the sentences that can be formed from list of word lists399
185Program to add two binary digits398
186Longest Common Prefix Using Binary Search II395
187Find the two Numbers with Odd Occurrences in an Unsorted Array394
188Reverse a Singly Linked List (Iterative/Non-Recursive)393
189Caesar Cipher389
190Kth Non-repeating Character388
191Rearrange a linked list in Zig-Zag386
192Check if String can Become Empty by Recursively Deleting given Substring384
193Longest Common Prefix Word by Word Matching381
194Pancake Sorting380
195Rotate Image by 90 degrees380
196Permutations of a Given String Using STL373
197Perfect Reversible String372
198Merging Two Sorted Arrays368
199Increasing Subsequence of Length three with Maximum Product368
200Sort a linked list with 0s, 1s and 2s367
2011`s and 2`s complement of binary number367
202Find First non-repeating character in a string366
203Find the point where a monotonically increasing function becomes positive first time366
204Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes366
205Four Elements that Sum to Given363
206List items containing all characters of a given word360
207Delete N nodes after M359
208Count Number of Occurrences in a Sorted Array354
209Longest Common Prefix using Character by Character Matching354
210Palindrome string (number)350
211Split a string348
212Minimum Characters to be Removed to Make a Binary String Alternate344
213Check if a Linked list of Strings form a Palindrome341
214Recursive Implementation of atoi()341
215Print All Distinct Elements of the Array339
216Sorting the array of strings337
217Even Substring Count336
218Maximum occurring character in a string336
219Convert a String that is Repetition of a Substring of Length K335
220Valid Parentheses LeetCode Solution334
221Find the first Repeating Number in a Given Array333
222Reverse a singly linked list recursively333
223Print Shortest Path to Print a String on Screen331
224Can we reverse a linked list in less than O(n) time ?329
225Binary Tree to Doubly linked list329
226Nth Character in Concatenated Decimal String328
227Convert string1 to string2 in one edit327
228Reverse a String using Stack326
229wildcard character matching325
230Sort Elements by Frequency II324
231Maximum Subarray Leetcode Solution323
232Lower Case To Upper Case323
233Count the number of words318
234Merge Two Sorted Arrays317
235Split Four Distinct Strings316
236Find the Lost Element From a Duplicated Array315
237Find middle of the Linked List312
238Longest Common Subsequence with Permutations309
239Count the Pairs at Same Distance as in English Alphabets308
240Matrix Chain Multiplication using Dynamic Programming307
241Next Greater Element in an Array303
242Palindrome Permutation298
243Roman to Integer Leetcode Solution293
244Find Nth Node292
245Searching a node in a Binary Search Tree291
246Find All Pairs With a Given Difference290
247Delete a Tree286
248Triplet from three linked lists with given sum286
249String(represents an integer) to value284
250Reverse a String283
251Word Search Leetcode Solution283
252Reverse Bits282
253Print all Possible Ways to Break a String in Bracket Form281
254Delete a node under given conditions280
255Binary Tree278
256Change Gender of a given String278
257How to Efficiently Implement k Stacks in a Single Array?277
258Sort an array of strings277
259Count Pairs With Given Sum275
260First non Repeating Element274
261Number of sub-strings which recursively add up to 9273
262Meeting Rooms II LeetCode Solution273
263Toeplitz Matrix273
264Repeated Substring Pattern272
265Longest Common Extension271
266Move all negative elements to one side of array270
267Remove middle points in a linked list of line segments270
268N queen problem269
269Remove spaces from a string268
270Longest Palindromic Substring LeetCode Solution266
271Shuffle a given Array264
272Min Stack263
273Number of Islands LeetCode Solution260
274Dijkstra Algorithm259
275Cuckoo sequence program259
276House Robber Leetcode Solution258
277Max stack258
278Find, second, frequent, character257
279Most Frequent Element in an Array256
280Minimize the maximum difference between the heights254
281Fibonacci numbers253
282Clone a linked list with next and random pointer (Hashing)252
283Search Insert Position Leetcode Solution251
284Expression Evaluation250
285Sort linked which is sorted on absolute values250
286Subset Leetcode249
287Sudoku Solver249
288Valid Palindrome Leetcode Solution248
289Plus One Leetcode Solution247
290KMP Algorithm247
291Number Of 1 bits246
292Evaluation of Postfix Expression246
293Word Search246
294Combination Sum Leetcode Solution245
295How to Delete a Linked List245
296Reverse words in a string245
297Min Stack Leetcode Solution244
298Backspace String Compare241
299Set Matrix Zeroes238
300Rabin Karp Algorithm237
301Pair of Positive Negative Values in an Array236
302Merge Sorted Arrays Leetcode Solution236
303Sqrt(x) Leetcode Solution236
304Reversing a Queue236
305Common elements in all rows of a given matrix233
306Subarray with 0 sum233
307Tower Of Hanoi233
308Combination Sum231
309Delete middle element of a stack230
310Product of array except self230
311Integer to Roman Leetcode Solution230
312Contains Duplicate II Leetcode Solution230
313String Compression228
314Pascal Triangle Leetcode228
315Intersection of Two Arrays II Leetcode Solution228
316Reverse individual words226
317Count subarrays with equal number of 1’s and 0’s225
318Segregate even and odd numbers225
319Minimum swaps required to bring all elements less than or equal to k together225
320Construct Binary Tree from Given Inorder and Preorder Traversals225
321Count of index pairs with equal elements in an array225
322Add Binary Leetcode Solution224
323Find Top K (or Most Frequent) Numbers in a Stream224
324Implementation of Deque using Doubly Linked List224
325Bellman Ford Algorithm224
326Single Number Leetcode Solution223
327Sliding Window Technique223
328Minimum Value to Get Positive Step by Step Sum Leetcode Solution223
329Contains Duplicate222
330Palindrome Linked List Leetcode Solution221
331Sort elements by frequency221
332Second Most Repeated Word in a Sequence221
333Arithmetic Expression Evaluation221
334Find sum of non-repeating elements (distinct) elements in an array220
335Pow(x, n) Leetcode Solution219
336Page Replacement Algorithms in Operating Systems219
337Count Odd Numbers in an Interval Range Leetcode Solution219
338Postfix to Infix Conversion219
339Next Permutation218
340Group Words With Same Set of Characters218
341Design a stack that supports getMin() in O(1) time and O(1) extra space218
342Maximum Number of Balloons Leetcode Solution217
343Kruskal Algorithm217
344Sum of minimum and maximum elements of all subarrays of size k216
345Longest Common Prefix Leetcode Solution216
346Smallest Subarray with k Distinct Numbers216
347Find Lucky Integer in an Array Leetcode Solution215
348Scramble String215
349Maximum Subarray215
350Third Maximum Number Leetcode Solution215
351Permutations Leetcode Solution214
352K-th Smallest Element in a Sorted Matrix214
353Top K Frequent Words214
354Longest Substring Without Repeating Characters LeetCode Solution214
355Convex Hull Algorithm214
356Find the Town Judge Leetcode Solution213
357Find Numbers with Even Number of Digits Leetcode Solution212
358Sorting array using Stacks212
359Minimum operation to make all elements equal in array212
360Count subarrays having total distinct elements same as original array212
361Majority Element Leetcode Solution210
362Special Number210
363Number of Good Pairs Leetcode Solution210
364Evaluate Division210
365Given two unsorted arrays find all pairs whose sum is x209
366Swap Nodes in Pairs Leetcode Solutions209
367Spiral Matrix LeetCode Solution209
368First element occurring k times in an array209
369Prefix to Infix Conversion208
370Minimum Path Sum207
371Check if two arrays are equal or not207
372Count Primes Leetcode Solutions207
373Huffman Coding207
374Merge Two Sorted Lists Leetcode Solutions207
375Missing Number Leetcode Solution206
376Pascal’s Triangle II Leetcode Solution206
377Single Number206
378Best Time to Buy and Sell Stock  II Leetcode Solution206
379Reversing the First K elements of a Queue206
380Reverse a Number Using Stack206
381Group Anagrams205
382Minimum Steps to reach target by a Knight205
383Maximal Square205
384Search in Rotated Sorted Array Leetcode Solution205
385Minimum Absolute Difference Leetcode Solution205
386Find duplicates in a given array when elements are not limited to a range204
387House Robber II Leetcode Solution204
388Sort Array by Increasing Frequency Leetcode Solution204
389Maximum Distance Between two Occurrences of Same Element in Array203
390Power of Two Leetcode Solution203
391Running Sum of 1d Array Leetcode Solution203
392Top K Frequent Elements202
393Find Minimum In Rotated Sorted Array202
394How to Implement Stack Using Priority Queue or Heap?202
395Palindrome Substring Queries202
396Find All Numbers Disappeared in an Array Leetcode Solution202
397Find the first repeating element in an array of integers202
398Matrix Diagonal Sum Leetcode Solution202
399Convert String To Int202
400Maximum possible difference of two subsets of an array201
401Fizz Buzz Leetcode201
402Expression Contains Redundant Bracket or Not201
403Zigzag Conversion201
404Unique Paths Leetcode Solution201
405Sorting using trivial hash function201
406Unique Paths201
407Subarray Sum Equals k201
408Find the Closest Palindrome number201
409Check if Array Contains Contiguous Integers With Duplicates Allowed201
410Smallest Element Repeated Exactly K Times200
411Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
412How Many Numbers Are Smaller Than the Current Number Leetcode Solution200
413Sort Integers by The Number of 1 Bit Leetcode Solution200
414Cumulative Frequency of Count of Each Element in an Unsorted Array199
415Range Sum Query 2D – Immutable Leetcode Solution199
416Find Number of Employees Under every Employee199
417Subset sum problem199
418Leetcode Permutations199
419Max Consecutive Ones Leetcode Solution199
420Find Winner on a Tic Tac Toe Game Leetcode Solution198
421Length of the largest subarray with contiguous elements198
422Happy Number Leetcode Solution198
423Coin Change 2 Leetcode Solution198
424Letter Case Permutation197
425Reverse Integer197
426Decode String197
427Difference between highest and least frequencies in an array197
428Implement Stack and Queue using Deque197
429Subarray Sum Equals K LeetCode Solution197
430Find top three repeated in array197
431Print All Distinct Elements of a Given Integer Array197
432Sort a stack using recursion197
433Nth Catalan Number196
434Best Time to Buy and Sell Stock III Leetcode Solution196
435Monotonic Array LeetCode Solution196
436Remove Duplicates from Sorted Array Leetcode Solution196
437LRU Cache Implementation196
438Fibonacci Number LeetCode Solution196
439Print all subarrays with 0 sum196
440Sum of Subarray Ranges Leetcode Solution195
441Generate a String With Characters That Have Odd Counts Leetcode Solution194
442Count Substrings with equal number of 0s, 1s and 2s194
443Find The Duplicate Number194
444Subarrays with distinct elements194
445Maximum Depth of Binary Tree Leetcode Solution194
446Capacity To Ship Packages Within D Days Leetcode Solution194
447Reverse a Stack Using Recursion194
448Reverse Vowels of a String Leetcode Solution194
449Check If N and Its Double Exist Leetcode Solution194
450Find Median from data Stream193
451Merge Two Sorted Linked Lists193
452Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
453Integer to English words193
454Kth largest element in an Array Leetcode Solutions193
455Reverse Words in a String III LeetCode Solution193
456Find the Duplicate Element192
457Prim’s Algorithm192
458Trapping Rain Water Leetcode Solution192
459Bipartite Graph192
460Delete a Node from linked list without head pointer192
461Shuffle the Array Leetcode Solution192
462Find the Difference Leetcode Solution191
463Longest Common Subsequence191
464Target Sum191
465Count and Say191
466Reverse a String191
467Remove Minimum Number of Elements Such That no Common Element Exist in both Array191
468Find elements which are present in first array and not in second190
469Find all pairs (a, b) in an array such that a % b = k190
470Excel Sheet Column Number Leetcode Solution190
471Count pairs from two linked lists whose sum is equal to a given value190
472Balanced Binary Tree Leetcode Solution190
473Edit Distance190
474Priority Queue Using Singly Linked List190
475Sorting a Queue without Extra Space190
476Iterative Tower of Hanoi190
477Find Common Characters Leetcode Solution190
478Floyd Warshall Algorithm189
479The K Weakest Rows in a Matrix Leetcode Solution189
480Concatenation of Array LeetCode Solution189
481Text Justification LeetCode Solution189
482Fizz Buzz189
483Longest Common Prefix using Trie189
484Next Greater Element I Leetcode Solution188
485Degree of an array188
486Kids With the Greatest Number of Candies Leetcode Solution188
487Design Parking System Leetcode Solution188
488Reverse a linked list188
489Minimum Moves to Equal Array Elements Leetcode Solution188
490Find First and Last Position of Element in Sorted Array Leetcode Solution188
491Number of Steps to Reduce a Number to Zero Leetcode Solution187
492Prefix to Postfix Conversion187
493Valid Parenthesis String187
494Kth Largest Element in a Stream Leetcode Solution187
495Word Ladder LeetCode Solution187
496Longest subarray not having more than K distinct elements187
497Merge Overlapping Intervals187
498MiniMax Algorithm186
499Top View of Binary Tree186
500Pair with given product186
501Slowest Key Leetcode Solution186
502Find subarray with given sum (Handles Negative Numbers)186
503Multiply Strings Leetcode Solution186
504Flood Fill LeetCode186
505Find four elements that sum to a given value (Hashmap)186
506Shortest Palindrome186
507Zigzag Conversion LeetCode Solution186
508Postfix to Prefix Conversion185
509The Stock Span Problem185
510Count and Say Leetcode Solution185
511Priority Queue in C++185
512Find N Unique Integers Sum up to Zero Leetcode Solution185
513Jump Game Leetcode Solution185
514Convert array into Zig-Zag fashion185
515Find Index of Closing Bracket for a Given Opening Bracket in an Expression184
516Substring With Concatenation Of All Words184
517Length of Last Word Leetcode Solution184
518Move Zeroes LeetCode Solution184
519Max Area of Island184
520Find any one of the multiple repeating elements in read only array184
521Implement a stack using single queue184
522Check if a given array contains duplicate elements within k distance from each other183
523Find distinct elements common to all rows of a matrix183
524Peak Index in a Mountain Array183
525Next Greater Frequency Element183
526Mobile Numeric Keypad Problem183
527Shuffle String Leetcode Solution183
528Recursion183
529Longest Common Prefix using Sorting182
530Iterative Inorder Traversal of a Binary Tree182
531Intersection of Two Arrays182
532Implement Stack using Queues182
533Rearrange a binary string as alternate x and y occurrences182
534Find missing elements of a range182
535Largest Sum Contiguous Subarray182
536Count number of triplets with product equal to given number182
537Smallest Subarray With all Occurrences of a Most Frequent Element181
538Delete Node in a Linked List Leetcode Solution181
539Convert a normal BST to Balanced BST181
540Contiguous Array Leetcode181
541Relative Sort Array Leetcode Solution181
542Last Stone Weight181
543Excel Sheet Column Title Leetcode Solution181
544Valid Sudoku180
545Change the Array into Permutation of Numbers From 1 to N180
546Koko Eating Bananas Leetcode Solution180
547Group Multiple Occurrence of Array Elements Ordered by first Occurrence180
548Container with Most Water179
549Linked List Cycle II LeetCode Solution179
550Distribute Candies to People Leetcode Solution179
551Best Time to Buy and Sell Stock179
552Is Subsequence Leetcode Solution179
553N-th Tribonacci Number Leetcode Solution179
554K-th Distinct Element in an Array179
555Isomorphic Strings Leetcode Solution179
556Minimum Bracket Reversals179
557Integer to Roman178
558Minimum Delete Operations to make all Elements of Array Same178
559Assign Cookies Leetcode Solution178
560Minimum Operations to convert X to Y178
561First negative integer in every window of size k178
562Find Words That Can Be Formed by Characters Leetcode Solution178
563Number of Provinces Leetcode Solution178
564Sum of Left Leaves Leetcode Solutions178
565Implementation of Deque using circular array178
566Jewels and Stones Leetcode Solution178
567Minimum Knight Moves LeetCode Solution177
568Shuffle an Array177
569Island Perimeter Leetcode Solution177
570Unique Binary Search Trees177
571Build Array From Permutation Leetcode Solution177
572Gold Mine Problem177
573Convert Sorted Array to Binary Search Tree Leetcode Solution177
574Largest Perimeter Triangle Leetcode Solution177
575Arrange given numbers to form the biggest number177
576Check for Balanced Parentheses in an Expression177
577Valid Anagrams177
578Summary Ranges Leetcode Solution177
579Remove Linked List Elements Leetcode Solution176
580Trapping Rain Water LeetCode Solution176
58101 Matrix LeetCode Solution176
582Maximum path sum in a triangle176
583LRU Cache LeetCode Solution176
584Hamming Distance176
585Maximum sum rectangle in a 2D matrix176
586Combinations Leetcode Solution176
587Rotate List Leetcode Solution175
588Count the number of nodes at given level in a tree using BFS175
5893Sum Closest LeetCode Solution175
590Decode Ways175
591The Knapsack Problem175
592Count all subsequences having product less than K175
593Find the smallest positive integer value that cannot be represented as sum of any subset of a given array175
594Minimum number of subsets with distinct elements174
595Minimum insertions to form a palindrome with permutations allowed174
596Shortest Path in a Grid with Obstacles Elimination LeetCode Solution174
597Distance Between Bus Stops Leetcode Solution173
598Insert Interval Leetcode Solution173
599Maximum Distance in Array173
600Maximum Number of Chocolates to be Distributed Equally Among k Students173
601Same Tree LeetCode Solution173
602Bubble sort using two Stacks173
603Minimum number of distinct elements after removing m items173
604Find minimum difference between any two elements173
605Sieve of Eratosthenes172
606How to check if two given sets are disjoint?172
607Sort Characters By Frequency LeetCode Solution172
608XOR Operation in an Array Leetcode Solution172
609Stone Game LeetCode172
610Rotate Image LeetCode Solution172
611Longest Increasing Subsequence172
612Reverse a stack without using extra space in O(n)171
613Painting Fence Algorithm171
614Permutation in String Leetcode Solution171
615Frog Jump Leetcode Solution171
616Defanging an IP Address Leetcode Solution171
617Find if an Expression has Duplicate Parenthesis or Not171
618Replace Elements with Greatest Element on Right Side Leetcode Solution171
619License Key Formatting Leetcode Solution171
620Applications of Breadth First Search and Depth First Search171
621Smallest Good Base170
622Find the Duplicate Number LeetCode Solution170
623Minimum Cost to Hire K Workers170
624Word Wrap Problem170
625K Empty Slots LeetCode170
626Word Pattern170
627Sort Array By Parity LeetCode Solution170
628Remove All Occurrences of a Substring LeetCode Solution170
629House Robber170
630Minimum Depth of Binary Tree Leetcode Solution169
631Non-overlapping sum of two sets169
632Optimal Account Balancing LeetCode Solution169
633Isomorphic Strings169
634Maximum Consecutive Numbers Present in an Array169
635Segregate 0s and 1s in an Array169
636Tracking current Maximum Element in a Stack169
637Longest Substring with At Least K Repeating Characters LeetCode Solution169
638Best Time to Buy and Sell Stock LeetCode Solution169
639Distance of nearest cell having 1 in a binary matrix169
640Printing brackets in Matrix Chain Multiplication Problem169
641Binary Tree Zigzag Level Order Traversal LeetCode Solution168
642Valid Palindrome II Leetcode Solution168
643Find Sum of all unique sub-array sum for a given array168
644Merge Two Balanced Binary Search Trees168
645Iterative Method to find Height of Binary Tree168
646Longest Substring with At Most K Distinct Characters LeetCode Solution168
647Wiggle Sort168
648Moving Average from Data Stream Leetcode Solution168
649Employee Free Time LeetCode Solution168
650Coin Change Problem168
651Count Good Nodes in Binary Tree Leetcode Solution167
652Maximum difference between first and last indexes of an element in array167
653Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions167
654Reorganize String167
655Find Maximum Level sum in Binary Tree167
656Kth Missing Positive Number Leetcode Solution167
657How to Create Mergable Stack?167
658Queries for counts of array elements with values in given range167
659Sum of All Odd Length Subarrays Leetcode Solution167
660Path With Maximum Minimum Value LeetCode Solution167
661Check If It Is a Straight Line Leetcode Solution167
662Best Time to Buy and Sell Stock with Cooldown Leetcode Solution166
663Maximum Number of Occurrences of a Substring Leetcode Solution166
664Find the Distance Value Between Two Arrays Leetcode Solution166
665Flipping an Image LeetCode Solution166
666GCD Of Two Numbers166
667Strobogrammatic Number LeetCode Solution166
668Print the Fibonacci numbers in reverse order165
669Delete consecutive same words in a sequence165
670Reducing Dishes LeetCode Solution165
671Find Largest d in Array such that a + b + c = d165
672Remove Invalid Parentheses Leetcode Solution165
673Find pairs with given sum such that elements of pair are in different rows165
674K Empty Slots165
675Convert an array to reduced form165
676Valid Palindrome165
677Letter Combinations of a Phone Number165
678Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest165
679Factorial Trailing Zeroes Leetcode Solution164
680Check if a queue can be sorted into another queue using a stack164
681To Lower Case Leetcode Solution164
682Number of Dice Rolls With Target Sum LeetCode Solution164
683Partition Labels LeetCode Solution164
684BFS vs DFS for Binary Tree164
685Maximum Number of Coins You Can Get Leetcode Solution164
686Inorder Successor of a node in Binary Tree164
687Check If Two String Arrays are Equivalent Leetcode Solution164
688Increasing Decreasing String Leetcode Solution164
689Power of Four Leetcode Solution163
690Partition Array Into Three Parts With Equal Sum Leetcode Solution163
691Edit Distance LeetCode Solution163
692Find Leaves of Binary Tree LeetCode Solution163
693Form minimum number from given sequence163
694Valid Perfect Square Leetcode Solution163
695Lucky Numbers in a Matrix Leetcode Solution163
696Subset Sum Leetcode163
697Find the Smallest Divisor given a Threshold Leetcode Solution163
698Recover Binary Search Tree163
699Delete Nth node from the end of the given linked list163
700Longest Increasing Path in a Matrix LeetCode Solution163
701Populating Next Right Pointers in Each Node163
702Permutation Sequence LeetCode Solution163
703String to Integer (atoi) LeetCode Solution162
704Reversing a Queue using Recursion162
705Construct BST from given Preorder Traversal162
706Reverse Only Letters LeetCode Solution162
707Dynamic Programming Basics162
708Binary Tree zigzag level order Traversal162
709Sort Array by Increasing Frequency Leetcode Solution162
710Unique Paths II Leetcode Solution162
711Merge Two Binary Trees LeetCode Solution162
712Maximum Product of Two Elements in an Array Leetcode Solution162
713Find whether an array is subset of another array162
714Ugly Number Leetcode Solution162
715Decompress Run-Length Encoded List Leetcode Solution161
716Binomial Coefficient161
717Reservoir Sampling161
718Convert a Number to Hexadecimal Leetcode Solution161
719Keyboard Row Leetcode Solution161
720Robot Room Cleaner Leetcode Solution161
721Add and Search Word – Data structure design LeetCode161
722Perform String Shifts Leetcode160
723Bulb Switcher LeetCode Solution160
724Majority Element II Leetcode Solution160
725Finding K closest element160
726Restore IP Addresses Leetcode Solution160
727Find the node with minimum value in a Binary Search Tree160
728Find the largest multiple of 3160
729Word Pattern LeetCode Solution159
730Numbers with prime frequencies greater than or equal to k159
731Check if Two Expressions With Brackets are Same159
732Minimum Cost For Tickets Leetcode Solution159
733Find Maximum Depth of Nested Parenthesis in a String159
734Rank Transform of an Array Leetcode Solution159
735Hamming Distance Leetcode Solution159
736Sum of f(a[i], a[j]) over all pairs in an array of n integers159
737Snakes and Ladders LeetCode Solution159
738Find Pair with Greatest Product in Array159
739Race Car LeetCode Solution159
740Student Attendance Record I Leetcode Solution158
741Morris Traversal158
742Maximum Product of Three Numbers LeetCode Solution158
743Tiling Problem158
744Non-decreasing Array LeetCode Solution158
745Minimum time required to rot all oranges158
746Merge K Sorted Linked Lists158
747Number of Islands II LeetCode Solution158
748Minimum Distance Between BST Nodes Leetcode Solution158
749Minimum Height Trees158
750Longest Span with same Sum in two Binary arrays158
751Generate all possible sorted arrays from alternate elements of two given sorted arrays158
752First Unique Character in a String LeetCode Solution158
753Queue based approach for first non-repeating character in a stream158
754Maximum 69 Number Leetcode Solution158
755Find unique character in a string158
756Invert Binary Tree LeetCode Solution158
757Binary Tree Maximum Path Sum LeetCode Solution158
758Kth ancestor of a node in binary tree157
759Minimize Maximum Pair Sum in Array LeetCode Solution157
760Sorted Linked List to Balanced BST157
761Linked List Cycle157
762Remove Nth Node From End of List Leetcode Solution157
763Best Meeting Point LeetCode Solution157
764Find if Path Exists in Graph Leetcode Solution157
765Diagonal Traversal of Binary Tree157
766Largest subarray with equal number of 0s and 1s157
767Maximum Depth of N-ary Tree Leetcode Solution157
768String Compression LeetCode Solution157
769Stack Permutations (Check if an array is stack permutation of other)157
770Remove brackets from an algebraic string containing + and – operators157
771Maximum Length of a Concatenated String with Unique Characters Leetcode Solution156
772Check If Array Pairs Are Divisible by k LeetCode Solution156
773Final Prices With a Special Discount in a Shop Leetcode Solution156
774Total Numbers With no Repeated Digits in a Range156
775Symmetric Tree Leetcode Solution156
776Partition to K Equal Sum Subsets Leetcode Solution156
777Largest Rectangle in Histogram LeetCode Solution156
778Special Array With X Elements Greater Than or Equal X Leetcode Solution156
779Find All Duplicates in an Array LeetCode Solution156
780Elements to be added so that all elements of a range are present in array156
781Evaluate Reverse Polish Notation LeetCode Solution155
782k-th missing element in increasing sequence which is not present in a given sequence155
783Search a 2D Matrix II Leetcode Solution155
784Count items common to both the lists but with different prices155
785Split a String in Balanced Strings Leetcode Solution155
786Jump Game155
787Largest rectangular sub-matrix whose sum is 0155
788Program for Bridge and Torch problem155
789Find Median from Data Stream LeetCode Solution155
790Search in a Binary Search Tree Leetcode Solution154
791Transpose Graph154
792Sort an array according to the order defined by another array154
793Base 7 Leetcode Solution154
794Deletion in a Binary Tree154
795Longest Subarray Having Count of 1s One More than Count of 0s154
796Maximum Difference Between Increasing Elements LeetCode Solution154
797Course Schedule II – LeetCode154
798N-Queens LeetCode Solution154
799Minimum Jumps to Reach Home LeetCode Solution154
800Number of NGEs to the Right154
801Check for Palindrome after every character replacement Query154
802Valid Number154
803Circular Queue154
804Growable array based stack154
805Print a Binary Tree in Vertical Order154
806Interval Tree154
807One Edit Distance LeetCode Solution153
808Minimum swaps to make sequences increasing153
809Spiral Matrix II Leetcode Solution153
810Reorder Data in Log Files LeetCode Solution153
811Last Stone Weight II LeetCode Solution153
812String comparison containing wildcards153
813Minimum number of jumps to reach end153
814Nested List Weight Sum II LeetCode Solution153
815Sort Array By Parity II Leetcode Solution153
816Remove Duplicates from Sorted List II153
817Merge Sorted Array LeetCode Solution153
818Minimum Time Visiting All Points Leetcode Solution153
819Get Maximum in Generated Array Leetcode Solution153
820Number Complement Leetcode Solution153
821Count quadruples from four sorted arrays whose sum is equal to a given value x153
822Nearest Exit from Entrance in Maze LeetCode Solution153
823Remove Duplicates from Sorted List LeetCode Solution152
824Maximum size subarray sum equals k152
825Convert BST to Min Heap152
826Regular Expression Matching152
827Crawler Log Folder Leetcode Solution152
828Maximum Profit in Job Scheduling Leetcode Solution152
829Iterative Preorder Traversal152
830Find all triplets with zero sum152
831A Space Optimized DP solution for 0-1 Knapsack Problem152
832Relative Ranks Leetcode Solution152
833Priority Queue using doubly linked list152
834Subarray Product Less Than K LeetCode Solution152
835Form Minimum Number From Given Sequence151
836Insert into a Binary Search Tree Leetcode Solution151
837Check if a given array can represent Preorder Traversal of Binary Search Tree150
838Given an Array of Pairs Find all Symmetric Pairs in it150
839Brick Wall LeetCode Solution150
840Subset with sum divisible by m150
841Level order Traversal in Spiral Form150
842Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution150
843Path with maximum average value150
844Valid Parentheses Leetcode Solution150
845Partition List Leetcode Solution150
846Minimum Number of Taps to Open to Water a Garden LeetCode Solution150
847Find the subarray with least average150
848Friends Pairing Problem150
849Find Maximum Sum Possible Equal Sum of Three Stacks150
850Top K Frequent Words LeetCode Solution150
851Binary Search Tree Search and Insertion150
852Design a Stack With Increment Operation Leetcode Solution150
853Can Place Flowers LeetCode Solution150
854Minimum Swaps to Make Strings Equal Leetcode Solution150
855Sum of nearest smaller and greater number150
856Alien Dictionary LeetCode Solution150
857Sort Colors150
858Maximum Nesting Depth of the Parentheses Leetcode Solution150
859Check whether a given Binary Tree is Complete or not149
860Balanced Expression with Replacement149
861Identify and Mark Unmatched Parenthesis in an Expression149
862Find All Possible Recipes from Given Supplies LeetCode Solution149
863Number of Days Between Two Dates LeetCode Solution149
864LCS (Longest Common Subsequence) of three strings149
865Minimum Sum Path in a Triangle149
866Missing Element in Sorted Array LeetCode Solution149
867Brightest Position on Street LeetCode Solution149
868Clone Graph LeetCode Solution149
869Guess Number Higher or Lower LeetCode Solution149
870Permutation Coefficient149
871Subsequence of Size K With the Largest Even Sum LeetCode Solution149
872Count Negative Numbers in a Sorted Matrix LeetCode Solution149
873Sorted Array to Balanced BST149
874Matrix Chain Multiplication149
875Count Distinct Elements in Every Window of Size K149
876Tree Traversal (Preorder, Inorder & Postorder)149
877Range LCM Queries149
878Count ways to reach the nth stair using step 1, 2 or 3148
879Find the Only Repetitive Element Between 1 to N-1148
880Range sum queries without updates148
881Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution148
882Diagonal Traverse LeetCode Solution148
883Sequences of given length where every element is more than or equal to twice of previous148
884Destination City Leetcode Solution148
885Repeated Substring Pattern LeetCode Solution148
886Check if stack elements are pairwise consecutive148
887Time Based Key-Value Store LeetCode Solution148
888Find Common Characters Leetcode Solution148
889Union and Intersection of two Linked Lists148
890GCDs of given index ranges in an array148
891An Interesting Method to generate Binary Numbers from 1 to n148
892Check if an Array is Stack Sortable147
893K’th Largest Element in BST when modification to BST is not allowed147
894Averages of Levels in Binary Tree147
895Shortest Word Distance Leetcode Solution147
896Diagonal Traversal LeetCode Solution147
897Three way partitioning of an array around a given range147
898Distinct adjacent elements in an array147
899Convert Sorted List to Binary Search Tree147
900Rearrange an Array Such that arr[i] is equal to i147
901Insert Delete GetRandom147
902Guess Number Higher or Lower II147
903Delete And Earn147
904BFS for Disconnected Graph147
905Spiral Matrix III LeetCode Solution147
906Design Browser History LeetCode Solution147
907Find distance between two nodes of a Binary Tree147
908Water Bottles Leetcode Solution147
909Vertical sum in a given binary tree146
910Maximum Score After Splitting a String Leetcode Solution146
911Robot Bounded In Circle LeetCode Solution146
912Queue using Stacks146
913Construct Complete Binary Tree from its Linked List Representation146
914Lemonade Change Leetcode Solution146
915Rearrange Spaces Between Words Leetcode Solution146
916Special Positions in a Binary Matrix Leetcode Solution146
917Minimum sum of multiplications of n numbers146
918Daily Temperatures Leetcode Solution146
919Set Matrix Zeroes Leetcode Solution146
920Construct the Rectangle Leetcode Solution145
921Alien Dictionary145
922Find all permuted rows of a given row in a matrix145
923Least Number of Unique Integers after K Removals Leetcode Solution145
924Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i145
925Number of Distinct Islands Leetcode Solution145
926Iterative Postorder Traversal Using Two Stacks145
927Check if the given array can represent Level Order Traversal of Binary Search Tree145
928Split Array Into Consecutive Subsequences144
929Construct BST from its given Level Order Traversal144
930Binary Tree Longest Consecutive Sequence LeetCode Solution144
9313 Sum144
932Maximum Subarray Sum Excluding Certain Elements144
933Merge Two Sorted Lists Leetcode144
934Count Subarrays with Same Even and Odd Elements144
935A program to check if a binary tree is BST or not144
936Largest area rectangular sub-matrix with equal number of 1’s and 0’s144
9374Sum144
938Palindrome Partitioning Leetcode Solution144
939Print Fibonacci sequence using 2 variables144
940Strongly Connected Component143
941Remove Duplicates from Sorted List II LeetCode Solution143
942Sliding Window Maximum143
943Number of Equivalent Domino Pairs Leetcode Solution143
944Stone Game II Leetcode143
945Create Maximum Number143
946Maximum Frequency Stack Leetcode Solution143
947Lexicographical Numbers Leetcode Solution143
948Queries for GCD of all numbers of an array except elements in a given range143
949Median of Two Sorted Arrays143
950Longest Palindromic Subsequence143
951Difference Array | Range update query in O(1)143
952Check if any two intervals overlap among a given set of intervals143
953Minimum Height Trees LeetCode Solution143
954Three Consecutive Odds Leetcode Solution142
955Dividing Array into Pairs With Sum Divisible by K142
956Can Make Arithmetic Progression From Sequence Leetcode Solution142
957My Calendar I LeetCode Solution142
958Trim a Binary Search Tree142
959All Unique Triplets that Sum up to a Given Value142
960Collect maximum points in a grid using two traversals142
961Infix to Postfix142
962Maximize Sum of Array after K Negations Leetcode Solution142
963Analyze User Website Visit Pattern LeetCode Solution142
964Find postorder traversal of BST from preorder traversal141
965Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space141
966Maximum Product Subarray141
967Binary array after M range toggle operations141
968Unique Paths II141
969Merging Intervals141
970Minesweeper LeetCode Solution141
971Kth Smallest Element in a BST Leetcode Solution141
972Count Submatrices With All Ones LeetCode Solution141
973Count Primes in Ranges141
974Find the Difference Leetcode Solution140
975Reverse Nodes in K-Group140
976Boundary Traversal of binary tree140
977Count pair with Given Sum140
978Sign of the Product of an Array LeetCode Solution140
979Intersection of Two Linked Lists LeetCode Solution140
980Word Break140
981Find Maximum of Minimum for Every Window Size in a Given Array140
982Symmetric Tree140
983Length of Longest Fibonacci Subsequence140
984Count subarrays where second highest lie before highest140
985Pattern Occurrences using Stack140
986K Closest Points to Origin Leetcode Solution140
987The Painter’s Partition Problem140
988Height of a generic tree from parent array140
989Longest Nice Substring LeetCode Solution140
990Friends Of Appropriate Ages LeetCode Solution139
991Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution139
992Largest divisible pairs subset139
993Maximum length subsequence with difference between adjacent elements as either 0 or 1139
994Newman-Conway Sequence139
995Asteroid Collision LeetCode Solution139
996Palindrome Partitioning139
997Product of Array Except Self LeetCode Solution139
998Binary Search Tree Delete Operation139
999Largest Number Leetcode Solution139
1000Climbing stairs139
1001Level Order Traversal of Binary Tree139
1002Valid Boomerang Leetcode Solution139
1003Graph Valid Tree LeetCode Solution138
1004Find Duplicate Subtrees138
1005Largest Substring Between Two Equal Characters Leetcode Solution138
1006Construction of Longest Increasing Subsequence (N log N)138
1007Double the first element and move zero to end138
1008Shortest Completing Word Leetcode Solution138
1009Boolean Parenthesization Problem138
1010Minimum Index Sum of Two Lists138
1011Segment Tree138
1012Merge Sort138
1013Maximum subsequence sum such that no three are consecutive138
1014Breadth First Search (BFS) for a Graph138
1015Scramble String LeetCode Solution138
1016Number Of Longest Increasing Subsequence138
1017Maximum Number of Ways to Partition an Array LeetCode Solution138
1018The Maze III LeetCode Solution138
1019Insertion in a Binary Tree138
1020Maximum Length of Repeated Subarray138
1021Find number of pairs in an array such that their XOR is 0138
1022String Matching in an Array Leetcode Solution137
1023Number of palindromic paths in a matrix137
1024Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’137
1025Compute nCr % p137
1026Longest subsequence such that difference between adjacents is one137
1027Kill Process LeetCode Solution137
1028Construct Binary Tree from given Parent Array representation137
1029Find the First Circular Tour that visits all the Petrol Pumps137
1030Rearrange array such that even positioned are greater than odd137
1031Maximum Product of Indexes of Next Greater on Left and Right137
1032Depth First Search (DFS) for a Graph137
1033Decrypt String from Alphabet to Integer Mapping Leetcode Solution137
1034Binary Search Tree137
1035Ugly Numbers137
1036Maximum Sum of 3 Non-Overlapping Subarrays137
1037Partition Equal Subset Sum136
1038Serialize and Deserialize Binary Tree136
1039Next Greater Element III LeetCode Solution136
1040Maximum weight transformation of a given string136
1041Morris Inorder Traversal136
1042Build an Array With Stack Operations Leetcode Solution136
1043Make The String Great Leetcode Solution136
1044Count minimum steps to get the given desired array136
1045K maximum sums of overlapping contiguous sub-arrays136
1046Level order traversal using two Queues136
1047Iterative Depth First Traversal of Graph136
1048First missing positive136
1049Maximum difference between frequency of two elements such that element having greater frequency is also greater135
1050Advantages of BST over Hash Table135
1051Custom Sort String Leetcode Solution135
1052Invalid Transactions LeetCode Solution135
1053Balanced Binary Tree135
1054Add two numbers135
1055Bitwise AND of Numbers Range LeetCode Solution135
1056Design Hit Counter LeetCode Solution135
1057Available Captures for Rook Leetcode Solution135
1058Kth Smallest Element in a Sorted Matrix LeetCode Solution134
1059Count pairs from two sorted arrays whose sum is equal to a given value x134
1060Path Sum II LeetCode Solution134
1061Validate Binary Search Tree134
1062Employee Importance LeetCode Solution134
1063Super Ugly Number133
1064Move all negative elements to end in order with extra space allowed133
1065Minimum Size Subarray Sum133
1066Lowest Common Ancestor133
1067Generate Parentheses Leetcode Solution133
1068Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution133
1069Ugly Number II LeetCode Solution133
1070Implement Trie (Prefix Tree) Leetcode Solution133
1071Defanging an IP Address LeetCode Solution133
1072Recover Binary Search Tree Leetcode Solution133
1073Rearrange array such that even index elements are smaller and odd index elements are greater133
1074Find Peak Element132
1075Find whether a subarray is in form of a mountain or not132
1076Binary Tree Right Side View LeetCode Solution132
1077Regular Expression Matching Regular Expression Matching LeetCode Solution132
1078Populating Next Right Pointers in Each Node Leetcode Solution132
1079Root to Leaf path with target sum Leetcode Solutions132
1080Largest BST Subtree LeetCode Solution132
1081Number of Closed Islands Leetcode Solution132
1082Remove Duplicates from Sorted Array II Leetcode Solution132
1083Find a Peak Element II LeetCode Solution132
1084Search in Sorted Rotated Array132
1085Subarrays with K Different Integers Leetcode Solution132
1086Find Smallest Range Containing Elements from k Lists131
1087Smallest Common Region Leetcode Solution131
1088Count Largest Group Leetcode Solution131
1089Combination Sum IV LeetCode Solution131
1090Types of Binary Tree131
1091Number of Students Doing Homework at a Given Time Leetcode Solution131
1092Day of the Year Leetcode Solution131
1093Longest Bitonic Subsequence131
1094Remove Palindromic Subsequences Leetcode Solution131
1095Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1096Consecutive Characters LeetCode Solution130
1097Number of siblings of a given Node in n-ary Tree130
1098Maximize Distance to Closest Person LeetCode Solution130
1099Minimum Absolute Difference in BST Leetcode Solution130
1100Print all triplets in sorted array that form AP130
1101Serialize and Deserialize Binary Tree LeetCode Solution130
1102Clone a Binary Tree with Random Pointers130
1103Binary Tree Data Structure130
1104Sum of Even Numbers After Queries129
1105Construct K Palindrome Strings LeetCode Solution129
1106Path Sum129
1107Find the minimum distance between two numbers129
1108Convert BST into a Min-Heap without using array129
1109Increasing Triplet Subsequence LeetCode Solution129
1110Print Next Greater Number of Q queries129
1111Level of Each node in a Tree from source node129
1112Palindrome Permutation LeetCode Solution129
1113Find maximum difference between nearest left and right smaller elements129
1114Remove duplicates from sorted array129
1115Cutting a Rod129
1116Distinct Subsequences129
1117Next Permutation Leetcode Solution129
1118Constant time range add operation on an array128
1119Iterative method to find ancestors of a given binary tree128
1120Reformat The String Leetcode Solution128
1121Minimum sum of squares of character counts in a given string after removing k characters128
1122Find Three Element From Different Three Arrays Such That a + b + c = sum128
1123Divisible Pairs Counting128
1124Mean of Array After Removing Some Elements Leetcode Solution128
1125Bottom View of a Binary Tree128
1126Maximum Product Subarray128
1127Valid Tic-Tac-Toe State LeetCode Solution128
1128Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution128
1129Third Maximum Number Leetcode Solution128
1130Longest Increasing Consecutive Subsequence127
1131Products of ranges in an array127
1132Thousand Separator Leetcode Solution127
1133Prime Palindrome LeetCode Solution127
1134Maximum Product of Splitted Binary Tree LeetCode Solution127
1135Delete Nodes and Return Forest Leetcode Solution127
1136Write Code to Determine if Two Trees are Identical127
1137Print Right View of a Binary Tree127
1138Minimum Score Triangulation of Polygon Leetcode Solution127
1139Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1140Palindromic Substrings Leetcode Solution126
1141Moser-de Bruijn Sequence126
1142Cells with Odd Values in a Matrix LeetCode Solution126
1143Search Insert Position126
1144Queries for Number of Distinct Elements in a Subarray126
1145Find maximum length Snake sequence126
1146Search an Element in Sorted Rotated Array126
1147Red-Black Tree Introduction125
1148Merge two BSTs with limited extra space125
1149Topological Sorting125
1150Maximum Binary Tree125
1151Subset Sum Problem in O(sum) space125
1152Swap Nodes In Pairs125
1153Maximize sum of consecutive differences in a circular array124
1154Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution124
1155Check Array Formation Through Concatenation Leetcode Solution124
1156Transform a BST to Greater sum Tree124
1157Diameter of N-Ary Tree LeetCode Solution124
1158Closest Binary Search Tree Value Leetcode Solution124
1159Priority Queue124
1160Print modified array after executing the commands of addition and subtraction124
1161Find Largest Value in Each Tree Row LeetCode Solution123
1162Minimum Sideway Jumps LeetCode Solution123
1163Golomb sequence123
1164Possible Bipartition LeetCode Solution123
1165Web Crawler LeetCode Solution123
1166Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution123
1167Search Suggestions System LeetCode Solution123
1168Kth Smallest Number in Multiplication Table Leetcode Solution123
1169Bus Routes Leetcode Solution123
1170Rotate Array122
1171Count even length binary sequences with same sum of first and second half bits122
1172Decision Tree122
1173Binary Tree to Binary Search Tree Conversion122
1174K’th Largest element in BST using constant extra space122
1175Compare Strings by Frequency of the Smallest Character Leetcode Solution122
1176Longest Repeated Subsequence122
1177Find the smallest binary digit multiple of given number122
1178Minimum Moves to Equal Array Elements LeetCode Solution122
1179Find a sorted subsequence of size 3 in linear time122
1180Minimum Cost to Move Chips to The Same Position LeetCode Solution122
1181Decrease Elements To Make Array Zigzag LeetCode Solution121
1182Given a binary tree, how do you remove all the half nodes?121
1183Matchsticks to Square Leetcode Solution121
1184Factorial Trailing Zeroes LeetCode Solution121
1185Swapping Nodes in a Linked List Leetcode Solution121
1186Graph and its representation121
1187First Bad Version121
1188Reformat Date LeetCode Solution120
1189Reverse a Path in BST using Queue120
1190Maximum number of segments of lengths a, b and c120
1191Count Pairs Whose Products Exist in Array120
1192Queue Reconstruction by Height120
1193Number of Orders in the Backlog Leetcode Solution120
1194Lowest Common Ancestor in Binary Search Tree120
1195Maximum sum of pairs with specific difference120
1196Contiguous Array LeetCode Solution120
1197Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1198Valid Triangle Number119
1199Path Crossing Leetcode Solution119
1200Maximum sum bitonic subarray119
1201Maximum Depth Of Binary Tree119
1202How to print maximum number of A’s using given four keys119
1203Closest Leaf in a Binary Tree LeetCode Solution119
1204Range Queries for Longest Correct Bracket Subsequence119
1205Sum of Left Leaves LeetCode Solution119
1206Champagne Tower LeetCode Solution118
1207Lowest Common Ancestor of a Binary Tree Leetcode Solution118
1208Moving Stones Until Consecutive Leetcode Solution118
1209Minimum Swaps To Make Sequences Increasing LeetCode Solution118
1210BST to a Tree with Sum of all Smaller Keys118
1211Integer Break LeetCode Solution117
1212Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution117
1213LRU Cache Leetcode Solution117
1214Perfect Squares LeetCode Solution117
1215Write a function to get the intersection point of two Linked Lists117
1216Concatenation of Array LeetCode Solution117
1217Array Queries for multiply replacements and product117
1218Divide Two Integers Leetcode Solution117
1219Guess The Word117
1220Kth Smallest Element in a BST117
1221Maximum Value at a Given Index in a Bounded Array LeetCode Solution116
1222Flatten 2D Vector LeetCode Solution116
1223Maximum sum of a path in a Right Number Triangle116
1224Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution116
1225Valid Perfect Square LeetCode Solution116
1226Sliding Window Median Leetcode Solution116
1227Replace two consecutive equal values with one greater116
1228Check if all levels of two Binary Tree are anagrams or not116
1229Queries on Probability of Even or Odd Number in given Ranges116
1230Power of Two115
1231Arithmetic Slices II – Subsequence LeetCode Solution115
1232New 21 Game115
1233Maximize Elements Using Another Array115
1234Range Sum Query using Sparse Table115
1235Maximum Array from Two given Arrays Keeping Order Same115
1236Check for Identical BSTs without building the trees114
1237Design Skiplist LeetCode Solution114
1238Find Minimum in Rotated Sorted Array II LeetCode Solution114
1239Bold Words in String LeetCode Solution114
1240The kth Factor of n Leetcode Solution114
1241Graph Cloning114
1242Check if each internal node of a BST has exactly one child114
1243Mean of range in array114
1244Check Completeness of a Binary Tree LeetCode Solution114
1245Longest Common Prefix Using Word by Word Matching114
1246Count Subsets Having Distinct Even Numbers113
1247Contiguous Array113
1248Parallel Courses II LeetCode Solution113
1249Maximum Product Subarray113
1250Largest Plus Sign Leetcode Solution113
1251Print modified array after multiple array range increment operations113
1252Find k-th smallest element in BST (Order Statistics in BST)113
1253Print Ancestors of a Given Binary Tree Node Without Recursion112
1254Find minimum number of merge operations to make an array palindrome112
1255Print n terms of Newman-Conway Sequence112
1256Symmetric Tree LeetCode Solution Leetcode Solution112
1257Minimum Remove to Make Valid Parentheses LeetCode Solution111
1258Image Overlap LeetCode Solution111
1259Missing Number111
1260Merge k Sorted Lists Leetcode Solution111
1261Count and Toggle Queries on a Binary Array110
1262Smallest Range II Leetcode Solution110
1263Check if two nodes are on the same path in a Tree110
1264Verify Preorder Serialization of a Binary Tree110
1265Number of elements less than or equal to a given number in a given subarray110
1266Excel Sheet Column Title LeetCode Solution110
1267Next greater element109
1268Palindrome Partitioning108
1269Orderly Queue LeetCode Solution108
1270Check If a String Can Break Another String Leetcode Solution108
1271Minimum Time to Collect All Apples in a Tree LeetCode Solution108
1272Different Ways to Add Parentheses Leetcode Solution107
1273Min Cost Climbing Stairs LeetCode Solution107
1274Koko Eating Bananas LeetCode Solution107
1275Peeking Iterator LeetCode Solution106
1276Largest Submatrix With Rearrangements LeetCode Solution106
1277Longest Substring Without Repeating Characters Leetcode Solution106
1278Check in binary array the number represented by a subarray is odd or even105
1279Check if X can give change to every person in the Queue105
1280Newman–Shanks–Williams prime105
1281Merge Sorted Array104
1282Queries for Decimal Values of Subarrays of a Binary Array104
1283Range Minimum Query (Square Root Decomposition and Sparse Table)103
1284Array Nesting Leetcode Solution102
1285Encoded String With Shortest Length LeetCode Solution102
1286Arranging Coins Leetcode Solution101
1287Find maximum average subarray of k length101
1288Maximum Sum Increasing Subsequence101
1289Maximum product of an increasing subsequence100
1290Number of indexes with equal elements in given range100
1291Convert a BST to a Binary Tree such that sum of all greater keys is added to every key100
1292Check given array of size n can represent BST of n levels or not100
1293Convert to Base -2 LeetCode Solution99
1294Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1295Continuous Subarray Sum LeetCode Solution98
1296Find the Winner of the Circular Game LeetCode Solution98
1297Random Pick Index LeetCode Solution98
1298Minimum Number of People to Teach LeetCode Solution98
1299Reach a Number LeetCode Solution97
1300Add Two Numbers II Leetcode Solution97
1301Jump Game IV LeetCode Solution97
1302Binary Tree to Binary Search Tree Conversion using STL set97
1303Vertical Order Traversal of Binary Tree LeetCode Solution96
1304Queries on XOR of greatest odd divisor of the range95
1305Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution95
1306Palindrome Number LeetCode Solution95
1307Insert Delete GetRandom O(1) Leetcode Solution94
1308Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1309Design Underground System Leetcode Solution90
1310Print Maximum Length Chain of Pairs89
1311Detect Capital Leetcode Solution88
1312Design A Leaderboard Leetcode Solution87
1313Shifting Letters LeetCode Solution85
1314Substring with Concatenation of All Words Leetcode Solution84
1315Minimum Swaps to Group All 1’s Together Leetcode Solution83
1316Top K Frequent Elements LeetCode Solution83
1317Count Sub Islands LeetCode Solution82
1318Minimum Path Sum Leetcode Solution81
1319Binary Tree Inorder Traversal LeetCode Solution81
1320Longest Common Subsequence LeetCode Solution78
1321Maximum Population Year LeetCode Solution77
1322Find the Town Judge LeetCode Solution77
1323Odd Even Linked List Leetcode Solution77
1324Find the Town Judge LeetCode Solution76
1325Decode String Leetcode Solution76
1326Best Meeting Point LeetCode Solution76
1327Shortest Unsorted Continuous Subarray LeetCode Solution75
1328Sum Root to Leaf Numbers LeetCode Solution74
1329Design Add and Search Words Data Structure LeetCode Solution71
1330Rectangle Overlap LeetCode Solution71
1331Maximum Population Year LeetCode Solution71
1332Flatten Binary Tree to Linked List LeetCode Solution69
1333Score of Parenthesis LeetCode Solution68
1334Stone Game IV LeetCode Solution67
1335Insert into a Sorted Circular Linked List LeetCode Solution67
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution65
1338Valid Triangle Number LeetCode Solution64
1339Is Graph Bipartite? LeetCode Solution63
1340Divide Chocolate LeetCode Solution57
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution52
1342Reverse Integer Leetcode Solution47
1343Range Sum of BST LeetCode Solution46
1344Find K Closest Elements LeetCode Solution43
1345Sort Colors LeetCode Solution43
1346Rotate String LeetCode Solution40
1347Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution40
1348Excel Sheet Column Number LeetCode Solution39
1349H-Index Leetcode Solution20
1350Maximum Size Subarray Sum Equals k Leetcode Solution20
1351High Five LeetCode Solution19
1352Camelcase Matching Leetcode Solution16
1353Monotonic Array Leetcode Solution15
1354Group Shifted Strings Leetcode Solution13
1355Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution12
1356Peak Index in a Mountain Array LeetCode Solution11
1357Unique Binary Search Trees LeetCode Solution11
1358Valid Triangle Number LeetCode Solution10
1359Isomorphic Strings LeetCode Solution9
1360Next Greater Element I Leetcode Solution8
1361Swim in Rising Water LeetCode Solution7
1362Flatten Binary Tree to Linked List LeetCode Solution2
Translate »