Vertical Order Traversal of Binary Tree LeetCode Solution

Difficulty Level Hard
Frequently asked in Adobe Amazon Apple Atlassian Bloomberg ByteDance Facebook Microsoft Samsung Uber
Binary Tree categories - Medium Depth First Search Hashing tiktok TreeViews 90

Problem Statement

Vertical Order Traversal of Binary Tree LeetCode Solution says – Given the root of a binary tree, calculate the vertical order traversal of the binary tree.

For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).

The vertical traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

Return the vertical order traversal of the binary tree.

 

Example 1:

PinInput:

 root = [3,9,20,null,null,15,7]

Output:

 [[9],[3,15],[20],[7]]

Explanation:

Column -1: Only node 9 is in this column.
Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.
Column 1: Only node 20 is in this column.
Column 2: Only node 7 is in this column.

Example 2:

Vertical Order Traversal of Binary Tree LeetCode SolutionPinInput:

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

Output:

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

Explanation:

Column -2: Only node 4 is in this column.
Column -1: Only node 2 is in this column.
Column 0: Nodes 1, 5, and 6 are in this column.
          1 is at the top, so it comes first.
          5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.
Column 1: Only node 3 is in this column.
Column 2: Only node 7 is in this column.

Example 3:

Vertical Order Traversal of Binary Tree LeetCode SolutionPinInput:

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

Output:

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

 

Constraints:

  • The number of nodes in the tree is in the range [1, 1000].
  • 0 <= Node.val <= 1000

 

Algorithm:

Idea:

  • In order to find Vertical Order Traversal of Binary Tree. First, we will focus on the index of all the elements then we will create a list and hashmap and Stores all the value of the same index into a list within the hashmap then sort the hashmap and at last we will return that list as our answer.

Approach:

  • First, we will make one queue and one answer list, and one Hashmap after that we will use level order traversal in order to achieve the answer.
  • Then we will make one tuple pair i.e (root,0) [0 – Index of root element] after that when we will traverse level-wise we decrease the value of the index by 1 in the case of root.left element and Increase the value of the index by 1 in case root. right element.
  • Also in each iteration, we’ll check if the index already exists in Hashmap, if it exists then we will append the value of the index into the index key otherwise if not then create a new key i.e Index and store the value as a list of root.val.
  • After that, we will sort the hashmap and add all lists into the answer list and Finally return that list as our answer.
  • Hence, we will find the Vertical Order Traversal of the Binary Tree.

Vertical Order Traversal of Binary Tree LeetCode SolutionPin

Vertical Order Traversal of Binary Tree LeetCode SolutionPin

Code:

Vertical Order Traversal of a Binary Tree Python Leetcode Solution:

class Solution:
    def verticalTraversal(self, root: Optional[TreeNode]) -> List[List[int]]:
        
        queue = [(root,0)]
        dic = {}
        ans = []
        
        while(queue):
            k = queue
            queue = []
            for v,i in k:
                
                if i in dic:
                    dic[i].append(v.val)
                
                else:
                    dic[i] = [v.val]
                    
            
                if v.left:
                    queue.append((v.left,i-1))
                
                if v.right:
                    queue.append((v.right,i+1))
            
            queue.sort(key = lambda x:(x[1],x[0].val))
                
        for i in sorted(dic):
            ans.append(dic[i])
            
        return ans

Vertical Order Traversal of a Binary Tree Java Leetcode Solution:

class Solution {
    public List<List<Integer>> verticalTraversal(TreeNode root) {
        
        class Group{
            TreeNode treeNode;
            int dis;
            int vd;
            Group(TreeNode treeNode, int dis, int vd){
                this.treeNode = treeNode;
                this.dis = dis;
                this.vd = vd;
            }
        }
        List<List<Integer>> ans = new ArrayList();
        if( root == null)   return ans;
        Map<Integer,List< Group>> dic = new HashMap();
        List<Group > list = new ArrayList();
        Queue<Group> queue = new LinkedList();
        queue.add(new Group(root, 0, 0));
        int minDis = Integer.MAX_VALUE;
        int maxDis = Integer.MIN_VALUE;
        
        while( ! queue.isEmpty() ){
            Group group = queue.poll();
            
            minDis = Math.min(minDis, group.dis);
            maxDis = Math.max(maxDis, group.dis);
            
            if( group.treeNode.left !=null ) {
                queue.add(new Group(group.treeNode.left, group.dis-1, group.vd+1) );
            }
            if( group.treeNode.right !=null){
                queue.add(new Group(group.treeNode.right, group.dis+1, group.vd+1) );
            }

            if( dic.containsKey(group.dis)){
                list = dic.get(group.dis);
                list.add(group);
                dic.put(group.dis,new ArrayList(list ));
                list.clear();
            }
            else{
                list.add(group );
                dic.put(group.dis, new ArrayList(list));
                list.clear();
            }
         }
        
        int index = 0;
        for(int d = minDis; d <= maxDis; d++ ){
            list =  dic.get(d);
            Collections.sort(list, (a,b) -> {
                
                if( a.vd == b.vd)   return a.treeNode.val - b.treeNode.val ;
                else
                    return a.vd - b.vd;
            
            } );
            
            ans.add(new ArrayList());
            
             for(Group g : list){
                 ans.get(index).add(g.treeNode.val);
             }
            
            index++;
        }
        return ans;
    }
}

 

Complexity Analysis of Vertical Order Traversal of a Binary Tree Leetcode Solution:

Time complexity:

The Time Complexity of the above solution is O(nlogn) where n = the number of nodes in the Binary Tree. We have traversed the whole array and sorted the hashmap.

Space complexity:

The Space Complexity of the above solution is O(n) since we have created a queue that has a maximum size of n.

