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 Uber
Binary Tree Depth First Search Linked-List Stack TreeViews 58

Flatten Binary Tree to Linked List LeetCode Solution says that – 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.

 

Example 1:

Flatten Binary Tree to Linked List LeetCode SolutionPinInput:

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

Output:

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

Example 2:

Input:

 root = []

Output:

 []

Example 3:

Input:

 root = [0]

Output:

 [0]

 

ALGORITHM –

IDEA –

  • In order to flatten a binary tree, we will first find the rightmost element of the left subtree and after we got the rightmost element we will link the right-pointer of that node with a right subtree of a given tree.
  • In step 2 we will link the right pointer of the root node with the left-subtree and set the left-subtree as null.
  • In step 3 now our root node is a right-subtree node same process will happen with this node and the process will still continue until all the left parts become null.

Approach for Flatten Binary Tree to Linked List Leetcode Solution –

– At first, i will run a loop i.e. while(root != null) then will take two variables and store the left-subtree.

– then will check check for the rightmost node of left-subtree by using while(k.left != null) and will link that node with right subtree using (k.right = root.right).

– then link  right pointer of root node with left subtree(root.right = left) and set left pointer of root node as null(root.left=null) and will update by ( root = root.right ) so now root is right subtree node.

– this process will continue until all left-subtree parts become right subtree. Hence, the binary tree will get flattened.

 

Flatten Binary Tree to Linked List LeetCode SolutionPin

Flatten Binary Tree to Linked List LeetCode SolutionPin

Python Solution:

class Solution:
    def flatten(self, root: Optional[TreeNode]) -> None:
        while(root):
            
            if root.left:
                
                k = root.left
                temp = root.left
            
            
                while(k.right):
                    k = k.right
            
                k.right = root.right
            
                root.right = temp
            
                root.left = None
            
            root = root.right

Java Solution:

class Solution {
    public void flatten(TreeNode root) {       
        while (root != null) {
            if (root.left != null) {
                TreeNode k = root.left;
                TreeNode temp = root.left;
                while (k.right != null) k = k.right;
                k.right = root.right;
                root.right = temp;
                root.left = null;
            }
            root = root.right;
        }
    }
}

Time complexity: O(N)

Space Complexity: O(1)

As we have traversed only once, time complexity will be o(n).

and as we haven’t taken any extra space, space complexity will be o(1) constant extra space.

Similar Question – https://www.tutorialcup.com/interview/linked-list/flattening-linked-list.htm

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2813
2Java program to find the number of Nodes in a Binary Tree2497
3Reverse a string without affecting special characters2451
4Delete a node of a linked list at given position1971
5Palindrome using Recursion1772
6Insert nodes in a linked list in a sorted way (Ascending Order)1655
7Find elements pair from array whose sum equal to number1643
8Sort Elements by Frequency of Occurrences1622
9Write a program to print all permutations of a given string1598
10Find Minimum Distance Between Two Numbers in an Array1465
11Create a Doubly Linked List1442
12Quick Sort1414
13Reverse an Array1405
14Smallest window in a string containing all characters of another string1387
15Find a Triplet That Sum to a Given Value1353
16Recursively remove all adjacent duplicates1347
17First Repeating Element1330
18Arrange Even and Odd number such that Odd comes after Even1315
19Sum of numbers in String1308
20Smallest Positive Number Missing in an Unsorted Array1276
21Check if the Elements of an Array are Consecutive1246
22Detect a loop in the Linked List1233
23Largest Sum Contiguous Subarray1223
24Quick Sort on SIngly Linked List1211
25Subarray with Given Sum1205
26Print all Possible Combinations of R Elements in a given Array of size N1196
27Recursive function to do substring search1193
28Find the Maximum Repeating Number in Array1147
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1115
31Check if two linked lists are identical1099
32Maximum Subarray Sum using Divide and Conquer1096
33Remove characters from first string which are in second1063
34Find Leaders in an Array1056
35Swap nodes in the linked list1030
36Find the Number Occurring Odd Number of Times in an Array998
37Arrange given Numbers to Form the Biggest Number II987
38Find the second most frequent character983
39Given a string find its first non-repeating character962
40Find Triplet in Array With a Given Sum955
41Given a sorted array and a number x, find the pair in array whose sum is closest to x949
42Total number of occurrences of a given item in the linked list949
43A Program to check if strings are rotations of each other or not940
44Print all possible words from phone digits927
45Find the Missing Number920
46Rearrange Positive and Negative Numbers Alternatively in Array912
47Longest Palindromic Substring896
48Segregate even and odd nodes in a linked list880
49Print Longest common subsequence876
50Union and Intersection of Two Linked Lists869
51Transform one string to another using minimum number of given operations860
52Rearrange given Array in Maximum Minimum Form840
53Check rearranged string can form a palindrome840
54Count Possible Triangles816
55Iterative Implementation of Quick Sort811
56Multiplication of Two Matrices795
57Check if the linked list is palindrome792
58Rotate a Linked List787
59Count of Triplets With Sum Less than Given Value787
60Stock Buy Sell to Maximize Profit782
61Concatenation of two strings755
62Tug of War754
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string747
65Find Nearest Greater and Smaller Element739
66The Celebrity Problem734
67Find Pythagorean Triplets from Array733
68Reverse String Without Temporary Variable728
69Remove ‘b’ and ‘ac’ from a given string725
70Find all Common Elements in Given Three Sorted Arrays723
71Remove all duplicates in an unsorted linked list705
72Find the Row with Maximum Number of 1’s701
73Find the Peak Element from an Array693
74Find the subarray whose sum is equal to a given number X692
75Insertion Sort684
76Remove Minimum Characters so that Two Strings Become Anagrams683
77A Product Array Puzzle679
78Find Smallest Missing Number in a Sorted Array679
79Addition of Two Matrices677
80Implement Two Stacks in an Array671
81Generate all Binary Strings Without Consecutive 1’s669
82Maximum Sum of Non Consecutive Elements666
83Maximum Product Subarray II657
84Lexicographic rank of string648
85Multiplication of Previous and Next640
86Check if Two given Matrices are Identical640
87Merge K Sorted Arrays and Print Sorted Output630
88Subtraction of Two Matrices630
89Move All the Zeros to the End of the Given Array624
90Divide a string in N equal parts619
91Form Minimum Number from Given Sequence of D’s and I’s617
92Online Algorithm for Checking Palindrome in a Stream617
93Check whether two strings are anagram of each other610
94Remove recurring digits in a given number607
95Sort a linked list that is sorted alternating ascending and descending606
96Maximum Circular Subarray Sum605
97Sort a stack using a temporary stack603
98Move last element of the Linked List at first place600
99Find the Minimum Element in a Sorted and Rotated Array597
100First Circular Tour to Visit all the Petrol Bunks595
101Subarray and Subsequence591
102Largest Subarray with Equal Number of 0’s and 1’s591
103Flattening a linked list589
104Compare two strings(linked lists)588
105Maximum Element in an Array which is Increasing and then Decreasing587
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array576
108Majority Element572
109Run length encoding571
110Minimum insertions to form a shortest palindrome570
111Print all permutations with repetition569
112Palindromes in a given range569
113Pangram Checking564
114Rearrange a given linked list in-place561
115Remove all duplicates in a sorted linked list560
116Merge a linked list into another at alternate positions560
117Minimum Characters to be Added at Front to Make String Palindrome558
118Minimum number of Merge Operations to make an Array Palindrome556
119Rotate string to get lexicographically minimum string555
120Repeated Subsequence of Length Two or More553
121Most repeating character in a string550
122Print all anagrams together in a sequence of words548
123Reorder an Array According to the Given Indexes546
124Pancake Sorting Problem539
125Clone a Linked List with next and random pointer535
126Merge Overlapping Intervals II533
127Two Sum Leetcode Solution526
128Size of The Subarray With Maximum Sum524
129Transpose of a Matrix521
130Removing Spaces from a String using stringstream517
131Remove Extra Spaces from a String517
132Check if a given string is a rotation of a palindrome514
133Partition Problem513
134Smallest Palindrome after Replacement512
135Remove duplicates from a string512
136Longest Palindrome can be Formed by Removing or Rearranging Characters510
137Maximum Sum Increasing Subsequence509
138Generate all Binary Strings from Given Pattern498
139Check whether Strings are K Distance Apart or Not497
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized495
141Insert Node in the Sorted Linked List495
142Delete Last Occurrence494
143Length of Longest valid Substring493
1443Sum Leetcode Solution490
145Check if Two given Strings are Isomorphic to each other489
146Maximum difference between two elements such as larger element comes after smaller484
147Program to Toggle all Characters in a String480
148Given string is interleaving of two other strings or not478
149Count Minimum Steps to Get the given Array477
150Merge sort better than quick sort for linked lists473
151Number of Smaller Elements on Right Side470
152Find Pair with Given Difference468
153Check length of a String is Equal to the Number Appended at its Last467
154Check if all Rows of a Matrix are Circular Rotations of Each Other467
155Longest Common Prefix using Divide and Conquer466
156Find nth node of the Linked list from the end465
157Sort 0s 1s and 2s in an Array456
158Find a Fixed Point in a Given Array455
159Print all interleavings of given two strings454
160Merge two sorted linked lists such that merged list is in reverse order452
161Find the Subarray of given length with Least Average451
162Compare Two Version Numbers450
163Reorder Array Using Given Indexes449
164Split linked list using alternate nodes448
165Reverse words in a given string448
166Print Reverse of a string (Recursion)444
167Median of Two Sorted Arrays LeetCode Solution443
168Print string of odd length in ‘X’ format433
169Swap Kth Node from beginning with Kth Node from End430
170Find Element Using Binary Search in Sorted Array429
171Find K Length Subarray of Maximum Average429
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way420
174print all palindromic partitions418
175Flatten a multilevel linked list414
176Shortest Superstring Problem413
177Maximum Length of Chain Pairs409
178Sorting a K Sorted Array407
179Check if String Follows Order of Characters by a Pattern or not407
180Sort a String According to Another String400
181Longest Span with same Sum in two Binary Arrays II396
182Reverse a Linked List in groups394
183Find a Sorted Subsequence of size 3390
184Program to add two binary digits386
185Recursively print all the sentences that can be formed from list of word lists385
186Find the two Numbers with Odd Occurrences in an Unsorted Array385
187Longest Common Prefix Using Binary Search II382
188Reverse a Singly Linked List (Iterative/Non-Recursive)379
189Rearrange a linked list in Zig-Zag376
190Kth Non-repeating Character375
191Caesar Cipher374
192Check if String can Become Empty by Recursively Deleting given Substring373
193Pancake Sorting371
194Rotate Image by 90 degrees369
195Longest Common Prefix Word by Word Matching367
196Perfect Reversible String363
197Permutations of a Given String Using STL362
198Merging Two Sorted Arrays360
199Increasing Subsequence of Length three with Maximum Product360
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes357
201Find the point where a monotonically increasing function becomes positive first time357
202Sort a linked list with 0s, 1s and 2s356
2031`s and 2`s complement of binary number354
204Find First non-repeating character in a string354
205Four Elements that Sum to Given351
206List items containing all characters of a given word350
207Delete N nodes after M350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array343
210Split a string338
211Palindrome string (number)337
212Minimum Characters to be Removed to Make a Binary String Alternate336
213Check if a Linked list of Strings form a Palindrome331
214Print All Distinct Elements of the Array328
215Sorting the array of strings328
216Recursive Implementation of atoi()328
217Convert a String that is Repetition of a Substring of Length K326
218Find the first Repeating Number in a Given Array323
219Even Substring Count323
220Reverse a singly linked list recursively321
221Binary Tree to Doubly linked list320
222Print Shortest Path to Print a String on Screen319
223Can we reverse a linked list in less than O(n) time ?318
224Maximum occurring character in a string318
225Valid Parentheses LeetCode Solution316
226Nth Character in Concatenated Decimal String315
227Sort Elements by Frequency II315
228Convert string1 to string2 in one edit315
229wildcard character matching313
230Reverse a String using Stack312
231Lower Case To Upper Case311
232Merge Two Sorted Arrays309
233Maximum Subarray Leetcode Solution308
234Find the Lost Element From a Duplicated Array308
235Count the number of words308
236Split Four Distinct Strings306
237Find middle of the Linked List303
238Longest Common Subsequence with Permutations298
239Count the Pairs at Same Distance as in English Alphabets297
240Next Greater Element in an Array293
241Matrix Chain Multiplication using Dynamic Programming291
242Palindrome Permutation286
243Find Nth Node282
244Find All Pairs With a Given Difference281
245Searching a node in a Binary Search Tree281
246Triplet from three linked lists with given sum278
247Roman to Integer Leetcode Solution278
248Delete a Tree278
249String(represents an integer) to value275
250Print all Possible Ways to Break a String in Bracket Form274
251Reverse a String274
252Binary Tree271
253Change Gender of a given String270
254Delete a node under given conditions270
255Reverse Bits269
256Sort an array of strings268
257Word Search Leetcode Solution266
258Number of sub-strings which recursively add up to 9265
259How to Efficiently Implement k Stacks in a Single Array?264
260Remove middle points in a linked list of line segments264
261Longest Common Extension263
262Toeplitz Matrix261
263Remove spaces from a string259
264First non Repeating Element259
265Count Pairs With Given Sum258
266Meeting Rooms II LeetCode Solution257
267Repeated Substring Pattern257
268Shuffle a given Array257
269Longest Palindromic Substring LeetCode Solution255
270Move all negative elements to one side of array254
271N queen problem252
272Min Stack251
273Find, second, frequent, character249
274Dijkstra Algorithm247
275Number of Islands LeetCode Solution245
276Cuckoo sequence program245
277Clone a linked list with next and random pointer (Hashing)244
278Most Frequent Element in an Array244
279Max stack243
280Minimize the maximum difference between the heights242
281Sort linked which is sorted on absolute values242
282House Robber Leetcode Solution241
283Fibonacci numbers238
284Expression Evaluation237
285Search Insert Position Leetcode Solution237
286How to Delete a Linked List237
287Valid Palindrome Leetcode Solution235
288Sudoku Solver234
289KMP Algorithm234
290Word Search234
291Min Stack Leetcode Solution233
292Plus One Leetcode Solution233
293Evaluation of Postfix Expression233
294Number Of 1 bits231
295Subset Leetcode231
296Reverse words in a string231
297Combination Sum Leetcode Solution230
298Backspace String Compare225
299Merge Sorted Arrays Leetcode Solution224
300Rabin Karp Algorithm223
301Pair of Positive Negative Values in an Array222
302Set Matrix Zeroes222
303Reversing a Queue222
304Tower Of Hanoi221
305Sqrt(x) Leetcode Solution221
306Subarray with 0 sum220
307Combination Sum219
308Contains Duplicate II Leetcode Solution219
309Common elements in all rows of a given matrix218
310Product of array except self217
311Integer to Roman Leetcode Solution216
312Intersection of Two Arrays II Leetcode Solution216
313Reverse individual words214
314Pascal Triangle Leetcode214
315Delete middle element of a stack213
316String Compression213
317Minimum swaps required to bring all elements less than or equal to k together212
318Construct Binary Tree from Given Inorder and Preorder Traversals212
319Count subarrays with equal number of 1’s and 0’s211
320Find Top K (or Most Frequent) Numbers in a Stream211
321Sliding Window Technique211
322Bellman Ford Algorithm210
323Add Binary Leetcode Solution210
324Page Replacement Algorithms in Operating Systems209
325Arithmetic Expression Evaluation209
326Pow(x, n) Leetcode Solution208
327Count of index pairs with equal elements in an array208
328Segregate even and odd numbers208
329Single Number Leetcode Solution208
330Palindrome Linked List Leetcode Solution207
331Second Most Repeated Word in a Sequence207
332Kruskal Algorithm207
333Contains Duplicate206
334Design a stack that supports getMin() in O(1) time and O(1) extra space206
335Implementation of Deque using Doubly Linked List206
336Minimum Value to Get Positive Step by Step Sum Leetcode Solution206
337Find sum of non-repeating elements (distinct) elements in an array206
338Next Permutation206
339Postfix to Infix Conversion206
340Sort elements by frequency205
341Count Odd Numbers in an Interval Range Leetcode Solution205
342Maximum Number of Balloons Leetcode Solution205
343Maximum Subarray203
344Third Maximum Number Leetcode Solution203
345Group Words With Same Set of Characters203
346Longest Common Prefix Leetcode Solution202
347K-th Smallest Element in a Sorted Matrix202
348Longest Substring Without Repeating Characters LeetCode Solution201
349Find Lucky Integer in an Array Leetcode Solution201
350Find Numbers with Even Number of Digits Leetcode Solution201
351Permutations Leetcode Solution201
352Convex Hull Algorithm201
353Sorting array using Stacks201
354Top K Frequent Words200
355Sum of minimum and maximum elements of all subarrays of size k200
356Minimum operation to make all elements equal in array199
357Smallest Subarray with k Distinct Numbers199
358Scramble String199
359Count subarrays having total distinct elements same as original array199
360Find the Town Judge Leetcode Solution199
361Evaluate Division198
362Swap Nodes in Pairs Leetcode Solutions198
363Majority Element Leetcode Solution197
364Spiral Matrix LeetCode Solution197
365Special Number197
366Merge Two Sorted Lists Leetcode Solutions196
367First element occurring k times in an array196
368Given two unsorted arrays find all pairs whose sum is x195
369Check if two arrays are equal or not195
370Minimum Path Sum194
371Count Primes Leetcode Solutions194
372Group Anagrams194
373Prefix to Infix Conversion194
374Reverse a Number Using Stack193
375Search in Rotated Sorted Array Leetcode Solution193
376Huffman Coding193
377Reversing the First K elements of a Queue193
378Best Time to Buy and Sell Stock  II Leetcode Solution192
379Find duplicates in a given array when elements are not limited to a range192
380Power of Two Leetcode Solution192
381Number of Good Pairs Leetcode Solution192
382Minimum Steps to reach target by a Knight192
383Missing Number Leetcode Solution192
384Minimum Absolute Difference Leetcode Solution192
385Maximum Distance Between two Occurrences of Same Element in Array191
386House Robber II Leetcode Solution191
387Sort Array by Increasing Frequency Leetcode Solution191
388Pascal’s Triangle II Leetcode Solution191
389Single Number191
390Maximal Square191
391Fizz Buzz Leetcode190
392Range Sum Query 2D – Immutable Leetcode Solution190
393Sorting using trivial hash function189
394Top K Frequent Elements189
395Unique Paths Leetcode Solution189
396Running Sum of 1d Array Leetcode Solution188
397Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution188
398Matrix Diagonal Sum Leetcode Solution188
399Find All Numbers Disappeared in an Array Leetcode Solution188
400Fibonacci Number LeetCode Solution187
401Leetcode Permutations187
402Unique Paths187
403Expression Contains Redundant Bracket or Not187
404How to Implement Stack Using Priority Queue or Heap?187
405Zigzag Conversion187
406Happy Number Leetcode Solution187
407Coin Change 2 Leetcode Solution187
408Maximum possible difference of two subsets of an array187
409Check if Array Contains Contiguous Integers With Duplicates Allowed187
410Find The Duplicate Number186
411Subset sum problem186
412Find Winner on a Tic Tac Toe Game Leetcode Solution186
413Subarray Sum Equals K LeetCode Solution186
414Palindrome Substring Queries186
415Decode String185
416Cumulative Frequency of Count of Each Element in an Unsorted Array185
417Convert String To Int185
418How Many Numbers Are Smaller Than the Current Number Leetcode Solution185
419Difference between highest and least frequencies in an array185
420Find the Closest Palindrome number185
421Letter Case Permutation185
422Smallest Element Repeated Exactly K Times185
423Nth Catalan Number185
424Reverse Integer184
425Max Consecutive Ones Leetcode Solution184
426Sort a stack using recursion184
427Subarray Sum Equals k184
428Sort Integers by The Number of 1 Bit Leetcode Solution184
429Remove Duplicates from Sorted Array Leetcode Solution184
430Find Number of Employees Under every Employee184
431Reverse Vowels of a String Leetcode Solution184
432Bipartite Graph183
433Subtract the Product and Sum of Digits of an Integer Leetcode Solution183
434Find top three repeated in array183
435Monotonic Array LeetCode Solution183
436Print All Distinct Elements of a Given Integer Array183
437Find Median from data Stream183
438Best Time to Buy and Sell Stock III Leetcode Solution183
439Check If N and Its Double Exist Leetcode Solution183
440Shuffle the Array Leetcode Solution183
441Trapping Rain Water Leetcode Solution183
442Length of the largest subarray with contiguous elements183
443Implement Stack and Queue using Deque182
444Find the first repeating element in an array of integers182
445LRU Cache Implementation182
446Generate a String With Characters That Have Odd Counts Leetcode Solution181
447Maximum Depth of Binary Tree Leetcode Solution181
448Find the Duplicate Element181
449Prim’s Algorithm181
450Sum of Subarray Ranges Leetcode Solution181
451Capacity To Ship Packages Within D Days Leetcode Solution181
452Find Minimum In Rotated Sorted Array181
453Reverse a Stack Using Recursion181
454Subarrays with distinct elements181
455Count Substrings with equal number of 0s, 1s and 2s180
456Merge Two Sorted Linked Lists180
457Kth largest element in an Array Leetcode Solutions180
458Integer to English words180
459Find all pairs (a, b) in an array such that a % b = k180
460Reverse Words in a String III LeetCode Solution180
461Priority Queue Using Singly Linked List180
462Find Common Characters Leetcode Solution179
463Delete a Node from linked list without head pointer179
464Count pairs from two linked lists whose sum is equal to a given value179
465Longest Common Subsequence179
466The K Weakest Rows in a Matrix Leetcode Solution179
467Sorting a Queue without Extra Space179
468Fizz Buzz178
469Edit Distance178
470Count and Say178
471Reverse a linked list178
472Find the Difference Leetcode Solution178
473MiniMax Algorithm178
474Reverse a String178
475Remove Minimum Number of Elements Such That no Common Element Exist in both Array178
476Find elements which are present in first array and not in second178
477Floyd Warshall Algorithm177
478Print all subarrays with 0 sum177
479Target Sum177
480Text Justification LeetCode Solution177
481Excel Sheet Column Number Leetcode Solution177
482Concatenation of Array LeetCode Solution176
483Find First and Last Position of Element in Sorted Array Leetcode Solution176
484Kth Largest Element in a Stream Leetcode Solution176
485Degree of an array176
486Balanced Binary Tree Leetcode Solution176
487Longest Common Prefix using Trie176
488Next Greater Element I Leetcode Solution176
489Flood Fill LeetCode175
490Design Parking System Leetcode Solution175
491Number of Steps to Reduce a Number to Zero Leetcode Solution175
492Merge Overlapping Intervals175
493Kids With the Greatest Number of Candies Leetcode Solution175
494Iterative Tower of Hanoi175
495Pair with given product174
496Priority Queue in C++174
497Top View of Binary Tree174
498Word Ladder LeetCode Solution174
499Multiply Strings Leetcode Solution174
500Longest subarray not having more than K distinct elements174
501Shortest Palindrome174
502Postfix to Prefix Conversion173
503Valid Parenthesis String173
504Minimum Moves to Equal Array Elements Leetcode Solution173
505Count and Say Leetcode Solution173
506Find subarray with given sum (Handles Negative Numbers)173
507Prefix to Postfix Conversion173
508Find N Unique Integers Sum up to Zero Leetcode Solution173
509Find four elements that sum to a given value (Hashmap)173
510Recursion172
511Contiguous Array Leetcode172
512Peak Index in a Mountain Array172
513Max Area of Island172
514Intersection of Two Arrays172
515Implement Stack using Queues172
516Find missing elements of a range172
517Slowest Key Leetcode Solution172
518Koko Eating Bananas Leetcode Solution172
519Length of Last Word Leetcode Solution172
520The Stock Span Problem172
521Move Zeroes LeetCode Solution172
522Implement a stack using single queue171
523Check if a given array contains duplicate elements within k distance from each other171
524Zigzag Conversion LeetCode Solution171
525Iterative Inorder Traversal of a Binary Tree171
526Convert array into Zig-Zag fashion171
527Substring With Concatenation Of All Words171
528Count number of triplets with product equal to given number171
529Find distinct elements common to all rows of a matrix171
530Mobile Numeric Keypad Problem170
531Find any one of the multiple repeating elements in read only array170
532Longest Common Prefix using Sorting170
533Smallest Subarray With all Occurrences of a Most Frequent Element170
534K-th Distinct Element in an Array170
535Jump Game Leetcode Solution170
536Find Index of Closing Bracket for a Given Opening Bracket in an Expression170
537Last Stone Weight170
538Container with Most Water170
539Valid Sudoku169
540Convert a normal BST to Balanced BST169
541Minimum Bracket Reversals169
542Delete Node in a Linked List Leetcode Solution169
543Shuffle String Leetcode Solution169
544Best Time to Buy and Sell Stock169
545Relative Sort Array Leetcode Solution169
546Next Greater Frequency Element169
547Build Array From Permutation Leetcode Solution168
548Largest Perimeter Triangle Leetcode Solution168
549Excel Sheet Column Title Leetcode Solution168
550Shuffle an Array167
551Minimum Operations to convert X to Y167
552Arrange given numbers to form the biggest number167
553First negative integer in every window of size k167
554Rearrange a binary string as alternate x and y occurrences167
555Isomorphic Strings Leetcode Solution167
556Sum of Left Leaves Leetcode Solutions167
557Distribute Candies to People Leetcode Solution167
558Find Words That Can Be Formed by Characters Leetcode Solution167
559Assign Cookies Leetcode Solution167
560Is Subsequence Leetcode Solution167
561Check for Balanced Parentheses in an Expression167
562Change the Array into Permutation of Numbers From 1 to N166
56301 Matrix LeetCode Solution166
564N-th Tribonacci Number Leetcode Solution166
565The Knapsack Problem166
566Integer to Roman166
567Maximum sum rectangle in a 2D matrix166
568Implementation of Deque using circular array166
569Group Multiple Occurrence of Array Elements Ordered by first Occurrence166
570Valid Anagrams166
571Jewels and Stones Leetcode Solution166
572Convert Sorted Array to Binary Search Tree Leetcode Solution165
573Linked List Cycle II LeetCode Solution165
574Minimum Delete Operations to make all Elements of Array Same165
575Hamming Distance165
576Unique Binary Search Trees165
577Shortest Path in a Grid with Obstacles Elimination LeetCode Solution165
578Island Perimeter Leetcode Solution165
579How to check if two given sets are disjoint?164
580Rotate List Leetcode Solution164
581Decode Ways164
582Remove Linked List Elements Leetcode Solution164
583Count the number of nodes at given level in a tree using BFS164
584Gold Mine Problem164
585Trapping Rain Water LeetCode Solution164
586Maximum path sum in a triangle164
587Find the smallest positive integer value that cannot be represented as sum of any subset of a given array164
588Combinations Leetcode Solution163
589LRU Cache LeetCode Solution163
590Same Tree LeetCode Solution163
591Sieve of Eratosthenes163
592Maximum Distance in Array163
593Summary Ranges Leetcode Solution163
594Minimum number of subsets with distinct elements162
595Find minimum difference between any two elements162
596Distance Between Bus Stops Leetcode Solution162
597Find Sum of all unique sub-array sum for a given array162
598Applications of Breadth First Search and Depth First Search162
599Insert Interval Leetcode Solution162
600Maximum difference between first and last indexes of an element in array162
601Count all subsequences having product less than K162
6023Sum Closest LeetCode Solution162
603Minimum Knight Moves LeetCode Solution162
604Word Pattern161
605Minimum insertions to form a palindrome with permutations allowed161
606Maximum Number of Chocolates to be Distributed Equally Among k Students161
607Minimum number of distinct elements after removing m items161
608Rotate Image LeetCode Solution161
609Frog Jump Leetcode Solution161
610Find if an Expression has Duplicate Parenthesis or Not161
611Stone Game LeetCode160
612Best Time to Buy and Sell Stock LeetCode Solution160
613Distance of nearest cell having 1 in a binary matrix160
614License Key Formatting Leetcode Solution160
615Printing brackets in Matrix Chain Multiplication Problem160
616Word Wrap Problem159
617Permutation in String Leetcode Solution159
618K Empty Slots LeetCode159
619Longest Increasing Subsequence159
620Defanging an IP Address Leetcode Solution159
621Minimum Cost to Hire K Workers159
622Sort Characters By Frequency LeetCode Solution159
623Sort Array By Parity LeetCode Solution159
624Replace Elements with Greatest Element on Right Side Leetcode Solution159
625House Robber159
626Minimum Depth of Binary Tree Leetcode Solution159
627XOR Operation in an Array Leetcode Solution159
628Coin Change Problem158
629Reverse a stack without using extra space in O(n)158
630Check If It Is a Straight Line Leetcode Solution158
631Find the Duplicate Number LeetCode Solution158
632Painting Fence Algorithm158
633Maximum Consecutive Numbers Present in an Array158
634Smallest Good Base158
635Remove All Occurrences of a Substring LeetCode Solution158
636Kth Missing Positive Number Leetcode Solution157
637Non-overlapping sum of two sets157
638Segregate 0s and 1s in an Array157
639Find Maximum Level sum in Binary Tree157
640Queries for counts of array elements with values in given range156
641Longest Substring with At Most K Distinct Characters LeetCode Solution156
642Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest156
643Tracking current Maximum Element in a Stack156
644Strobogrammatic Number LeetCode Solution156
645Isomorphic Strings156
646GCD Of Two Numbers156
647Iterative Method to find Height of Binary Tree156
648Optimal Account Balancing LeetCode Solution156
649Merge Two Balanced Binary Search Trees156
650Best Time to Buy and Sell Stock with Cooldown Leetcode Solution156
651Valid Palindrome II Leetcode Solution156
652Find Largest d in Array such that a + b + c = d155
653Moving Average from Data Stream Leetcode Solution155
654Partition Labels LeetCode Solution155
655Flipping an Image LeetCode Solution155
656Reorganize String155
657Employee Free Time LeetCode Solution155
658Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
659How to Create Mergable Stack?155
660Binary Tree Zigzag Level Order Traversal LeetCode Solution155
661Wiggle Sort155
662Convert an array to reduced form155
663Inorder Successor of a node in Binary Tree154
664Check if a queue can be sorted into another queue using a stack154
665Maximum Number of Occurrences of a Substring Leetcode Solution154
666Count Good Nodes in Binary Tree Leetcode Solution154
667Path With Maximum Minimum Value LeetCode Solution154
668Letter Combinations of a Phone Number154
669Largest Sum Contiguous Subarray154
670Form minimum number from given sequence154
671Find the Distance Value Between Two Arrays Leetcode Solution154
672Number of Provinces Leetcode Solution154
673K Empty Slots154
674Check If Two String Arrays are Equivalent Leetcode Solution154
675BFS vs DFS for Binary Tree154
676Longest Substring with At Least K Repeating Characters LeetCode Solution154
677Reservoir Sampling153
678Sum of All Odd Length Subarrays Leetcode Solution153
679Sort Array by Increasing Frequency Leetcode Solution153
680Power of Four Leetcode Solution153
681Lucky Numbers in a Matrix Leetcode Solution153
682Populating Next Right Pointers in Each Node153
683Valid Palindrome153
684Sum of f(a[i], a[j]) over all pairs in an array of n integers153
685Find the Smallest Divisor given a Threshold Leetcode Solution153
686Find pairs with given sum such that elements of pair are in different rows152
687Reversing a Queue using Recursion152
688Construct BST from given Preorder Traversal152
689Find the node with minimum value in a Binary Search Tree152
690Delete consecutive same words in a sequence152
691Subset Sum Leetcode152
692Remove Invalid Parentheses Leetcode Solution152
693To Lower Case Leetcode Solution152
694Maximum Number of Coins You Can Get Leetcode Solution152
695Reducing Dishes LeetCode Solution152
696Print the Fibonacci numbers in reverse order152
697Majority Element II Leetcode Solution152
698Unique Paths II Leetcode Solution152
699Delete Nth node from the end of the given linked list152
700Partition Array Into Three Parts With Equal Sum Leetcode Solution152
701Number of Dice Rolls With Target Sum LeetCode Solution151
702Convert a Number to Hexadecimal Leetcode Solution151
703Longest Increasing Path in a Matrix LeetCode Solution151
704Add and Search Word – Data structure design LeetCode151
705Increasing Decreasing String Leetcode Solution151
706Find Leaves of Binary Tree LeetCode Solution151
707Permutation Sequence LeetCode Solution151
708Ugly Number Leetcode Solution151
709Factorial Trailing Zeroes Leetcode Solution151
710String to Integer (atoi) LeetCode Solution151
711Valid Perfect Square Leetcode Solution151
712Recover Binary Search Tree151
713Binary Tree zigzag level order Traversal150
714Edit Distance LeetCode Solution150
715Reverse Only Letters LeetCode Solution150
716Find whether an array is subset of another array150
717Dynamic Programming Basics150
718Restore IP Addresses Leetcode Solution150
719Maximum Product of Two Elements in an Array Leetcode Solution150
720Longest Span with same Sum in two Binary arrays149
721Hamming Distance Leetcode Solution149
722Keyboard Row Leetcode Solution149
723Largest subarray with equal number of 0s and 1s149
724Rank Transform of an Array Leetcode Solution149
725Minimum Distance Between BST Nodes Leetcode Solution149
726Merge Two Binary Trees LeetCode Solution149
727Binomial Coefficient149
728Numbers with prime frequencies greater than or equal to k149
729Bubble sort using two Stacks149
730Find Maximum Depth of Nested Parenthesis in a String149
731Merge K Sorted Linked Lists148
732Decompress Run-Length Encoded List Leetcode Solution148
733Find unique character in a string148
734Find Pair with Greatest Product in Array148
735Perform String Shifts Leetcode148
736Bulb Switcher LeetCode Solution148
737Minimum Cost For Tickets Leetcode Solution148
738Finding K closest element148
739Deletion in a Binary Tree148
740Stack Permutations (Check if an array is stack permutation of other)148
741Maximum 69 Number Leetcode Solution148
742Minimum Height Trees148
743Find the largest multiple of 3148
744Morris Traversal147
745Find All Duplicates in an Array LeetCode Solution147
746Count quadruples from four sorted arrays whose sum is equal to a given value x147
747Race Car LeetCode Solution147
748Growable array based stack147
749Symmetric Tree Leetcode Solution147
750Binary Tree Maximum Path Sum LeetCode Solution147
751Kth ancestor of a node in binary tree147
752Sorted Linked List to Balanced BST147
753Robot Room Cleaner Leetcode Solution147
754Best Meeting Point LeetCode Solution147
755Non-decreasing Array LeetCode Solution147
756Maximum Product of Three Numbers LeetCode Solution147
757Student Attendance Record I Leetcode Solution147
758Elements to be added so that all elements of a range are present in array147
759Jump Game147
760Word Pattern LeetCode Solution146
761Maximum Depth of N-ary Tree Leetcode Solution146
762Evaluate Reverse Polish Notation LeetCode Solution146
763Remove brackets from an algebraic string containing + and – operators146
764Diagonal Traversal of Binary Tree146
765Valid Number146
766Snakes and Ladders LeetCode Solution146
767Largest rectangular sub-matrix whose sum is 0146
768Generate all possible sorted arrays from alternate elements of two given sorted arrays146
769Minimum time required to rot all oranges146
770k-th missing element in increasing sequence which is not present in a given sequence146
771Special Array With X Elements Greater Than or Equal X Leetcode Solution145
772Largest Rectangle in Histogram LeetCode Solution145
773String Compression LeetCode Solution145
774Minimize Maximum Pair Sum in Array LeetCode Solution145
775Queue based approach for first non-repeating character in a stream145
776Find Median from Data Stream LeetCode Solution145
777First Unique Character in a String LeetCode Solution145
778Number of Islands II LeetCode Solution145
779Tiling Problem145
780N-Queens LeetCode Solution145
781Linked List Cycle145
782Program for Bridge and Torch problem145
783Search in a Binary Search Tree Leetcode Solution145
784Interval Tree144
785Circular Queue144
786Final Prices With a Special Discount in a Shop Leetcode Solution144
787Maximum Difference Between Increasing Elements LeetCode Solution144
788Partition to K Equal Sum Subsets Leetcode Solution144
789Count items common to both the lists but with different prices144
790Check if Two Expressions With Brackets are Same144
791Sort an array according to the order defined by another array144
792Maximum Length of a Concatenated String with Unique Characters Leetcode Solution144
793Number of NGEs to the Right144
794Transpose Graph144
795Find if Path Exists in Graph Leetcode Solution144
796Nested List Weight Sum II LeetCode Solution144
797Check If Array Pairs Are Divisible by k LeetCode Solution144
798Split a String in Balanced Strings Leetcode Solution144
799Check for Palindrome after every character replacement Query144
800Search a 2D Matrix II Leetcode Solution144
801Base 7 Leetcode Solution144
802Iterative Preorder Traversal143
803Crawler Log Folder Leetcode Solution143
804A Space Optimized DP solution for 0-1 Knapsack Problem143
805Permutation Coefficient143
806Print a Binary Tree in Vertical Order143
807Remove Duplicates from Sorted List II143
808Remove Duplicates from Sorted List LeetCode Solution143
809String comparison containing wildcards143
810Relative Ranks Leetcode Solution143
811Minimum swaps to make sequences increasing143
812Remove Nth Node From End of List Leetcode Solution143
813Get Maximum in Generated Array Leetcode Solution143
814Number Complement Leetcode Solution143
815Total Numbers With no Repeated Digits in a Range143
816Course Schedule II – LeetCode142
817Longest Subarray Having Count of 1s One More than Count of 0s142
818Reorder Data in Log Files LeetCode Solution142
819Nearest Exit from Entrance in Maze LeetCode Solution142
820Convert BST to Min Heap142
821Merge Sorted Array LeetCode Solution142
822Priority Queue using doubly linked list142
823Last Stone Weight II LeetCode Solution142
824Invert Binary Tree LeetCode Solution142
825Minimum Jumps to Reach Home LeetCode Solution141
826Maximum Nesting Depth of the Parentheses Leetcode Solution141
827Regular Expression Matching141
828Path with maximum average value141
829Maximum size subarray sum equals k141
830Minimum number of jumps to reach end141
831Minimum Time Visiting All Points Leetcode Solution141
832Design a Stack With Increment Operation Leetcode Solution141
833One Edit Distance LeetCode Solution141
834Clone Graph LeetCode Solution141
835Sort Colors141
836Alien Dictionary LeetCode Solution141
837Partition List Leetcode Solution141
838Sort Array By Parity II Leetcode Solution141
839Check if a given array can represent Preorder Traversal of Binary Search Tree140
840Count ways to reach the nth stair using step 1, 2 or 3140
841Sum of nearest smaller and greater number140
842Find the Only Repetitive Element Between 1 to N-1140
843Minimum Swaps to Make Strings Equal Leetcode Solution140
844Check if an Array is Stack Sortable140
845Find All Possible Recipes from Given Supplies LeetCode Solution140
846Find all triplets with zero sum140
847Subset with sum divisible by m140
848Valid Parentheses Leetcode Solution140
849Matrix Chain Multiplication140
850Sorted Array to Balanced BST140
851Form Minimum Number From Given Sequence140
852Brightest Position on Street LeetCode Solution140
853Spiral Matrix II Leetcode Solution140
854Friends Pairing Problem140
855Minimum Number of Taps to Open to Water a Garden LeetCode Solution140
856Find the subarray with least average140
857Check whether a given Binary Tree is Complete or not140
858Top K Frequent Words LeetCode Solution140
859Binary Search Tree Search and Insertion140
860Can Place Flowers LeetCode Solution140
861Brick Wall LeetCode Solution140
862Insert into a Binary Search Tree Leetcode Solution139
863Level order Traversal in Spiral Form139
864Subsequence of Size K With the Largest Even Sum LeetCode Solution139
865LCS (Longest Common Subsequence) of three strings139
866Given an Array of Pairs Find all Symmetric Pairs in it139
867Tree Traversal (Preorder, Inorder & Postorder)139
868Maximum Profit in Job Scheduling Leetcode Solution139
869Range sum queries without updates139
870Count Distinct Elements in Every Window of Size K139
871Subarray Product Less Than K LeetCode Solution139
872Sequences of given length where every element is more than or equal to twice of previous138
873Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
874Maximum Score After Splitting a String Leetcode Solution138
875Identify and Mark Unmatched Parenthesis in an Expression138
876Find Maximum Sum Possible Equal Sum of Three Stacks138
877Minimum Sum Path in a Triangle138
878Union and Intersection of two Linked Lists138
879Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution138
880Guess Number Higher or Lower LeetCode Solution138
881Count Negative Numbers in a Sorted Matrix LeetCode Solution138
882Insert Delete GetRandom138
883Check if stack elements are pairwise consecutive137
884A program to check if a binary tree is BST or not137
885Destination City Leetcode Solution137
886Lemonade Change Leetcode Solution137
887Missing Element in Sorted Array LeetCode Solution137
888Guess Number Higher or Lower II137
889GCDs of given index ranges in an array137
890Water Bottles Leetcode Solution137
891BFS for Disconnected Graph137
892Distinct adjacent elements in an array137
893Delete And Earn137
894Find distance between two nodes of a Binary Tree137
895Repeated Substring Pattern LeetCode Solution137
896Balanced Expression with Replacement137
897An Interesting Method to generate Binary Numbers from 1 to n137
898Minimum sum of multiplications of n numbers137
899Alien Dictionary137
900Rearrange an Array Such that arr[i] is equal to i137
901Check if the given array can represent Level Order Traversal of Binary Search Tree136
902Design Browser History LeetCode Solution136
903Convert Sorted List to Binary Search Tree136
904Diagonal Traversal LeetCode Solution136
905Find Common Characters Leetcode Solution136
906Three way partitioning of an array around a given range136
907Set Matrix Zeroes Leetcode Solution136
908Merge Two Sorted Lists Leetcode136
909Rearrange Spaces Between Words Leetcode Solution136
910Diagonal Traverse LeetCode Solution136
911Least Number of Unique Integers after K Removals Leetcode Solution136
912Find all permuted rows of a given row in a matrix136
913Number of Days Between Two Dates LeetCode Solution136
914Spiral Matrix III LeetCode Solution136
915Shortest Word Distance Leetcode Solution136
916Range LCM Queries136
917Maximum Subarray Sum Excluding Certain Elements135
918Construct Complete Binary Tree from its Linked List Representation135
919Robot Bounded In Circle LeetCode Solution135
920Number of Equivalent Domino Pairs Leetcode Solution135
921Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i135
922Vertical sum in a given binary tree135
923Queue using Stacks135
924Count Subarrays with Same Even and Odd Elements135
925Construct the Rectangle Leetcode Solution135
926Averages of Levels in Binary Tree135
9274Sum135
928K’th Largest Element in BST when modification to BST is not allowed135
929Special Positions in a Binary Matrix Leetcode Solution135
930Dividing Array into Pairs With Sum Divisible by K134
931Trim a Binary Search Tree134
932Queries for GCD of all numbers of an array except elements in a given range134
933Infix to Postfix134
934Lexicographical Numbers Leetcode Solution134
935Print Fibonacci sequence using 2 variables134
936Daily Temperatures Leetcode Solution134
937Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
938Palindrome Partitioning Leetcode Solution134
939Can Make Arithmetic Progression From Sequence Leetcode Solution133
940Longest Palindromic Subsequence133
941Time Based Key-Value Store LeetCode Solution133
942Analyze User Website Visit Pattern LeetCode Solution133
943Pattern Occurrences using Stack133
944Remove Duplicates from Sorted List II LeetCode Solution133
945Median of Two Sorted Arrays133
946Binary array after M range toggle operations133
947Construct BST from its given Level Order Traversal133
948Maximum Frequency Stack Leetcode Solution133
949Merging Intervals133
950Check if any two intervals overlap among a given set of intervals133
951Stone Game II Leetcode133
952Maximize Sum of Array after K Negations Leetcode Solution133
953Three Consecutive Odds Leetcode Solution133
954Strongly Connected Component133
955Number of Distinct Islands Leetcode Solution133
956Largest Substring Between Two Equal Characters Leetcode Solution133
957Iterative Postorder Traversal Using Two Stacks132
958Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space132
959Binary Tree Longest Consecutive Sequence LeetCode Solution132
960Split Array Into Consecutive Subsequences132
9613 Sum132
962Create Maximum Number132
963Newman-Conway Sequence132
964All Unique Triplets that Sum up to a Given Value132
965Palindrome Partitioning132
966Symmetric Tree132
967Depth First Search (DFS) for a Graph132
968Climbing stairs131
969Segment Tree131
970Word Break131
971Intersection of Two Linked Lists LeetCode Solution131
972Length of Longest Fibonacci Subsequence131
973Difference Array | Range update query in O(1)131
974Count Submatrices With All Ones LeetCode Solution131
975Minimum Height Trees LeetCode Solution131
976Breadth First Search (BFS) for a Graph131
977Binary Search Tree Delete Operation131
978My Calendar I LeetCode Solution131
979Maximum Product Subarray130
980Maximum subsequence sum such that no three are consecutive130
981Sign of the Product of an Array LeetCode Solution130
982Find the Difference Leetcode Solution130
983Count pair with Given Sum130
984Sliding Window Maximum130
985Reverse Nodes in K-Group130
986Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
987Find postorder traversal of BST from preorder traversal130
988Find Maximum of Minimum for Every Window Size in a Given Array130
989Height of a generic tree from parent array129
990Serialize and Deserialize Binary Tree129
991Largest divisible pairs subset129
992Level Order Traversal of Binary Tree129
993Minesweeper LeetCode Solution129
994Valid Boomerang Leetcode Solution129
995The Painter’s Partition Problem129
996Count subarrays where second highest lie before highest129
997Boundary Traversal of binary tree129
998Insertion in a Binary Tree129
999Asteroid Collision LeetCode Solution129
1000Count Primes in Ranges129
1001Kth Smallest Element in a BST Leetcode Solution128
1002Friends Of Appropriate Ages LeetCode Solution128
1003Longest Nice Substring LeetCode Solution128
1004Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1005Find Duplicate Subtrees128
1006Product of Array Except Self LeetCode Solution128
1007Find the First Circular Tour that visits all the Petrol Pumps128
1008Number Of Longest Increasing Subsequence128
1009Compute nCr % p128
1010Find number of pairs in an array such that their XOR is 0128
1011Maximum Length of Repeated Subarray128
1012Unique Paths II128
1013Collect maximum points in a grid using two traversals128
1014Rearrange array such that even positioned are greater than odd128
1015First missing positive128
1016Ugly Numbers127
1017Next Greater Element III LeetCode Solution127
1018Level order traversal using two Queues127
1019Build an Array With Stack Operations Leetcode Solution127
1020Construct Binary Tree from given Parent Array representation127
1021Graph Valid Tree LeetCode Solution127
1022Partition Equal Subset Sum127
1023Maximum Number of Ways to Partition an Array LeetCode Solution127
1024Advantages of BST over Hash Table127
1025Make The String Great Leetcode Solution127
1026The Maze III LeetCode Solution127
1027String Matching in an Array Leetcode Solution127
1028Shortest Completing Word Leetcode Solution127
1029Construction of Longest Increasing Subsequence (N log N)127
1030Binary Search Tree127
1031Scramble String LeetCode Solution127
1032Boolean Parenthesization Problem126
1033Design Hit Counter LeetCode Solution126
1034Balanced Binary Tree126
1035Longest subsequence such that difference between adjacents is one126
1036Implement Trie (Prefix Tree) Leetcode Solution126
1037Maximum length subsequence with difference between adjacent elements as either 0 or 1126
1038Number of palindromic paths in a matrix126
1039Double the first element and move zero to end126
1040Kill Process LeetCode Solution126
1041Maximum weight transformation of a given string126
1042Morris Inorder Traversal126
1043Largest Number Leetcode Solution126
1044Lowest Common Ancestor125
1045Minimum Index Sum of Two Lists125
1046Maximum Sum of 3 Non-Overlapping Subarrays125
1047Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’125
1048Invalid Transactions LeetCode Solution125
1049Iterative Depth First Traversal of Graph125
1050Minimum Size Subarray Sum125
1051Maximum Product of Indexes of Next Greater on Left and Right125
1052Path Sum II LeetCode Solution125
1053Find whether a subarray is in form of a mountain or not125
1054Validate Binary Search Tree125
1055K Closest Points to Origin Leetcode Solution125
1056Add two numbers124
1057Custom Sort String Leetcode Solution124
1058Bitwise AND of Numbers Range LeetCode Solution124
1059Move all negative elements to end in order with extra space allowed124
1060Find a Peak Element II LeetCode Solution124
1061Regular Expression Matching Regular Expression Matching LeetCode Solution124
1062Employee Importance LeetCode Solution124
1063Find Peak Element124
1064Ugly Number II LeetCode Solution124
1065Available Captures for Rook Leetcode Solution124
1066Defanging an IP Address LeetCode Solution124
1067Kth Smallest Element in a Sorted Matrix LeetCode Solution124
1068Binary Tree Right Side View LeetCode Solution123
1069Count minimum steps to get the given desired array123
1070Super Ugly Number123
1071Remove Duplicates from Sorted Array II Leetcode Solution123
1072Recover Binary Search Tree Leetcode Solution123
1073Day of the Year Leetcode Solution123
1074Rearrange array such that even index elements are smaller and odd index elements are greater123
1075Largest BST Subtree LeetCode Solution123
1076Types of Binary Tree123
1077Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution123
1078Number of Closed Islands Leetcode Solution122
1079Smallest Common Region Leetcode Solution122
1080Divisible Pairs Counting122
1081Print all triplets in sorted array that form AP122
1082Binary Tree Data Structure122
1083Maximum difference between frequency of two elements such that element having greater frequency is also greater122
1084Populating Next Right Pointers in Each Node Leetcode Solution122
1085Search in Sorted Rotated Array122
1086Find the minimum distance between two numbers122
1087Print Next Greater Number of Q queries122
1088Path Sum122
1089Count pairs from two sorted arrays whose sum is equal to a given value x122
1090Number of siblings of a given Node in n-ary Tree122
1091Find Smallest Range Containing Elements from k Lists122
1092Number of Students Doing Homework at a Given Time Leetcode Solution122
1093Clone a Binary Tree with Random Pointers121
1094Remove Palindromic Subsequences Leetcode Solution121
1095Constant time range add operation on an array121
1096Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1097Combination Sum IV LeetCode Solution121
1098Root to Leaf path with target sum Leetcode Solutions121
1099Longest Bitonic Subsequence121
1100Serialize and Deserialize Binary Tree LeetCode Solution121
1101Generate Parentheses Leetcode Solution121
1102Convert BST into a Min-Heap without using array120
1103Level of Each node in a Tree from source node120
1104Print Right View of a Binary Tree120
1105Maximize Distance to Closest Person LeetCode Solution120
1106Find maximum difference between nearest left and right smaller elements120
1107Distinct Subsequences120
1108Bottom View of a Binary Tree120
1109Search Insert Position120
1110Write Code to Determine if Two Trees are Identical120
1111Valid Tic-Tac-Toe State LeetCode Solution120
1112Remove duplicates from sorted array120
1113Subarrays with K Different Integers Leetcode Solution120
1114Third Maximum Number Leetcode Solution120
1115Prime Palindrome LeetCode Solution119
1116Palindrome Permutation LeetCode Solution119
1117Increasing Triplet Subsequence LeetCode Solution119
1118Find Three Element From Different Three Arrays Such That a + b + c = sum119
1119Minimum sum of squares of character counts in a given string after removing k characters119
1120Count Largest Group Leetcode Solution119
1121Minimum Score Triangulation of Polygon Leetcode Solution119
1122Cutting a Rod119
1123Next Permutation Leetcode Solution119
1124Iterative method to find ancestors of a given binary tree118
1125Mean of Array After Removing Some Elements Leetcode Solution118
1126Moser-de Bruijn Sequence118
1127Maximum Binary Tree118
1128Consecutive Characters LeetCode Solution118
1129Reformat The String Leetcode Solution118
1130Thousand Separator Leetcode Solution118
1131Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1132Products of ranges in an array118
1133Maximum Product Subarray118
1134Topological Sorting118
1135Print modified array after executing the commands of addition and subtraction118
1136Cells with Odd Values in a Matrix LeetCode Solution118
1137Longest Increasing Consecutive Subsequence117
1138Construct K Palindrome Strings LeetCode Solution117
1139Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1140Search an Element in Sorted Rotated Array117
1141Golomb sequence117
1142Minimum Absolute Difference in BST Leetcode Solution117
1143Sum of Even Numbers After Queries117
1144Maximum Product of Splitted Binary Tree LeetCode Solution116
1145K maximum sums of overlapping contiguous sub-arrays116
1146Kth Smallest Number in Multiplication Table Leetcode Solution116
1147Swap Nodes In Pairs116
1148Check Array Formation Through Concatenation Leetcode Solution116
1149Find maximum length Snake sequence116
1150Red-Black Tree Introduction116
1151Count even length binary sequences with same sum of first and second half bits116
1152Queries for Number of Distinct Elements in a Subarray116
1153Factorial Trailing Zeroes LeetCode Solution116
1154Transform a BST to Greater sum Tree116
1155Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution116
1156Binary Tree to Binary Search Tree Conversion116
1157Rotate Array115
1158Palindromic Substrings Leetcode Solution115
1159Subset Sum Problem in O(sum) space115
1160Possible Bipartition LeetCode Solution115
1161Delete Nodes and Return Forest Leetcode Solution115
1162K’th Largest element in BST using constant extra space115
1163Priority Queue115
1164Merge two BSTs with limited extra space115
1165Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1166Maximize sum of consecutive differences in a circular array115
1167Decision Tree115
1168Closest Binary Search Tree Value Leetcode Solution114
1169Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1170Find the smallest binary digit multiple of given number114
1171Minimum Sideway Jumps LeetCode Solution114
1172Search Suggestions System LeetCode Solution114
1173First Bad Version113
1174Number of Orders in the Backlog Leetcode Solution113
1175Given a binary tree, how do you remove all the half nodes?113
1176Minimum Cost to Move Chips to The Same Position LeetCode Solution113
1177Bus Routes Leetcode Solution113
1178Diameter of N-Ary Tree LeetCode Solution113
1179Find a sorted subsequence of size 3 in linear time113
1180Count Pairs Whose Products Exist in Array113
1181Longest Repeated Subsequence112
1182Contiguous Array LeetCode Solution112
1183Maximum number of segments of lengths a, b and c112
1184Decrease Elements To Make Array Zigzag LeetCode Solution112
1185Web Crawler LeetCode Solution112
1186Reverse a Path in BST using Queue112
1187Lowest Common Ancestor in Binary Search Tree111
1188Champagne Tower LeetCode Solution111
1189Find Largest Value in Each Tree Row LeetCode Solution111
1190Swapping Nodes in a Linked List Leetcode Solution111
1191Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1192Matchsticks to Square Leetcode Solution111
1193Queue Reconstruction by Height111
1194How to print maximum number of A’s using given four keys110
1195Reformat Date LeetCode Solution110
1196Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution110
1197Valid Perfect Square LeetCode Solution110
1198Moving Stones Until Consecutive Leetcode Solution110
1199Closest Leaf in a Binary Tree LeetCode Solution110
1200Valid Triangle Number110
1201New 21 Game110
1202Maximum sum bitonic subarray110
1203Replace two consecutive equal values with one greater109
1204Graph and its representation109
1205Write a function to get the intersection point of two Linked Lists109
1206The kth Factor of n Leetcode Solution109
1207Print modified array after multiple array range increment operations109
1208Sum of Left Leaves LeetCode Solution109
1209Minimum Moves to Equal Array Elements LeetCode Solution109
1210Maximum Depth Of Binary Tree109
1211Kth Smallest Element in a BST109
1212Maximum sum of pairs with specific difference109
1213Array Queries for multiply replacements and product109
1214Range Sum Query using Sparse Table109
1215Maximum Value at a Given Index in a Bounded Array LeetCode Solution108
1216Arithmetic Slices II – Subsequence LeetCode Solution108
1217Merge Sort108
1218Guess The Word108
1219Concatenation of Array LeetCode Solution108
1220Maximum sum of a path in a Right Number Triangle108
1221BST to a Tree with Sum of all Smaller Keys108
1222Integer Break LeetCode Solution108
1223Range Queries for Longest Correct Bracket Subsequence108
1224Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution108
1225Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1226Design Skiplist LeetCode Solution108
1227Path Crossing Leetcode Solution108
1228Queries on Probability of Even or Odd Number in given Ranges107
1229Check if all levels of two Binary Tree are anagrams or not107
1230Lowest Common Ancestor of a Binary Tree Leetcode Solution107
1231Check if each internal node of a BST has exactly one child107
1232Flatten 2D Vector LeetCode Solution107
1233Check for Identical BSTs without building the trees107
1234Divide Two Integers Leetcode Solution106
1235Perfect Squares LeetCode Solution106
1236Count Subsets Having Distinct Even Numbers106
1237Graph Cloning106
1238Longest Common Prefix Using Word by Word Matching106
1239Power of Two106
1240Check Completeness of a Binary Tree LeetCode Solution106
1241Maximum Array from Two given Arrays Keeping Order Same105
1242Bold Words in String LeetCode Solution105
1243Sliding Window Median Leetcode Solution105
1244Largest Plus Sign Leetcode Solution105
1245Contiguous Array105
1246Print n terms of Newman-Conway Sequence105
1247Maximize Elements Using Another Array105
1248Find minimum number of merge operations to make an array palindrome105
1249Symmetric Tree LeetCode Solution Leetcode Solution105
1250Mean of range in array105
1251Missing Number104
1252Verify Preorder Serialization of a Binary Tree104
1253Find k-th smallest element in BST (Order Statistics in BST)104
1254Find Minimum in Rotated Sorted Array II LeetCode Solution104
1255LRU Cache Leetcode Solution104
1256Check If a String Can Break Another String Leetcode Solution103
1257Print Ancestors of a Given Binary Tree Node Without Recursion103
1258Parallel Courses II LeetCode Solution103
1259Next greater element103
1260Maximum Product Subarray102
1261Smallest Range II Leetcode Solution102
1262Excel Sheet Column Title LeetCode Solution102
1263Minimum Remove to Make Valid Parentheses LeetCode Solution102
1264Merge k Sorted Lists Leetcode Solution102
1265Count and Toggle Queries on a Binary Array101
1266Image Overlap LeetCode Solution101
1267Minimum Time to Collect All Apples in a Tree LeetCode Solution101
1268Check if two nodes are on the same path in a Tree100
1269Check in binary array the number represented by a subarray is odd or even100
1270Orderly Queue LeetCode Solution100
1271Palindrome Partitioning100
1272Koko Eating Bananas LeetCode Solution99
1273Merge Sorted Array98
1274Check if X can give change to every person in the Queue98
1275Min Cost Climbing Stairs LeetCode Solution98
1276Newman–Shanks–Williams prime98
1277Number of elements less than or equal to a given number in a given subarray97
1278Peeking Iterator LeetCode Solution97
1279Largest Submatrix With Rearrangements LeetCode Solution97
1280Different Ways to Add Parentheses Leetcode Solution97
1281Maximum Sum Increasing Subsequence96
1282Range Minimum Query (Square Root Decomposition and Sparse Table)95
1283Number of indexes with equal elements in given range95
1284Find maximum average subarray of k length95
1285Queries for Decimal Values of Subarrays of a Binary Array94
1286Longest Substring Without Repeating Characters Leetcode Solution93
1287Maximum product of an increasing subsequence93
1288Array Nesting Leetcode Solution93
1289Arranging Coins Leetcode Solution92
1290Binary Tree to Binary Search Tree Conversion using STL set92
1291Check given array of size n can represent BST of n levels or not92
1292Encoded String With Shortest Length LeetCode Solution91
1293Minimum Number of People to Teach LeetCode Solution91
1294Minimum Total Space Wasted With K Resizing Operations LeetCode Solution90
1295Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1296Random Pick Index LeetCode Solution90
1297Convert a BST to a Binary Tree such that sum of all greater keys is added to every key89
1298Queries on XOR of greatest odd divisor of the range89
1299Reach a Number LeetCode Solution89
1300Convert to Base -2 LeetCode Solution89
1301Find the Winner of the Circular Game LeetCode Solution88
1302Jump Game IV LeetCode Solution87
1303Insert Delete GetRandom O(1) Leetcode Solution86
1304Add Two Numbers II Leetcode Solution86
1305Palindrome Number LeetCode Solution85
1306Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution83
1307Design Underground System Leetcode Solution83
1308Print Maximum Length Chain of Pairs83
1309Vertical Order Traversal of Binary Tree LeetCode Solution82
1310Continuous Subarray Sum LeetCode Solution81
1311Detect Capital Leetcode Solution80
1312Design A Leaderboard Leetcode Solution78
1313Substring with Concatenation of All Words Leetcode Solution75
1314Minimum Swaps to Group All 1’s Together Leetcode Solution75
1315Minimum Path Sum Leetcode Solution72
1316Top K Frequent Elements LeetCode Solution71
1317Odd Even Linked List Leetcode Solution70
1318Binary Tree Inorder Traversal LeetCode Solution70
1319Maximum Population Year LeetCode Solution69
1320Count Sub Islands LeetCode Solution69
1321Shortest Unsorted Continuous Subarray LeetCode Solution68
1322Shifting Letters LeetCode Solution68
1323Best Meeting Point LeetCode Solution68
1324Find the Town Judge LeetCode Solution68
1325Decode String Leetcode Solution67
1326Longest Common Subsequence LeetCode Solution67
1327Sum Root to Leaf Numbers LeetCode Solution66
1328Find the Town Judge LeetCode Solution64
1329Design Add and Search Words Data Structure LeetCode Solution64
1330Rectangle Overlap LeetCode Solution62
1331Maximum Population Year LeetCode Solution62
1332Score of Parenthesis LeetCode Solution59
1333Stone Game IV LeetCode Solution59
1334Insert into a Sorted Circular Linked List LeetCode Solution59
1335Range Sum Query 2D – Immutable LeetCode Solution58
1336Flatten Binary Tree to Linked List LeetCode Solution58
1337Valid Triangle Number LeetCode Solution57
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution51
1340Divide Chocolate LeetCode Solution47
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution38
1342Sort Colors LeetCode Solution35
1343Reverse Integer Leetcode Solution35
1344Range Sum of BST LeetCode Solution35
1345Find K Closest Elements LeetCode Solution32
1346Excel Sheet Column Number LeetCode Solution29
1347Rotate String LeetCode Solution29
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution27
Translate »