Similar Problem: https://www.tutorialcup.com/interview/tree/vertical-sum-in-a-given-binary-tree.htm

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2826
2Java program to find the number of Nodes in a Binary Tree2505
3Reverse a string without affecting special characters2466
4Delete a node of a linked list at given position1981
5Palindrome using Recursion1868
6Insert nodes in a linked list in a sorted way (Ascending Order)1664
7Find elements pair from array whose sum equal to number1651
8Sort Elements by Frequency of Occurrences1636
9Write a program to print all permutations of a given string1609
10Find Minimum Distance Between Two Numbers in an Array1477
11Create a Doubly Linked List1447
12Quick Sort1422
13Reverse an Array1416
14Smallest window in a string containing all characters of another string1399
15Find a Triplet That Sum to a Given Value1360
16Recursively remove all adjacent duplicates1357
17First Repeating Element1345
18Arrange Even and Odd number such that Odd comes after Even1325
19Sum of numbers in String1322
20Smallest Positive Number Missing in an Unsorted Array1289
21Check if the Elements of an Array are Consecutive1259
22Detect a loop in the Linked List1240
23Largest Sum Contiguous Subarray1233
24Quick Sort on SIngly Linked List1220
25Subarray with Given Sum1216
26Print all Possible Combinations of R Elements in a given Array of size N1207
27Recursive function to do substring search1200
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1128
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1108
32Maximum Subarray Sum using Divide and Conquer1102
33Remove characters from first string which are in second1072
34Find Leaders in an Array1064
35Swap nodes in the linked list1040
36Find the Number Occurring Odd Number of Times in an Array1008
37Arrange given Numbers to Form the Biggest Number II996
38Find the second most frequent character990
39Given a string find its first non-repeating character972
40Find Triplet in Array With a Given Sum966
41Total number of occurrences of a given item in the linked list956
42Given a sorted array and a number x, find the pair in array whose sum is closest to x956
43A Program to check if strings are rotations of each other or not949
44Print all possible words from phone digits936
45Find the Missing Number927
46Rearrange Positive and Negative Numbers Alternatively in Array923
47Longest Palindromic Substring907
48Segregate even and odd nodes in a linked list888
49Print Longest common subsequence885
50Union and Intersection of Two Linked Lists877
51Transform one string to another using minimum number of given operations872
52Check rearranged string can form a palindrome850
53Rearrange given Array in Maximum Minimum Form849
54Count Possible Triangles822
55Iterative Implementation of Quick Sort820
56Multiplication of Two Matrices805
57Check if the linked list is palindrome798
58Rotate a Linked List795
59Count of Triplets With Sum Less than Given Value795
60Stock Buy Sell to Maximize Profit795
61Concatenation of two strings766
62Tug of War762
63Count Number of Substrings with K Distinct Character’s758
64Print all duplicates in the input string758
65Find Nearest Greater and Smaller Element750
66The Celebrity Problem741
67Find Pythagorean Triplets from Array740
68Reverse String Without Temporary Variable735
69Remove ‘b’ and ‘ac’ from a given string734
70Find all Common Elements in Given Three Sorted Arrays731
71Remove all duplicates in an unsorted linked list713
72Find the Row with Maximum Number of 1’s709
73Find the Peak Element from an Array704
74Find the subarray whose sum is equal to a given number X697
75Remove Minimum Characters so that Two Strings Become Anagrams693
76Find Smallest Missing Number in a Sorted Array691
77Addition of Two Matrices689
78A Product Array Puzzle688
79Insertion Sort687
80Implement Two Stacks in an Array679
81Generate all Binary Strings Without Consecutive 1’s679
82Maximum Sum of Non Consecutive Elements671
83Maximum Product Subarray II660
84Lexicographic rank of string656
85Multiplication of Previous and Next650
86Check if Two given Matrices are Identical648
87Subtraction of Two Matrices639
88Merge K Sorted Arrays and Print Sorted Output635
89Move All the Zeros to the End of the Given Array633
90Divide a string in N equal parts626
91Form Minimum Number from Given Sequence of D’s and I’s626
92Online Algorithm for Checking Palindrome in a Stream626
93Check whether two strings are anagram of each other615
94Maximum Circular Subarray Sum615
95Remove recurring digits in a given number614
96Sort a stack using a temporary stack611
97Sort a linked list that is sorted alternating ascending and descending610
98Find the Minimum Element in a Sorted and Rotated Array608
99Move last element of the Linked List at first place604
100First Circular Tour to Visit all the Petrol Bunks602
101Subarray and Subsequence602
102Largest Subarray with Equal Number of 0’s and 1’s600
103Compare two strings(linked lists)595
104Flattening a linked list594
105Maximum Element in an Array which is Increasing and then Decreasing592
106Palindrome Permutations of a String587
107Elements Appear more than N/K times in Array584
108Palindromes in a given range580
109Majority Element579
110Run length encoding576
111Pangram Checking573
112Minimum insertions to form a shortest palindrome573
113Print all permutations with repetition573
114Merge a linked list into another at alternate positions569
115Minimum Characters to be Added at Front to Make String Palindrome568
116Remove all duplicates in a sorted linked list566
117Rearrange a given linked list in-place564
118Most repeating character in a string564
119Minimum number of Merge Operations to make an Array Palindrome563
120Rotate string to get lexicographically minimum string559
121Repeated Subsequence of Length Two or More558
122Print all anagrams together in a sequence of words555
123Reorder an Array According to the Given Indexes551
124Pancake Sorting Problem544
125Two Sum Leetcode Solution542
126Merge Overlapping Intervals II540
127Clone a Linked List with next and random pointer538
128Transpose of a Matrix529
129Size of The Subarray With Maximum Sum528
130Remove duplicates from a string523
131Removing Spaces from a String using stringstream523
132Remove Extra Spaces from a String522
133Maximum Sum Increasing Subsequence521
134Smallest Palindrome after Replacement521
135Check if a given string is a rotation of a palindrome519
136Partition Problem518
137Longest Palindrome can be Formed by Removing or Rearranging Characters517
138Check whether Strings are K Distance Apart or Not508
139Generate all Binary Strings from Given Pattern506
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized504
141Delete Last Occurrence504
142Insert Node in the Sorted Linked List503
1433Sum Leetcode Solution502
144Length of Longest valid Substring500
145Check if Two given Strings are Isomorphic to each other495
146Maximum difference between two elements such as larger element comes after smaller489
147Program to Toggle all Characters in a String486
148Given string is interleaving of two other strings or not486
149Count Minimum Steps to Get the given Array482
150Number of Smaller Elements on Right Side481
151Merge sort better than quick sort for linked lists480
152Find Pair with Given Difference478
153Check length of a String is Equal to the Number Appended at its Last474
154Check if all Rows of a Matrix are Circular Rotations of Each Other472
155Find nth node of the Linked list from the end472
156Longest Common Prefix using Divide and Conquer470
157Find a Fixed Point in a Given Array467
158Sort 0s 1s and 2s in an Array465
159Print all interleavings of given two strings461
160Find the Subarray of given length with Least Average458
161Reverse words in a given string457
162Compare Two Version Numbers457
163Median of Two Sorted Arrays LeetCode Solution455
164Split linked list using alternate nodes454
165Merge two sorted linked lists such that merged list is in reverse order454
166Reorder Array Using Given Indexes453
167Print Reverse of a string (Recursion)452
168Print string of odd length in ‘X’ format444
169Find K Length Subarray of Maximum Average440
170Find Element Using Binary Search in Sorted Array436
171Swap Kth Node from beginning with Kth Node from End434
172Print all Palindromic Partitions of a String432
173Find Duplicates in an Array in Most Efficient Way430
174print all palindromic partitions422
175Maximum Length of Chain Pairs419
176Shortest Superstring Problem418
177Flatten a multilevel linked list416
178Check if String Follows Order of Characters by a Pattern or not415
179Sorting a K Sorted Array412
180Sort a String According to Another String408
181Longest Span with same Sum in two Binary Arrays II399
182Find a Sorted Subsequence of size 3399
183Reverse a Linked List in groups399
184Program to add two binary digits395
185Recursively print all the sentences that can be formed from list of word lists394
186Find the two Numbers with Odd Occurrences in an Unsorted Array390
187Longest Common Prefix Using Binary Search II386
188Reverse a Singly Linked List (Iterative/Non-Recursive)384
189Caesar Cipher382
190Kth Non-repeating Character381
191Check if String can Become Empty by Recursively Deleting given Substring381
192Rearrange a linked list in Zig-Zag379
193Rotate Image by 90 degrees378
194Pancake Sorting377
195Longest Common Prefix Word by Word Matching372
196Permutations of a Given String Using STL372
197Perfect Reversible String369
198Merging Two Sorted Arrays365
199Sort a linked list with 0s, 1s and 2s364
200Find the point where a monotonically increasing function becomes positive first time362
201Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes362
202Increasing Subsequence of Length three with Maximum Product362
203Find First non-repeating character in a string361
2041`s and 2`s complement of binary number360
205Four Elements that Sum to Given355
206Delete N nodes after M354
207List items containing all characters of a given word354
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Split a string344
211Palindrome string (number)343
212Minimum Characters to be Removed to Make a Binary String Alternate341
213Recursive Implementation of atoi()338
214Check if a Linked list of Strings form a Palindrome335
215Print All Distinct Elements of the Array335
216Sorting the array of strings332
217Even Substring Count332
218Valid Parentheses LeetCode Solution331
219Convert a String that is Repetition of a Substring of Length K331
220Reverse a singly linked list recursively331
221Maximum occurring character in a string329
222Find the first Repeating Number in a Given Array328
223Can we reverse a linked list in less than O(n) time ?326
224Print Shortest Path to Print a String on Screen325
225Binary Tree to Doubly linked list323
226Convert string1 to string2 in one edit322
227Reverse a String using Stack322
228Nth Character in Concatenated Decimal String321
229Maximum Subarray Leetcode Solution320
230Sort Elements by Frequency II320
231wildcard character matching319
232Lower Case To Upper Case317
233Count the number of words315
234Merge Two Sorted Arrays313
235Find the Lost Element From a Duplicated Array311
236Split Four Distinct Strings311
237Find middle of the Linked List310
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets302
240Matrix Chain Multiplication using Dynamic Programming298
241Next Greater Element in an Array295
242Palindrome Permutation292
243Roman to Integer Leetcode Solution289
244Find Nth Node286
245Triplet from three linked lists with given sum285
246Searching a node in a Binary Search Tree285
247Find All Pairs With a Given Difference284
248Delete a Tree281
249String(represents an integer) to value280
250Word Search Leetcode Solution279
251Reverse a String279
252Print all Possible Ways to Break a String in Bracket Form278
253Reverse Bits278
254Binary Tree276
255How to Efficiently Implement k Stacks in a Single Array?274
256Delete a node under given conditions274
257Change Gender of a given String273
258Sort an array of strings272
259Meeting Rooms II LeetCode Solution271
260Count Pairs With Given Sum270
261First non Repeating Element270
262Number of sub-strings which recursively add up to 9269
263Longest Common Extension269
264Repeated Substring Pattern268
265Remove middle points in a linked list of line segments268
266Move all negative elements to one side of array266
267Toeplitz Matrix266
268Longest Palindromic Substring LeetCode Solution264
269Remove spaces from a string263
270Shuffle a given Array263
271Min Stack262
272N queen problem260
273Cuckoo sequence program256
274Number of Islands LeetCode Solution255
275Dijkstra Algorithm254
276House Robber Leetcode Solution253
277Minimize the maximum difference between the heights253
278Find, second, frequent, character252
279Max stack252
280Most Frequent Element in an Array249
281Clone a linked list with next and random pointer (Hashing)249
282Search Insert Position Leetcode Solution249
283KMP Algorithm246
284Valid Palindrome Leetcode Solution246
285Sort linked which is sorted on absolute values246
286Expression Evaluation246
287Sudoku Solver245
288Subset Leetcode245
289Reverse words in a string244
290Number Of 1 bits243
291Fibonacci numbers243
292Plus One Leetcode Solution242
293Combination Sum Leetcode Solution242
294Min Stack Leetcode Solution242
295Evaluation of Postfix Expression241
296How to Delete a Linked List241
297Word Search239
298Backspace String Compare236
299Merge Sorted Arrays Leetcode Solution234
300Set Matrix Zeroes232
301Reversing a Queue232
302Subarray with 0 sum232
303Sqrt(x) Leetcode Solution232
304Pair of Positive Negative Values in an Array232
305Rabin Karp Algorithm231
306Contains Duplicate II Leetcode Solution229
307Product of array except self229
308Tower Of Hanoi227
309Common elements in all rows of a given matrix227
310Delete middle element of a stack226
311Integer to Roman Leetcode Solution226
312Combination Sum226
313Intersection of Two Arrays II Leetcode Solution225
314String Compression224
315Pascal Triangle Leetcode224
316Reverse individual words223
317Find Top K (or Most Frequent) Numbers in a Stream222
318Construct Binary Tree from Given Inorder and Preorder Traversals221
319Arithmetic Expression Evaluation221
320Sliding Window Technique221
321Minimum swaps required to bring all elements less than or equal to k together221
322Count subarrays with equal number of 1’s and 0’s221
323Implementation of Deque using Doubly Linked List220
324Count of index pairs with equal elements in an array220
325Single Number Leetcode Solution220
326Minimum Value to Get Positive Step by Step Sum Leetcode Solution219
327Add Binary Leetcode Solution219
328Bellman Ford Algorithm219
329Second Most Repeated Word in a Sequence218
330Pow(x, n) Leetcode Solution217
331Palindrome Linked List Leetcode Solution217
332Segregate even and odd numbers217
333Contains Duplicate216
334Postfix to Infix Conversion216
335Count Odd Numbers in an Interval Range Leetcode Solution216
336Find sum of non-repeating elements (distinct) elements in an array216
337Design a stack that supports getMin() in O(1) time and O(1) extra space216
338Page Replacement Algorithms in Operating Systems216
339Maximum Number of Balloons Leetcode Solution215
340Sort elements by frequency215
341Kruskal Algorithm214
342Next Permutation214
343Third Maximum Number Leetcode Solution214
344K-th Smallest Element in a Sorted Matrix212
345Convex Hull Algorithm211
346Group Words With Same Set of Characters211
347Permutations Leetcode Solution210
348Longest Substring Without Repeating Characters LeetCode Solution210
349Sum of minimum and maximum elements of all subarrays of size k210
350Longest Common Prefix Leetcode Solution209
351Smallest Subarray with k Distinct Numbers209
352Find Lucky Integer in an Array Leetcode Solution209
353Top K Frequent Words209
354Find the Town Judge Leetcode Solution209
355Majority Element Leetcode Solution208
356Maximum Subarray208
357Spiral Matrix LeetCode Solution207
358Swap Nodes in Pairs Leetcode Solutions207
359Scramble String207
360Find Numbers with Even Number of Digits Leetcode Solution207
361Minimum operation to make all elements equal in array206
362Evaluate Division206
363First element occurring k times in an array206
364Count subarrays having total distinct elements same as original array206
365Merge Two Sorted Lists Leetcode Solutions205
366Minimum Path Sum205
367Number of Good Pairs Leetcode Solution205
368Sorting array using Stacks205
369Prefix to Infix Conversion205
370Given two unsorted arrays find all pairs whose sum is x204
371Missing Number Leetcode Solution204
372Count Primes Leetcode Solutions204
373Check if two arrays are equal or not204
374Special Number204
375Best Time to Buy and Sell Stock  II Leetcode Solution203
376Minimum Absolute Difference Leetcode Solution203
377Huffman Coding202
378Sort Array by Increasing Frequency Leetcode Solution202
379Pascal’s Triangle II Leetcode Solution202
380Power of Two Leetcode Solution202
381Top K Frequent Elements201
382Minimum Steps to reach target by a Knight201
383Find All Numbers Disappeared in an Array Leetcode Solution201
384Reverse a Number Using Stack201
385House Robber II Leetcode Solution201
386Maximal Square201
387Unique Paths Leetcode Solution201
388Find duplicates in a given array when elements are not limited to a range201
389Search in Rotated Sorted Array Leetcode Solution201
390Single Number200
391Fizz Buzz Leetcode200
392Running Sum of 1d Array Leetcode Solution199
393Reversing the First K elements of a Queue199
394Matrix Diagonal Sum Leetcode Solution199
395Maximum possible difference of two subsets of an array198
396Sort Integers by The Number of 1 Bit Leetcode Solution198
397Leetcode Permutations198
398Group Anagrams198
399Find Minimum In Rotated Sorted Array198
400Sorting using trivial hash function198
401Coin Change 2 Leetcode Solution197
402Happy Number Leetcode Solution197
403How to Implement Stack Using Priority Queue or Heap?197
404Maximum Distance Between two Occurrences of Same Element in Array197
405How Many Numbers Are Smaller Than the Current Number Leetcode Solution197
406Max Consecutive Ones Leetcode Solution196
407Range Sum Query 2D – Immutable Leetcode Solution196
408Unique Paths196
409Convert String To Int195
410Zigzag Conversion195
411Expression Contains Redundant Bracket or Not195
412Remove Duplicates from Sorted Array Leetcode Solution195
413Decode String195
414Find the Closest Palindrome number195
415Find Number of Employees Under every Employee195
416Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution195
417Monotonic Array LeetCode Solution194
418Subarray Sum Equals k194
419Smallest Element Repeated Exactly K Times194
420Subarray Sum Equals K LeetCode Solution194
421Fibonacci Number LeetCode Solution194
422Check if Array Contains Contiguous Integers With Duplicates Allowed194
423Difference between highest and least frequencies in an array194
424Best Time to Buy and Sell Stock III Leetcode Solution194
425Subset sum problem193
426Reverse Vowels of a String Leetcode Solution193
427Length of the largest subarray with contiguous elements193
428Capacity To Ship Packages Within D Days Leetcode Solution193
429Find The Duplicate Number193
430Reverse Integer193
431Reverse a Stack Using Recursion192
432Implement Stack and Queue using Deque192
433Find Median from data Stream192
434Check If N and Its Double Exist Leetcode Solution192
435Find Winner on a Tic Tac Toe Game Leetcode Solution192
436Subtract the Product and Sum of Digits of an Integer Leetcode Solution192
437Palindrome Substring Queries191
438Delete a Node from linked list without head pointer191
439LRU Cache Implementation191
440Letter Case Permutation191
441Generate a String With Characters That Have Odd Counts Leetcode Solution191
442Shuffle the Array Leetcode Solution191
443Sort a stack using recursion190
444Find the Duplicate Element190
445Print All Distinct Elements of a Given Integer Array190
446Priority Queue Using Singly Linked List190
447Trapping Rain Water Leetcode Solution190
448Nth Catalan Number190
449Find top three repeated in array190
450Cumulative Frequency of Count of Each Element in an Unsorted Array190
451Maximum Depth of Binary Tree Leetcode Solution190
452Reverse a String189
453Target Sum189
454Kth largest element in an Array Leetcode Solutions189
455Sorting a Queue without Extra Space189
456Reverse Words in a String III LeetCode Solution189
457Find Common Characters Leetcode Solution189
458Subarrays with distinct elements189
459Find the first repeating element in an array of integers188
460Count Substrings with equal number of 0s, 1s and 2s188
461Bipartite Graph188
462Longest Common Subsequence188
463Word Ladder LeetCode Solution187
464Minimum Moves to Equal Array Elements Leetcode Solution187
465Iterative Tower of Hanoi187
466Find the Difference Leetcode Solution187
467Balanced Binary Tree Leetcode Solution187
468Kids With the Greatest Number of Candies Leetcode Solution187
469Prim’s Algorithm187
470Sum of Subarray Ranges Leetcode Solution187
471The K Weakest Rows in a Matrix Leetcode Solution187
472Integer to English words187
473Concatenation of Array LeetCode Solution186
474Find all pairs (a, b) in an array such that a % b = k186
475Print all subarrays with 0 sum186
476Floyd Warshall Algorithm186
477Excel Sheet Column Number Leetcode Solution186
478Find elements which are present in first array and not in second185
479Number of Steps to Reduce a Number to Zero Leetcode Solution185
480Text Justification LeetCode Solution185
481Merge Two Sorted Linked Lists185
482Find First and Last Position of Element in Sorted Array Leetcode Solution185
483Next Greater Element I Leetcode Solution185
484Kth Largest Element in a Stream Leetcode Solution185
485Merge Overlapping Intervals185
486Fizz Buzz185
487Count pairs from two linked lists whose sum is equal to a given value185
488Zigzag Conversion LeetCode Solution184
489Edit Distance184
490Multiply Strings Leetcode Solution184
491Slowest Key Leetcode Solution183
492Degree of an array183
493Count and Say Leetcode Solution183
494Flood Fill LeetCode183
495Move Zeroes LeetCode Solution183
496Count and Say183
497Reverse a linked list183
498Remove Minimum Number of Elements Such That no Common Element Exist in both Array182
499Implement a stack using single queue182
500Shuffle String Leetcode Solution182
501Design Parking System Leetcode Solution182
502Prefix to Postfix Conversion182
503Max Area of Island182
504Mobile Numeric Keypad Problem182
505MiniMax Algorithm182
506Substring With Concatenation Of All Words181
507Jump Game Leetcode Solution181
508Length of Last Word Leetcode Solution181
509Priority Queue in C++181
510Next Greater Frequency Element181
511Longest Common Prefix using Trie181
512Intersection of Two Arrays181
513Valid Parenthesis String181
514Top View of Binary Tree181
515Last Stone Weight180
516Find N Unique Integers Sum up to Zero Leetcode Solution180
517The Stock Span Problem180
518Find subarray with given sum (Handles Negative Numbers)180
519Convert array into Zig-Zag fashion180
520Peak Index in a Mountain Array180
521Find distinct elements common to all rows of a matrix179
522Postfix to Prefix Conversion179
523Pair with given product179
524Find any one of the multiple repeating elements in read only array178
525Find four elements that sum to a given value (Hashmap)178
526Longest subarray not having more than K distinct elements178
527Contiguous Array Leetcode178
528Find Index of Closing Bracket for a Given Opening Bracket in an Expression178
529N-th Tribonacci Number Leetcode Solution178
530Delete Node in a Linked List Leetcode Solution178
531Longest Common Prefix using Sorting178
532Smallest Subarray With all Occurrences of a Most Frequent Element178
533Iterative Inorder Traversal of a Binary Tree178
534Container with Most Water177
535Recursion177
536Is Subsequence Leetcode Solution177
537Jewels and Stones Leetcode Solution177
538Koko Eating Bananas Leetcode Solution177
539Check if a given array contains duplicate elements within k distance from each other177
540Isomorphic Strings Leetcode Solution177
541Relative Sort Array Leetcode Solution177
542Find missing elements of a range177
543Excel Sheet Column Title Leetcode Solution177
544Count number of triplets with product equal to given number177
545Implement Stack using Queues177
546Best Time to Buy and Sell Stock176
547Implementation of Deque using circular array176
548Sum of Left Leaves Leetcode Solutions176
549Shortest Palindrome176
550Minimum Operations to convert X to Y176
551Largest Perimeter Triangle Leetcode Solution176
552First negative integer in every window of size k176
553Convert a normal BST to Balanced BST176
554Remove Linked List Elements Leetcode Solution175
555Find Words That Can Be Formed by Characters Leetcode Solution175
556Build Array From Permutation Leetcode Solution175
55701 Matrix LeetCode Solution175
558K-th Distinct Element in an Array175
559Linked List Cycle II LeetCode Solution174
560Distribute Candies to People Leetcode Solution174
561Minimum Bracket Reversals174
562Group Multiple Occurrence of Array Elements Ordered by first Occurrence174
563Maximum sum rectangle in a 2D matrix174
564Convert Sorted Array to Binary Search Tree Leetcode Solution174
565Valid Anagrams174
566Shuffle an Array174
567Valid Sudoku174
568Change the Array into Permutation of Numbers From 1 to N174
569Largest Sum Contiguous Subarray174
570Check for Balanced Parentheses in an Expression174
571Arrange given numbers to form the biggest number174
572Hamming Distance173
573Island Perimeter Leetcode Solution173
574Rotate List Leetcode Solution173
575Gold Mine Problem172
576Combinations Leetcode Solution172
577Insert Interval Leetcode Solution172
5783Sum Closest LeetCode Solution172
579Unique Binary Search Trees172
580Integer to Roman172
581Count the number of nodes at given level in a tree using BFS172
582Decode Ways172
583Count all subsequences having product less than K172
584The Knapsack Problem172
585Assign Cookies Leetcode Solution172
586Trapping Rain Water LeetCode Solution172
587Find the smallest positive integer value that cannot be represented as sum of any subset of a given array172
588Rotate Image LeetCode Solution171
589Distance Between Bus Stops Leetcode Solution171
590Summary Ranges Leetcode Solution171
591Minimum Delete Operations to make all Elements of Array Same171
592Maximum Distance in Array171
593Maximum path sum in a triangle171
594Minimum number of distinct elements after removing m items171
595Shortest Path in a Grid with Obstacles Elimination LeetCode Solution171
596Maximum Number of Chocolates to be Distributed Equally Among k Students171
597Sieve of Eratosthenes170
598Rearrange a binary string as alternate x and y occurrences170
599LRU Cache LeetCode Solution170
600Minimum Knight Moves LeetCode Solution169
601Same Tree LeetCode Solution169
602Permutation in String Leetcode Solution169
603K Empty Slots LeetCode169
604Remove All Occurrences of a Substring LeetCode Solution169
605Stone Game LeetCode168
606XOR Operation in an Array Leetcode Solution168
607Find the Duplicate Number LeetCode Solution168
608How to check if two given sets are disjoint?168
609Defanging an IP Address Leetcode Solution168
610Replace Elements with Greatest Element on Right Side Leetcode Solution167
611Maximum Consecutive Numbers Present in an Array167
612Distance of nearest cell having 1 in a binary matrix167
613Painting Fence Algorithm167
614Segregate 0s and 1s in an Array167
615Applications of Breadth First Search and Depth First Search167
616Minimum Depth of Binary Tree Leetcode Solution167
617Tracking current Maximum Element in a Stack167
618Word Wrap Problem167
619Sort Array By Parity LeetCode Solution167
620Minimum number of subsets with distinct elements167
621Printing brackets in Matrix Chain Multiplication Problem167
622Coin Change Problem167
623Find if an Expression has Duplicate Parenthesis or Not167
624Frog Jump Leetcode Solution166
625Minimum insertions to form a palindrome with permutations allowed166
626License Key Formatting Leetcode Solution166
627Sort Characters By Frequency LeetCode Solution166
628Find Sum of all unique sub-array sum for a given array166
629House Robber166
630Word Pattern166
631Best Time to Buy and Sell Stock LeetCode Solution166
632Find minimum difference between any two elements166
633Smallest Good Base165
634Count Good Nodes in Binary Tree Leetcode Solution165
635Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions165
636Maximum difference between first and last indexes of an element in array165
637Check If It Is a Straight Line Leetcode Solution165
638Longest Substring with At Least K Repeating Characters LeetCode Solution165
639Isomorphic Strings165
640Sum of All Odd Length Subarrays Leetcode Solution165
641Merge Two Balanced Binary Search Trees164
642Wiggle Sort164
643Longest Substring with At Most K Distinct Characters LeetCode Solution164
644Find Maximum Level sum in Binary Tree164
645Queries for counts of array elements with values in given range164
646Letter Combinations of a Phone Number164
647Optimal Account Balancing LeetCode Solution164
648Iterative Method to find Height of Binary Tree164
649Kth Missing Positive Number Leetcode Solution164
650Minimum Cost to Hire K Workers164
651Employee Free Time LeetCode Solution164
652GCD Of Two Numbers163
653Find pairs with given sum such that elements of pair are in different rows163
654Reorganize String163
655Strobogrammatic Number LeetCode Solution163
656Valid Palindrome II Leetcode Solution163
657Number of Provinces Leetcode Solution163
658Valid Perfect Square Leetcode Solution163
659Binary Tree Zigzag Level Order Traversal LeetCode Solution163
660Power of Four Leetcode Solution163
661Maximum Number of Occurrences of a Substring Leetcode Solution163
662Best Time to Buy and Sell Stock with Cooldown Leetcode Solution163
663Partition Labels LeetCode Solution163
664Non-overlapping sum of two sets163
665Maximum Number of Coins You Can Get Leetcode Solution162
666Print the Fibonacci numbers in reverse order162
667Reverse a stack without using extra space in O(n)162
668Moving Average from Data Stream Leetcode Solution162
669Find the Distance Value Between Two Arrays Leetcode Solution162
670Edit Distance LeetCode Solution162
671Delete consecutive same words in a sequence161
672To Lower Case Leetcode Solution161
673Ugly Number Leetcode Solution161
674Permutation Sequence LeetCode Solution161
675Longest Increasing Subsequence161
676Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
677Valid Palindrome161
678Path With Maximum Minimum Value LeetCode Solution161
679Dynamic Programming Basics161
680Reducing Dishes LeetCode Solution160
681Reverse Only Letters LeetCode Solution160
682Convert an array to reduced form160
683Number of Dice Rolls With Target Sum LeetCode Solution160
684Find Leaves of Binary Tree LeetCode Solution160
685Maximum Product of Two Elements in an Array Leetcode Solution160
686Factorial Trailing Zeroes Leetcode Solution160
687Sort Array by Increasing Frequency Leetcode Solution160
688Longest Increasing Path in a Matrix LeetCode Solution160
689Check if a queue can be sorted into another queue using a stack160
690Check If Two String Arrays are Equivalent Leetcode Solution160
691Flipping an Image LeetCode Solution160
692K Empty Slots160
693Recover Binary Search Tree160
694Reservoir Sampling159
695Reversing a Queue using Recursion159
696Inorder Successor of a node in Binary Tree159
697Find whether an array is subset of another array159
698Form minimum number from given sequence159
699Find Largest d in Array such that a + b + c = d159
700BFS vs DFS for Binary Tree159
701Majority Element II Leetcode Solution159
702Partition Array Into Three Parts With Equal Sum Leetcode Solution159
703Subset Sum Leetcode159
704Unique Paths II Leetcode Solution159
705Binary Tree zigzag level order Traversal159
706String to Integer (atoi) LeetCode Solution159
707Restore IP Addresses Leetcode Solution159
708Bulb Switcher LeetCode Solution158
709Remove Invalid Parentheses Leetcode Solution158
710Construct BST from given Preorder Traversal158
711Robot Room Cleaner Leetcode Solution158
712Populating Next Right Pointers in Each Node158
713Increasing Decreasing String Leetcode Solution158
714How to Create Mergable Stack?158
715Delete Nth node from the end of the given linked list158
716Minimum Cost For Tickets Leetcode Solution158
717Convert a Number to Hexadecimal Leetcode Solution158
718Find the Smallest Divisor given a Threshold Leetcode Solution158
719Lucky Numbers in a Matrix Leetcode Solution158
720Perform String Shifts Leetcode157
721Keyboard Row Leetcode Solution157
722Sum of f(a[i], a[j]) over all pairs in an array of n integers157
723Merge Two Binary Trees LeetCode Solution157
724Add and Search Word – Data structure design LeetCode156
725Rank Transform of an Array Leetcode Solution156
726Find the node with minimum value in a Binary Search Tree156
727First Unique Character in a String LeetCode Solution155
728Hamming Distance Leetcode Solution155
729Sorted Linked List to Balanced BST155
730Decompress Run-Length Encoded List Leetcode Solution155
731Finding K closest element155
732Maximum Product of Three Numbers LeetCode Solution155
733Bubble sort using two Stacks155
734Student Attendance Record I Leetcode Solution155
735Best Meeting Point LeetCode Solution155
736Minimum Distance Between BST Nodes Leetcode Solution154
737Find unique character in a string154
738Minimum time required to rot all oranges154
739Invert Binary Tree LeetCode Solution154
740Maximum 69 Number Leetcode Solution154
741Diagonal Traversal of Binary Tree154
742Maximum Difference Between Increasing Elements LeetCode Solution154
743Tiling Problem154
744Split a String in Balanced Strings Leetcode Solution154
745Search a 2D Matrix II Leetcode Solution154
746String Compression LeetCode Solution154
747Generate all possible sorted arrays from alternate elements of two given sorted arrays154
748Evaluate Reverse Polish Notation LeetCode Solution154
749Symmetric Tree Leetcode Solution154
750Non-decreasing Array LeetCode Solution154
751Queue based approach for first non-repeating character in a stream154
752Word Pattern LeetCode Solution154
753Morris Traversal154
754Find Median from Data Stream LeetCode Solution154
755Binary Tree Maximum Path Sum LeetCode Solution154
756Minimize Maximum Pair Sum in Array LeetCode Solution153
757k-th missing element in increasing sequence which is not present in a given sequence153
758Check If Array Pairs Are Divisible by k LeetCode Solution153
759Kth ancestor of a node in binary tree153
760Maximum Depth of N-ary Tree Leetcode Solution153
761Minimum Height Trees153
762Merge K Sorted Linked Lists153
763Special Array With X Elements Greater Than or Equal X Leetcode Solution153
764Largest rectangular sub-matrix whose sum is 0153
765Largest subarray with equal number of 0s and 1s153
766Deletion in a Binary Tree153
767Stack Permutations (Check if an array is stack permutation of other)153
768Elements to be added so that all elements of a range are present in array153
769Snakes and Ladders LeetCode Solution153
770Find the largest multiple of 3153
771Find All Duplicates in an Array LeetCode Solution153
772Binomial Coefficient153
773Numbers with prime frequencies greater than or equal to k153
774Maximum Length of a Concatenated String with Unique Characters Leetcode Solution152
775Number of Islands II LeetCode Solution152
776Count quadruples from four sorted arrays whose sum is equal to a given value x152
777Longest Span with same Sum in two Binary arrays152
778Minimum number of jumps to reach end152
779Find if Path Exists in Graph Leetcode Solution152
780Largest Rectangle in Histogram LeetCode Solution152
781Find Pair with Greatest Product in Array152
782Minimum swaps to make sequences increasing152
783Find Maximum Depth of Nested Parenthesis in a String152
784Search in a Binary Search Tree Leetcode Solution152
785N-Queens LeetCode Solution152
786Jump Game152
787Transpose Graph152
788Minimum Jumps to Reach Home LeetCode Solution151
789Remove brackets from an algebraic string containing + and – operators151
790Final Prices With a Special Discount in a Shop Leetcode Solution151
791Linked List Cycle151
792Base 7 Leetcode Solution151
793Number of NGEs to the Right151
794Minimum Time Visiting All Points Leetcode Solution151
795Remove Duplicates from Sorted List LeetCode Solution151
796Remove Nth Node From End of List Leetcode Solution151
797Crawler Log Folder Leetcode Solution151
798Program for Bridge and Torch problem151
799Race Car LeetCode Solution151
800Check if Two Expressions With Brackets are Same150
801Nearest Exit from Entrance in Maze LeetCode Solution150
802Number Complement Leetcode Solution150
803Partition to K Equal Sum Subsets Leetcode Solution150
804Relative Ranks Leetcode Solution150
805A Space Optimized DP solution for 0-1 Knapsack Problem150
806Interval Tree150
807String comparison containing wildcards150
808Remove Duplicates from Sorted List II150
809Maximum Profit in Job Scheduling Leetcode Solution150
810Iterative Preorder Traversal150
811Nested List Weight Sum II LeetCode Solution149
812Valid Parentheses Leetcode Solution149
813Print a Binary Tree in Vertical Order149
814Can Place Flowers LeetCode Solution149
815One Edit Distance LeetCode Solution149
816Reorder Data in Log Files LeetCode Solution149
817Get Maximum in Generated Array Leetcode Solution149
818Growable array based stack149
819Check for Palindrome after every character replacement Query149
820Total Numbers With no Repeated Digits in a Range149
821Alien Dictionary LeetCode Solution149
822Find the subarray with least average149
823Merge Sorted Array LeetCode Solution149
824Find all triplets with zero sum149
825Convert BST to Min Heap149
826Maximum size subarray sum equals k149
827Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution148
828Find All Possible Recipes from Given Supplies LeetCode Solution148
829Check if a given array can represent Preorder Traversal of Binary Search Tree148
830Count items common to both the lists but with different prices148
831Sort Colors148
832Path with maximum average value148
833Sort Array By Parity II Leetcode Solution148
834Find the Only Repetitive Element Between 1 to N-1148
835Partition List Leetcode Solution148
836Valid Number148
837Sort an array according to the order defined by another array148
838Regular Expression Matching148
839Level order Traversal in Spiral Form147
840Design a Stack With Increment Operation Leetcode Solution147
841Maximum Nesting Depth of the Parentheses Leetcode Solution147
842Count Distinct Elements in Every Window of Size K147
843Subset with sum divisible by m147
844Subarray Product Less Than K LeetCode Solution147
845Friends Pairing Problem147
846Clone Graph LeetCode Solution147
847Subsequence of Size K With the Largest Even Sum LeetCode Solution147
848Form Minimum Number From Given Sequence147
849Priority Queue using doubly linked list147
850Check whether a given Binary Tree is Complete or not147
851Top K Frequent Words LeetCode Solution147
852Brick Wall LeetCode Solution147
853Guess Number Higher or Lower LeetCode Solution146
854Given an Array of Pairs Find all Symmetric Pairs in it146
855Circular Queue146
856Longest Subarray Having Count of 1s One More than Count of 0s146
857Brightest Position on Street LeetCode Solution146
858Matrix Chain Multiplication146
859Count Negative Numbers in a Sorted Matrix LeetCode Solution146
860Last Stone Weight II LeetCode Solution146
861Binary Search Tree Search and Insertion146
862Course Schedule II – LeetCode146
863Repeated Substring Pattern LeetCode Solution146
864K’th Largest Element in BST when modification to BST is not allowed146
865Insert into a Binary Search Tree Leetcode Solution146
866Minimum Number of Taps to Open to Water a Garden LeetCode Solution146
867Distinct adjacent elements in an array146
868Union and Intersection of two Linked Lists145
869Three way partitioning of an array around a given range145
870Spiral Matrix II Leetcode Solution145
871Sum of nearest smaller and greater number145
872An Interesting Method to generate Binary Numbers from 1 to n145
873GCDs of given index ranges in an array145
874Tree Traversal (Preorder, Inorder & Postorder)145
875Sequences of given length where every element is more than or equal to twice of previous145
876Daily Temperatures Leetcode Solution145
877Minimum Swaps to Make Strings Equal Leetcode Solution145
878Sorted Array to Balanced BST145
879Robot Bounded In Circle LeetCode Solution144
880Delete And Earn144
881Number of Days Between Two Dates LeetCode Solution144
882Permutation Coefficient144
883Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution144
884Check if an Array is Stack Sortable144
885Minimum sum of multiplications of n numbers144
886Design Browser History LeetCode Solution144
887Find Maximum Sum Possible Equal Sum of Three Stacks144
888Minimum Sum Path in a Triangle144
889Count ways to reach the nth stair using step 1, 2 or 3143
890LCS (Longest Common Subsequence) of three strings143
891Check if the given array can represent Level Order Traversal of Binary Search Tree143
892Lemonade Change Leetcode Solution143
893Destination City Leetcode Solution143
894Water Bottles Leetcode Solution143
895Find distance between two nodes of a Binary Tree143
8964Sum143
897Missing Element in Sorted Array LeetCode Solution143
898Guess Number Higher or Lower II143
899Rearrange Spaces Between Words Leetcode Solution143
900Shortest Word Distance Leetcode Solution142
901Balanced Expression with Replacement142
902Time Based Key-Value Store LeetCode Solution142
903Special Positions in a Binary Matrix Leetcode Solution142
904Range sum queries without updates142
905Maximum Score After Splitting a String Leetcode Solution142
906Set Matrix Zeroes Leetcode Solution142
907Spiral Matrix III LeetCode Solution142
908Palindrome Partitioning Leetcode Solution142
909Queries for GCD of all numbers of an array except elements in a given range142
910Identify and Mark Unmatched Parenthesis in an Expression142
911A program to check if a binary tree is BST or not142
912Least Number of Unique Integers after K Removals Leetcode Solution142
913BFS for Disconnected Graph141
914All Unique Triplets that Sum up to a Given Value141
915Strongly Connected Component141
916Diagonal Traversal LeetCode Solution141
917Number of Distinct Islands Leetcode Solution141
918Construct Complete Binary Tree from its Linked List Representation141
919Insert Delete GetRandom141
920Remove Duplicates from Sorted List II LeetCode Solution141
921Convert Sorted List to Binary Search Tree141
922Trim a Binary Search Tree141
923Alien Dictionary141
924Construct BST from its given Level Order Traversal141
925Rearrange an Array Such that arr[i] is equal to i141
926Lexicographical Numbers Leetcode Solution140
927Diagonal Traverse LeetCode Solution140
928Range LCM Queries140
929Reverse Nodes in K-Group140
930Merging Intervals140
931Collect maximum points in a grid using two traversals140
932Count Subarrays with Same Even and Odd Elements140
933Infix to Postfix140
934Find all permuted rows of a given row in a matrix140
935Find Common Characters Leetcode Solution140
936Intersection of Two Linked Lists LeetCode Solution140
937Count Submatrices With All Ones LeetCode Solution140
938Maximum Frequency Stack Leetcode Solution140
939Construct the Rectangle Leetcode Solution140
940Difference Array | Range update query in O(1)140
941Longest Palindromic Subsequence140
942Queue using Stacks140
943Iterative Postorder Traversal Using Two Stacks140
944Number of Equivalent Domino Pairs Leetcode Solution139
945Word Break139
9463 Sum139
947Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i139
948Count pair with Given Sum139
949Can Make Arithmetic Progression From Sequence Leetcode Solution139
950Check if stack elements are pairwise consecutive139
951Merge Two Sorted Lists Leetcode139
952Minimum Height Trees LeetCode Solution138
953Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space138
954Vertical sum in a given binary tree138
955Print Fibonacci sequence using 2 variables138
956Binary Tree Longest Consecutive Sequence LeetCode Solution138
957Analyze User Website Visit Pattern LeetCode Solution138
958Averages of Levels in Binary Tree138
959Find the Difference Leetcode Solution138
960Stone Game II Leetcode138
961Longest Nice Substring LeetCode Solution137
962Product of Array Except Self LeetCode Solution137
963Palindrome Partitioning137
964Three Consecutive Odds Leetcode Solution137
965Maximize Sum of Array after K Negations Leetcode Solution137
966Largest area rectangular sub-matrix with equal number of 1’s and 0’s136
967Symmetric Tree136
968Maximum Subarray Sum Excluding Certain Elements136
969Create Maximum Number136
970Find postorder traversal of BST from preorder traversal136
971Level order traversal using two Queues136
972Largest divisible pairs subset136
973Count Primes in Ranges136
974Boolean Parenthesization Problem136
975Dividing Array into Pairs With Sum Divisible by K136
976Minesweeper LeetCode Solution136
977Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution136
978Sliding Window Maximum136
979K Closest Points to Origin Leetcode Solution136
980Height of a generic tree from parent array136
981Kth Smallest Element in a BST Leetcode Solution136
982Split Array Into Consecutive Subsequences136
983Binary array after M range toggle operations136
984Check if any two intervals overlap among a given set of intervals136
985Maximum Product of Indexes of Next Greater on Left and Right136
986Asteroid Collision LeetCode Solution136
987Find Duplicate Subtrees135
988Largest Substring Between Two Equal Characters Leetcode Solution135
989Median of Two Sorted Arrays135
990Next Greater Element III LeetCode Solution135
991Maximum subsequence sum such that no three are consecutive135
992Breadth First Search (BFS) for a Graph135
993Number Of Longest Increasing Subsequence135
994Find Maximum of Minimum for Every Window Size in a Given Array135
995The Painter’s Partition Problem135
996Maximum weight transformation of a given string135
997Graph Valid Tree LeetCode Solution135
998Pattern Occurrences using Stack135
999Friends Of Appropriate Ages LeetCode Solution135
1000Segment Tree135
1001Double the first element and move zero to end135
1002Level Order Traversal of Binary Tree135
1003First missing positive135
1004Depth First Search (DFS) for a Graph134
1005Decrypt String from Alphabet to Integer Mapping Leetcode Solution134
1006The Maze III LeetCode Solution134
1007Length of Longest Fibonacci Subsequence134
1008Binary Search Tree Delete Operation134
1009Maximum Length of Repeated Subarray134
1010Maximum Product Subarray134
1011Build an Array With Stack Operations Leetcode Solution134
1012Newman-Conway Sequence134
1013Unique Paths II134
1014String Matching in an Array Leetcode Solution134
1015Find the First Circular Tour that visits all the Petrol Pumps134
1016Valid Boomerang Leetcode Solution134
1017Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’134
1018Morris Inorder Traversal134
1019Sign of the Product of an Array LeetCode Solution133
1020Boundary Traversal of binary tree133
1021Design Hit Counter LeetCode Solution133
1022Kill Process LeetCode Solution133
1023Rearrange array such that even positioned are greater than odd133
1024Maximum Number of Ways to Partition an Array LeetCode Solution133
1025My Calendar I LeetCode Solution133
1026Shortest Completing Word Leetcode Solution133
1027Construction of Longest Increasing Subsequence (N log N)133
1028Count subarrays where second highest lie before highest133
1029Serialize and Deserialize Binary Tree133
1030K maximum sums of overlapping contiguous sub-arrays133
1031Partition Equal Subset Sum133
1032Climbing stairs133
1033Longest subsequence such that difference between adjacents is one132
1034Maximum Sum of 3 Non-Overlapping Subarrays132
1035Balanced Binary Tree132
1036Insertion in a Binary Tree132
1037Scramble String LeetCode Solution132
1038Make The String Great Leetcode Solution132
1039Compute nCr % p132
1040Construct Binary Tree from given Parent Array representation132
1041Find number of pairs in an array such that their XOR is 0132
1042Super Ugly Number132
1043Binary Tree Right Side View LeetCode Solution131
1044Invalid Transactions LeetCode Solution131
1045Validate Binary Search Tree131
1046Custom Sort String Leetcode Solution131
1047Move all negative elements to end in order with extra space allowed131
1048Recover Binary Search Tree Leetcode Solution131
1049Advantages of BST over Hash Table131
1050Binary Search Tree131
1051Add two numbers131
1052Largest Number Leetcode Solution131
1053Ugly Numbers131
1054Maximum difference between frequency of two elements such that element having greater frequency is also greater130
1055Bitwise AND of Numbers Range LeetCode Solution130
1056Iterative Depth First Traversal of Graph130
1057Minimum Index Sum of Two Lists130
1058Ugly Number II LeetCode Solution130
1059Path Sum II LeetCode Solution130
1060Implement Trie (Prefix Tree) Leetcode Solution130
1061Employee Importance LeetCode Solution130
1062Generate Parentheses Leetcode Solution130
1063Available Captures for Rook Leetcode Solution129
1064Kth Smallest Element in a Sorted Matrix LeetCode Solution129
1065Remove Duplicates from Sorted Array II Leetcode Solution129
1066Maximum length subsequence with difference between adjacent elements as either 0 or 1129
1067Regular Expression Matching Regular Expression Matching LeetCode Solution129
1068Minimum Size Subarray Sum129
1069Largest BST Subtree LeetCode Solution129
1070Serialize and Deserialize Binary Tree LeetCode Solution129
1071Number of palindromic paths in a matrix129
1072Find Peak Element129
1073Find whether a subarray is in form of a mountain or not129
1074Count pairs from two sorted arrays whose sum is equal to a given value x129
1075Count minimum steps to get the given desired array129
1076Combination Sum IV LeetCode Solution128
1077Remove duplicates from sorted array128
1078Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution128
1079Find a Peak Element II LeetCode Solution128
1080Longest Bitonic Subsequence128
1081Defanging an IP Address LeetCode Solution128
1082Populating Next Right Pointers in Each Node Leetcode Solution128
1083Increasing Triplet Subsequence LeetCode Solution128
1084Maximize Distance to Closest Person LeetCode Solution128
1085Number of Students Doing Homework at a Given Time Leetcode Solution128
1086Lowest Common Ancestor128
1087Binary Tree Data Structure128
1088Clone a Binary Tree with Random Pointers128
1089Types of Binary Tree127
1090Constant time range add operation on an array127
1091Find the minimum distance between two numbers127
1092Number of Closed Islands Leetcode Solution127
1093Print all triplets in sorted array that form AP127
1094Remove Palindromic Subsequences Leetcode Solution127
1095Number of siblings of a given Node in n-ary Tree127
1096Search in Sorted Rotated Array127
1097Distinct Subsequences127
1098Root to Leaf path with target sum Leetcode Solutions127
1099Find maximum difference between nearest left and right smaller elements126
1100Find Smallest Range Containing Elements from k Lists126
1101Path Sum126
1102Next Permutation Leetcode Solution126
1103Smallest Common Region Leetcode Solution126
1104Find Three Element From Different Three Arrays Such That a + b + c = sum126
1105Rearrange array such that even index elements are smaller and odd index elements are greater126
1106Divisible Pairs Counting126
1107Day of the Year Leetcode Solution126
1108Print Next Greater Number of Q queries126
1109Subarrays with K Different Integers Leetcode Solution125
1110Kth Smallest Product of Two Sorted Arrays LeetCode Solution125
1111Minimum Score Triangulation of Polygon Leetcode Solution125
1112Third Maximum Number Leetcode Solution125
1113Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution125
1114Cells with Odd Values in a Matrix LeetCode Solution125
1115Write Code to Determine if Two Trees are Identical125
1116Bottom View of a Binary Tree124
1117Minimum Absolute Difference in BST Leetcode Solution124
1118Consecutive Characters LeetCode Solution124
1119Moser-de Bruijn Sequence124
1120Mean of Array After Removing Some Elements Leetcode Solution124
1121Topological Sorting124
1122Count Largest Group Leetcode Solution124
1123Print Right View of a Binary Tree124
1124Level of Each node in a Tree from source node124
1125Cutting a Rod123
1126Prime Palindrome LeetCode Solution123
1127Subset Sum Problem in O(sum) space123
1128Diameter of N-Ary Tree LeetCode Solution123
1129Maximum Product Subarray123
1130Products of ranges in an array123
1131Convert BST into a Min-Heap without using array123
1132Longest Subarray of 1’s After Deleting One Element LeetCode Solution123
1133Closest Binary Search Tree Value Leetcode Solution122
1134Reformat The String Leetcode Solution122
1135Search an Element in Sorted Rotated Array122
1136Thousand Separator Leetcode Solution122
1137Queries for Number of Distinct Elements in a Subarray122
1138Maximum Binary Tree122
1139Check Array Formation Through Concatenation Leetcode Solution122
1140Palindrome Permutation LeetCode Solution122
1141Search Insert Position122
1142Iterative method to find ancestors of a given binary tree121
1143Construct K Palindrome Strings LeetCode Solution121
1144Minimum sum of squares of character counts in a given string after removing k characters121
1145Golomb sequence121
1146Bus Routes Leetcode Solution121
1147Minimum Sideway Jumps LeetCode Solution121
1148Valid Tic-Tac-Toe State LeetCode Solution121
1149Find a sorted subsequence of size 3 in linear time121
1150Print modified array after executing the commands of addition and subtraction121
1151Possible Bipartition LeetCode Solution120
1152Swap Nodes In Pairs120
1153Kth Smallest Number in Multiplication Table Leetcode Solution120
1154Sum of Even Numbers After Queries120
1155Factorial Trailing Zeroes LeetCode Solution120
1156Find maximum length Snake sequence120
1157Transform a BST to Greater sum Tree120
1158Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution120
1159Merge two BSTs with limited extra space120
1160Longest Increasing Consecutive Subsequence120
1161Binary Tree to Binary Search Tree Conversion120
1162Red-Black Tree Introduction119
1163Maximum Product of Splitted Binary Tree LeetCode Solution119
1164Swapping Nodes in a Linked List Leetcode Solution119
1165Maximize sum of consecutive differences in a circular array119
1166Find the smallest binary digit multiple of given number119
1167Longest Repeated Subsequence119
1168Palindromic Substrings Leetcode Solution119
1169Decrease Elements To Make Array Zigzag LeetCode Solution118
1170Graph and its representation118
1171Minimum Cost to Move Chips to The Same Position LeetCode Solution118
1172Rotate Array118
1173Decision Tree118
1174Minimum Moves to Equal Array Elements LeetCode Solution118
1175K’th Largest element in BST using constant extra space118
1176Count even length binary sequences with same sum of first and second half bits118
1177Search Suggestions System LeetCode Solution118
1178Find Largest Value in Each Tree Row LeetCode Solution118
1179Maximum sum bitonic subarray118
1180Compare Strings by Frequency of the Smallest Character Leetcode Solution118
1181Delete Nodes and Return Forest Leetcode Solution118
1182Matchsticks to Square Leetcode Solution117
1183Contiguous Array LeetCode Solution117
1184Number of Orders in the Backlog Leetcode Solution117
1185Priority Queue117
1186Count Pairs Whose Products Exist in Array117
1187How to print maximum number of A’s using given four keys117
1188Web Crawler LeetCode Solution117
1189Reverse a Path in BST using Queue117
1190Valid Triangle Number117
1191Closest Leaf in a Binary Tree LeetCode Solution116
1192Lowest Common Ancestor in Binary Search Tree116
1193Maximum sum of pairs with specific difference116
1194Maximum number of segments of lengths a, b and c116
1195Kth Smallest Element in a BST116
1196Guess The Word115
1197Given a binary tree, how do you remove all the half nodes?115
1198Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution115
1199Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution115
1200Concatenation of Array LeetCode Solution115
1201First Bad Version115
1202Moving Stones Until Consecutive Leetcode Solution115
1203Convert Sorted Array to Binary Search Tree LeetCode Solutions114
1204Array Queries for multiply replacements and product114
1205Integer Break LeetCode Solution114
1206Sum of Left Leaves LeetCode Solution114
1207Divide Two Integers Leetcode Solution114
1208Queue Reconstruction by Height114
1209Lowest Common Ancestor of a Binary Tree Leetcode Solution114
1210Reformat Date LeetCode Solution113
1211Maximum Depth Of Binary Tree113
1212Perfect Squares LeetCode Solution113
1213Range Sum Query using Sparse Table113
1214Largest Plus Sign Leetcode Solution113
1215Power of Two113
1216Replace two consecutive equal values with one greater113
1217Champagne Tower LeetCode Solution113
1218Minimum Swaps To Make Sequences Increasing LeetCode Solution113
1219Flatten 2D Vector LeetCode Solution112
1220Print modified array after multiple array range increment operations112
1221The kth Factor of n Leetcode Solution112
1222LRU Cache Leetcode Solution112
1223Write a function to get the intersection point of two Linked Lists112
1224Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution112
1225Longest Common Prefix Using Word by Word Matching112
1226New 21 Game112
1227Valid Perfect Square LeetCode Solution112
1228Path Crossing Leetcode Solution112
1229Merge Sort112
1230Arithmetic Slices II – Subsequence LeetCode Solution112
1231Symmetric Tree LeetCode Solution Leetcode Solution111
1232Range Queries for Longest Correct Bracket Subsequence111
1233Sliding Window Median Leetcode Solution111
1234Maximize Elements Using Another Array111
1235Parallel Courses II LeetCode Solution111
1236Find Minimum in Rotated Sorted Array II LeetCode Solution111
1237Maximum sum of a path in a Right Number Triangle111
1238Mean of range in array111
1239Bold Words in String LeetCode Solution111
1240Check Completeness of a Binary Tree LeetCode Solution111
1241Print n terms of Newman-Conway Sequence111
1242Graph Cloning110
1243Check if all levels of two Binary Tree are anagrams or not110
1244Maximum Product Subarray110
1245Check if each internal node of a BST has exactly one child110
1246Design Skiplist LeetCode Solution110
1247Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1248Queries on Probability of Even or Odd Number in given Ranges110
1249Maximum Array from Two given Arrays Keeping Order Same109
1250Missing Number109
1251BST to a Tree with Sum of all Smaller Keys109
1252Check for Identical BSTs without building the trees109
1253Count Subsets Having Distinct Even Numbers109
1254Count and Toggle Queries on a Binary Array108
1255Smallest Range II Leetcode Solution108
1256Image Overlap LeetCode Solution108
1257Find minimum number of merge operations to make an array palindrome108
1258Min Cost Climbing Stairs LeetCode Solution107
1259Number of elements less than or equal to a given number in a given subarray107
1260Contiguous Array107
1261Merge k Sorted Lists Leetcode Solution107
1262Minimum Remove to Make Valid Parentheses LeetCode Solution106
1263Palindrome Partitioning106
1264Check If a String Can Break Another String Leetcode Solution106
1265Print Ancestors of a Given Binary Tree Node Without Recursion106
1266Find k-th smallest element in BST (Order Statistics in BST)106
1267Excel Sheet Column Title LeetCode Solution106
1268Next greater element105
1269Peeking Iterator LeetCode Solution105
1270Verify Preorder Serialization of a Binary Tree105
1271Check if two nodes are on the same path in a Tree105
1272Different Ways to Add Parentheses Leetcode Solution105
1273Merge Sorted Array103
1274Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1275Orderly Queue LeetCode Solution103
1276Newman–Shanks–Williams prime102
1277Check in binary array the number represented by a subarray is odd or even102
1278Longest Substring Without Repeating Characters Leetcode Solution102
1279Koko Eating Bananas LeetCode Solution101
1280Largest Submatrix With Rearrangements LeetCode Solution101
1281Check if X can give change to every person in the Queue101
1282Arranging Coins Leetcode Solution100
1283Encoded String With Shortest Length LeetCode Solution99
1284Find maximum average subarray of k length98
1285Maximum Sum Increasing Subsequence98
1286Array Nesting Leetcode Solution97
1287Minimum Total Space Wasted With K Resizing Operations LeetCode Solution97
1288Minimum Number of People to Teach LeetCode Solution97
1289Range Minimum Query (Square Root Decomposition and Sparse Table)97
1290Queries for Decimal Values of Subarrays of a Binary Array97
1291Number of indexes with equal elements in given range96
1292Maximum product of an increasing subsequence96
1293Find the Winner of the Circular Game LeetCode Solution95
1294Continuous Subarray Sum LeetCode Solution94
1295Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1296Check given array of size n can represent BST of n levels or not94
1297Binary Tree to Binary Search Tree Conversion using STL set94
1298Convert to Base -2 LeetCode Solution94
1299Random Pick Index LeetCode Solution94
1300Convert a BST to a Binary Tree such that sum of all greater keys is added to every key94
1301Queries on XOR of greatest odd divisor of the range93
1302Add Two Numbers II Leetcode Solution93
1303Jump Game IV LeetCode Solution93
1304Insert Delete GetRandom O(1) Leetcode Solution93
1305Reach a Number LeetCode Solution92
1306Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution91
1307Palindrome Number LeetCode Solution91
1308Vertical Order Traversal of Binary Tree LeetCode Solution90
1309Design Underground System Leetcode Solution89
1310Print Maximum Length Chain of Pairs86
1311Design A Leaderboard Leetcode Solution85
1312Detect Capital Leetcode Solution83
1313Substring with Concatenation of All Words Leetcode Solution82
1314Minimum Swaps to Group All 1’s Together Leetcode Solution79
1315Top K Frequent Elements LeetCode Solution79
1316Minimum Path Sum Leetcode Solution78
1317Count Sub Islands LeetCode Solution78
1318Best Meeting Point LeetCode Solution76
1319Shifting Letters LeetCode Solution74
1320Decode String Leetcode Solution74
1321Longest Common Subsequence LeetCode Solution74
1322Binary Tree Inorder Traversal LeetCode Solution73
1323Find the Town Judge LeetCode Solution73
1324Odd Even Linked List Leetcode Solution73
1325Maximum Population Year LeetCode Solution71
1326Sum Root to Leaf Numbers LeetCode Solution71
1327Shortest Unsorted Continuous Subarray LeetCode Solution71
1328Find the Town Judge LeetCode Solution70
1329Design Add and Search Words Data Structure LeetCode Solution68
1330Rectangle Overlap LeetCode Solution67
1331Maximum Population Year LeetCode Solution66
1332Score of Parenthesis LeetCode Solution65
1333Range Sum Query 2D – Immutable LeetCode Solution64
1334Flatten Binary Tree to Linked List LeetCode Solution63
1335Insert into a Sorted Circular Linked List LeetCode Solution63
1336Stone Game IV LeetCode Solution62
1337Is Graph Bipartite? LeetCode Solution62
1338Reveal Cards In Increasing Order Leetcode Solution61
1339Valid Triangle Number LeetCode Solution60
1340Divide Chocolate LeetCode Solution51
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution47
1342Range Sum of BST LeetCode Solution45
1343Reverse Integer Leetcode Solution41
1344Sort Colors LeetCode Solution40
1345Find K Closest Elements LeetCode Solution38
1346Excel Sheet Column Number LeetCode Solution36
1347Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution35
1348Rotate String LeetCode Solution35
1349Maximum Size Subarray Sum Equals k Leetcode Solution17
1350H-Index Leetcode Solution15
1351High Five LeetCode Solution13
Translate »
1