Sum Root to Leaf Numbers LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon Apple Bloomberg Facebook Google Microsoft Paytm
Binary Tree Depth First Search TreeViews 67

Problem Statement

Sum Root to Leaf Numbers LeetCode Solution says – You are given the root of a binary tree containing digits from 0 to 9 only.

Each root-to-leaf path in the tree represents a number.

  • For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.

Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.

leaf node is a node with no children.

Sum Root to Leaf Numbers LeetCode SolutionPin

Input: root = [1,2,3]
Output: 25
Explanation:
The root-to-leaf path 1->2 represents the number 12.
The root-to-leaf path 1->3 represents the number 13.
Therefore, sum = 12 + 13 = 25.

Sum Root to Leaf Numbers LeetCode SolutionPin

Input: root = [4,9,0,5,1]
Output: 1026
Explanation:
The root-to-leaf path 4->9->5 represents the number 495.
The root-to-leaf path 4->9->1 represents the number 491.
The root-to-leaf path 4->0 represents the number 40.
Therefore, sum = 495 + 491 + 40 = 1026.

Explanation

We recursively go to each node and check if it is null or not
a- If it is a null node, then we skip it and move to the next
b- If it is not a null node, we multiply the current by 10, and add the node value

We repeat the same procedure for all the nodes present, to get the final answer and return it.

Code

Java Solution:

class Solution {
    
    public int sumNumbers(TreeNode root) {
        
        return solve(root, 0);
    }
    
    int solve(TreeNode root, int curr){
        
        if(root == null){
            return 0;
        }
        
        curr = curr*10 + root.val;
        
        if(root.left == null && root.right == null){
            //leaf node
            return curr ;
        }
        
        return solve(root.left, curr) + solve(root.right, curr);
    }
}

 

C++ Solution

class Solution {
public:
    
    void solve(TreeNode* root, int ans, int &fans)
    {
        if(!root)
            return;
        
        if(!root->left && !root->right)
        {
            ans = ans *10 + root->val;
            fans +=ans;
            return;
        }
        
        ans = ans *10 + root->val;
        solve(root->left, ans, fans);
        solve(root->right, ans,fans);
    }
    int sumNumbers(TreeNode* root) 
    {
        int ans =0;
        int fans = 0;
        solve(root, ans, fans);
        return fans;
    }
};

Complexity Analysis of Sum Root to Leaf Numbers Leetcode Solution:

Time complexity O(N) where N is number of Nodes

Space complexity O(H) where H is the height of the tree

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2815
2Java program to find the number of Nodes in a Binary Tree2498
3Reverse a string without affecting special characters2454
4Delete a node of a linked list at given position1973
5Palindrome using Recursion1776
6Insert nodes in a linked list in a sorted way (Ascending Order)1658
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1627
9Write a program to print all permutations of a given string1600
10Find Minimum Distance Between Two Numbers in an Array1470
11Create a Doubly Linked List1443
12Quick Sort1415
13Reverse an Array1408
14Smallest window in a string containing all characters of another string1393
15Find a Triplet That Sum to a Given Value1355
16Recursively remove all adjacent duplicates1351
17First Repeating Element1334
18Arrange Even and Odd number such that Odd comes after Even1318
19Sum of numbers in String1312
20Smallest Positive Number Missing in an Unsorted Array1277
21Check if the Elements of an Array are Consecutive1250
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1212
25Subarray with Given Sum1209
26Print all Possible Combinations of R Elements in a given Array of size N1201
27Recursive function to do substring search1195
28Find the Maximum Repeating Number in Array1149
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1100
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1065
34Find Leaders in an Array1058
35Swap nodes in the linked list1032
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II991
38Find the second most frequent character983
39Given a string find its first non-repeating character963
40Find Triplet in Array With a Given Sum963
41Given a sorted array and a number x, find the pair in array whose sum is closest to x950
42Total number of occurrences of a given item in the linked list950
43A Program to check if strings are rotations of each other or not942
44Print all possible words from phone digits928
45Find the Missing Number922
46Rearrange Positive and Negative Numbers Alternatively in Array916
47Longest Palindromic Substring903
48Segregate even and odd nodes in a linked list881
49Print Longest common subsequence877
50Union and Intersection of Two Linked Lists870
51Transform one string to another using minimum number of given operations862
52Check rearranged string can form a palindrome842
53Rearrange given Array in Maximum Minimum Form841
54Count Possible Triangles818
55Iterative Implementation of Quick Sort813
56Multiplication of Two Matrices796
57Check if the linked list is palindrome794
58Rotate a Linked List788
59Count of Triplets With Sum Less than Given Value788
60Stock Buy Sell to Maximize Profit786
61Tug of War758
62Concatenation of two strings757
63Count Number of Substrings with K Distinct Character’s752
64Print all duplicates in the input string748
65Find Nearest Greater and Smaller Element743
66Find Pythagorean Triplets from Array736
67The Celebrity Problem735
68Reverse String Without Temporary Variable729
69Find all Common Elements in Given Three Sorted Arrays727
70Remove ‘b’ and ‘ac’ from a given string726
71Remove all duplicates in an unsorted linked list708
72Find the Row with Maximum Number of 1’s702
73Find the Peak Element from an Array696
74Find the subarray whose sum is equal to a given number X693
75Remove Minimum Characters so that Two Strings Become Anagrams685
76Insertion Sort685
77Find Smallest Missing Number in a Sorted Array684
78A Product Array Puzzle681
79Addition of Two Matrices681
80Implement Two Stacks in an Array675
81Generate all Binary Strings Without Consecutive 1’s671
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II658
84Lexicographic rank of string652
85Multiplication of Previous and Next642
86Check if Two given Matrices are Identical641
87Subtraction of Two Matrices631
88Merge K Sorted Arrays and Print Sorted Output631
89Move All the Zeros to the End of the Given Array626
90Divide a string in N equal parts621
91Form Minimum Number from Given Sequence of D’s and I’s620
92Online Algorithm for Checking Palindrome in a Stream620
93Check whether two strings are anagram of each other613
94Maximum Circular Subarray Sum607
95Remove recurring digits in a given number607
96Sort a linked list that is sorted alternating ascending and descending607
97Sort a stack using a temporary stack604
98Find the Minimum Element in a Sorted and Rotated Array603
99Move last element of the Linked List at first place601
100Subarray and Subsequence598
101First Circular Tour to Visit all the Petrol Bunks596
102Largest Subarray with Equal Number of 0’s and 1’s595
103Compare two strings(linked lists)591
104Flattening a linked list590
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String582
107Elements Appear more than N/K times in Array580
108Majority Element573
109Minimum insertions to form a shortest palindrome571
110Run length encoding571
111Print all permutations with repetition570
112Palindromes in a given range569
113Pangram Checking565
114Merge a linked list into another at alternate positions563
115Rearrange a given linked list in-place562
116Minimum Characters to be Added at Front to Make String Palindrome561
117Remove all duplicates in a sorted linked list561
118Minimum number of Merge Operations to make an Array Palindrome557
119Most repeating character in a string556
120Rotate string to get lexicographically minimum string556
121Repeated Subsequence of Length Two or More553
122Print all anagrams together in a sequence of words549
123Reorder an Array According to the Given Indexes549
124Pancake Sorting Problem540
125Clone a Linked List with next and random pointer536
126Merge Overlapping Intervals II536
127Two Sum Leetcode Solution533
128Size of The Subarray With Maximum Sum527
129Transpose of a Matrix522
130Removing Spaces from a String using stringstream518
131Remove Extra Spaces from a String518
132Check if a given string is a rotation of a palindrome516
133Smallest Palindrome after Replacement516
134Partition Problem514
135Remove duplicates from a string513
136Maximum Sum Increasing Subsequence511
137Longest Palindrome can be Formed by Removing or Rearranging Characters511
138Check whether Strings are K Distance Apart or Not501
139Generate all Binary Strings from Given Pattern499
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized498
141Insert Node in the Sorted Linked List497
142Length of Longest valid Substring497
1433Sum Leetcode Solution496
144Delete Last Occurrence495
145Check if Two given Strings are Isomorphic to each other491
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String481
148Given string is interleaving of two other strings or not479
149Count Minimum Steps to Get the given Array478
150Merge sort better than quick sort for linked lists474
151Number of Smaller Elements on Right Side472
152Find Pair with Given Difference471
153Check if all Rows of a Matrix are Circular Rotations of Each Other469
154Check length of a String is Equal to the Number Appended at its Last469
155Find nth node of the Linked list from the end466
156Longest Common Prefix using Divide and Conquer466
157Find a Fixed Point in a Given Array460
158Sort 0s 1s and 2s in an Array457
159Print all interleavings of given two strings454
160Compare Two Version Numbers454
161Merge two sorted linked lists such that merged list is in reverse order453
162Find the Subarray of given length with Least Average452
163Reorder Array Using Given Indexes450
164Split linked list using alternate nodes449
165Reverse words in a given string448
166Print Reverse of a string (Recursion)446
167Median of Two Sorted Arrays LeetCode Solution445
168Print string of odd length in ‘X’ format434
169Swap Kth Node from beginning with Kth Node from End430
170Find Element Using Binary Search in Sorted Array430
171Find K Length Subarray of Maximum Average430
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way425
174print all palindromic partitions420
175Flatten a multilevel linked list415
176Maximum Length of Chain Pairs414
177Shortest Superstring Problem413
178Check if String Follows Order of Characters by a Pattern or not411
179Sorting a K Sorted Array408
180Sort a String According to Another String401
181Longest Span with same Sum in two Binary Arrays II397
182Reverse a Linked List in groups395
183Find a Sorted Subsequence of size 3391
184Program to add two binary digits389
185Find the two Numbers with Odd Occurrences in an Unsorted Array386
186Recursively print all the sentences that can be formed from list of word lists385
187Longest Common Prefix Using Binary Search II383
188Reverse a Singly Linked List (Iterative/Non-Recursive)381
189Rearrange a linked list in Zig-Zag377
190Check if String can Become Empty by Recursively Deleting given Substring376
191Kth Non-repeating Character376
192Caesar Cipher376
193Pancake Sorting373
194Rotate Image by 90 degrees370
195Longest Common Prefix Word by Word Matching367
196Perfect Reversible String364
197Permutations of a Given String Using STL363
198Merging Two Sorted Arrays361
199Increasing Subsequence of Length three with Maximum Product361
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes360
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
2031`s and 2`s complement of binary number356
204Find First non-repeating character in a string356
205Four Elements that Sum to Given353
206Delete N nodes after M351
207List items containing all characters of a given word350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array344
210Split a string339
211Minimum Characters to be Removed to Make a Binary String Alternate338
212Palindrome string (number)338
213Check if a Linked list of Strings form a Palindrome332
214Print All Distinct Elements of the Array330
215Recursive Implementation of atoi()330
216Sorting the array of strings329
217Convert a String that is Repetition of a Substring of Length K328
218Find the first Repeating Number in a Given Array325
219Maximum occurring character in a string325
220Even Substring Count324
221Reverse a singly linked list recursively323
222Valid Parentheses LeetCode Solution323
223Binary Tree to Doubly linked list322
224Can we reverse a linked list in less than O(n) time ?322
225Print Shortest Path to Print a String on Screen320
226Convert string1 to string2 in one edit318
227Nth Character in Concatenated Decimal String316
228Reverse a String using Stack316
229Sort Elements by Frequency II316
230Lower Case To Upper Case314
231wildcard character matching313
232Maximum Subarray Leetcode Solution312
233Count the number of words310
234Merge Two Sorted Arrays310
235Find the Lost Element From a Duplicated Array310
236Split Four Distinct Strings307
237Find middle of the Linked List305
238Count the Pairs at Same Distance as in English Alphabets300
239Longest Common Subsequence with Permutations298
240Next Greater Element in an Array294
241Matrix Chain Multiplication using Dynamic Programming292
242Palindrome Permutation287
243Find Nth Node283
244Searching a node in a Binary Search Tree283
245Find All Pairs With a Given Difference281
246Triplet from three linked lists with given sum280
247Delete a Tree279
248Roman to Integer Leetcode Solution279
249Print all Possible Ways to Break a String in Bracket Form276
250String(represents an integer) to value275
251Reverse a String275
252Binary Tree272
253Reverse Bits271
254Change Gender of a given String271
255Delete a node under given conditions271
256Word Search Leetcode Solution269
257Sort an array of strings268
258Remove middle points in a linked list of line segments265
259Number of sub-strings which recursively add up to 9265
260How to Efficiently Implement k Stacks in a Single Array?265
261Longest Common Extension264
262Count Pairs With Given Sum264
263Meeting Rooms II LeetCode Solution263
264Toeplitz Matrix262
265First non Repeating Element262
266Remove spaces from a string261
267Repeated Substring Pattern260
268Longest Palindromic Substring LeetCode Solution260
269Move all negative elements to one side of array258
270Shuffle a given Array258
271Min Stack255
272N queen problem254
273Find, second, frequent, character249
274House Robber Leetcode Solution249
275Number of Islands LeetCode Solution249
276Dijkstra Algorithm249
277Cuckoo sequence program248
278Most Frequent Element in an Array246
279Clone a linked list with next and random pointer (Hashing)245
280Minimize the maximum difference between the heights244
281Expression Evaluation244
282Search Insert Position Leetcode Solution243
283Sort linked which is sorted on absolute values243
284Max stack243
285Fibonacci numbers240
286Valid Palindrome Leetcode Solution239
287How to Delete a Linked List238
288Plus One Leetcode Solution238
289Sudoku Solver237
290KMP Algorithm237
291Min Stack Leetcode Solution236
292Word Search236
293Subset Leetcode235
294Evaluation of Postfix Expression234
295Reverse words in a string234
296Combination Sum Leetcode Solution233
297Number Of 1 bits232
298Pair of Positive Negative Values in an Array227
299Merge Sorted Arrays Leetcode Solution227
300Backspace String Compare227
301Rabin Karp Algorithm226
302Subarray with 0 sum226
303Set Matrix Zeroes225
304Sqrt(x) Leetcode Solution225
305Reversing a Queue224
306Contains Duplicate II Leetcode Solution223
307Combination Sum222
308Tower Of Hanoi222
309Common elements in all rows of a given matrix221
310Integer to Roman Leetcode Solution220
311Product of array except self219
312Delete middle element of a stack219
313Intersection of Two Arrays II Leetcode Solution218
314Pascal Triangle Leetcode217
315Count subarrays with equal number of 1’s and 0’s217
316String Compression215
317Second Most Repeated Word in a Sequence215
318Add Binary Leetcode Solution215
319Reverse individual words214
320Construct Binary Tree from Given Inorder and Preorder Traversals214
321Find Top K (or Most Frequent) Numbers in a Stream214
322Minimum swaps required to bring all elements less than or equal to k together213
323Palindrome Linked List Leetcode Solution213
324Count of index pairs with equal elements in an array212
325Pow(x, n) Leetcode Solution212
326Sliding Window Technique212
327Next Permutation211
328Single Number Leetcode Solution211
329Arithmetic Expression Evaluation211
330Segregate even and odd numbers211
331Bellman Ford Algorithm211
332Implementation of Deque using Doubly Linked List210
333Page Replacement Algorithms in Operating Systems210
334Kruskal Algorithm209
335Postfix to Infix Conversion209
336Design a stack that supports getMin() in O(1) time and O(1) extra space209
337Contains Duplicate209
338Find sum of non-repeating elements (distinct) elements in an array209
339Count Odd Numbers in an Interval Range Leetcode Solution208
340Minimum Value to Get Positive Step by Step Sum Leetcode Solution208
341Sort elements by frequency208
342K-th Smallest Element in a Sorted Matrix207
343Maximum Number of Balloons Leetcode Solution207
344Maximum Subarray206
345Longest Common Prefix Leetcode Solution206
346Third Maximum Number Leetcode Solution205
347Group Words With Same Set of Characters205
348Permutations Leetcode Solution204
349Convex Hull Algorithm204
350Find Lucky Integer in an Array Leetcode Solution204
351Find the Town Judge Leetcode Solution203
352Top K Frequent Words203
353Longest Substring Without Repeating Characters LeetCode Solution203
354Majority Element Leetcode Solution203
355Find Numbers with Even Number of Digits Leetcode Solution203
356Sum of minimum and maximum elements of all subarrays of size k203
357Swap Nodes in Pairs Leetcode Solutions202
358Spiral Matrix LeetCode Solution202
359Minimum operation to make all elements equal in array202
360Smallest Subarray with k Distinct Numbers202
361Count subarrays having total distinct elements same as original array201
362Sorting array using Stacks201
363First element occurring k times in an array201
364Scramble String200
365Evaluate Division200
366Given two unsorted arrays find all pairs whose sum is x199
367Merge Two Sorted Lists Leetcode Solutions199
368Count Primes Leetcode Solutions199
369Reverse a Number Using Stack198
370Special Number198
371Search in Rotated Sorted Array Leetcode Solution197
372Check if two arrays are equal or not197
373Prefix to Infix Conversion196
374Minimum Path Sum196
375Reversing the First K elements of a Queue196
376Group Anagrams196
377Maximum possible difference of two subsets of an array196
378Pascal’s Triangle II Leetcode Solution195
379Number of Good Pairs Leetcode Solution195
380Maximum Distance Between two Occurrences of Same Element in Array195
381Fizz Buzz Leetcode195
382Find duplicates in a given array when elements are not limited to a range195
383Best Time to Buy and Sell Stock  II Leetcode Solution195
384Huffman Coding194
385Top K Frequent Elements193
386Minimum Absolute Difference Leetcode Solution193
387Single Number193
388Power of Two Leetcode Solution193
389Minimum Steps to reach target by a Knight193
390Missing Number Leetcode Solution193
391Maximal Square192
392Running Sum of 1d Array Leetcode Solution192
393Find All Numbers Disappeared in an Array Leetcode Solution192
394Sort Array by Increasing Frequency Leetcode Solution192
395Coin Change 2 Leetcode Solution192
396Range Sum Query 2D – Immutable Leetcode Solution192
397House Robber II Leetcode Solution192
398How to Implement Stack Using Priority Queue or Heap?191
399Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution191
400Unique Paths Leetcode Solution191
401Leetcode Permutations190
402Find The Duplicate Number190
403Sorting using trivial hash function190
404Subarray Sum Equals K LeetCode Solution190
405Expression Contains Redundant Bracket or Not189
406Check if Array Contains Contiguous Integers With Duplicates Allowed189
407Matrix Diagonal Sum Leetcode Solution189
408Max Consecutive Ones Leetcode Solution189
409How Many Numbers Are Smaller Than the Current Number Leetcode Solution189
410Unique Paths189
411Decode String188
412Happy Number Leetcode Solution188
413Subset sum problem188
414Palindrome Substring Queries188
415Subarray Sum Equals k188
416Smallest Element Repeated Exactly K Times188
417Zigzag Conversion188
418Difference between highest and least frequencies in an array187
419Convert String To Int187
420Reverse Vowels of a String Leetcode Solution187
421Sort Integers by The Number of 1 Bit Leetcode Solution187
422Subtract the Product and Sum of Digits of an Integer Leetcode Solution187
423Find Winner on a Tic Tac Toe Game Leetcode Solution187
424Nth Catalan Number187
425Cumulative Frequency of Count of Each Element in an Unsorted Array187
426Fibonacci Number LeetCode Solution187
427Remove Duplicates from Sorted Array Leetcode Solution187
428Length of the largest subarray with contiguous elements186
429Find Number of Employees Under every Employee186
430Print All Distinct Elements of a Given Integer Array186
431Find Median from data Stream186
432Reverse Integer186
433Letter Case Permutation186
434Find the Closest Palindrome number186
435Shuffle the Array Leetcode Solution186
436Find top three repeated in array186
437Check If N and Its Double Exist Leetcode Solution186
438Monotonic Array LeetCode Solution186
439Best Time to Buy and Sell Stock III Leetcode Solution185
440Capacity To Ship Packages Within D Days Leetcode Solution185
441Sort a stack using recursion185
442Trapping Rain Water Leetcode Solution185
443Find all pairs (a, b) in an array such that a % b = k185
444Subarrays with distinct elements184
445Implement Stack and Queue using Deque184
446Integer to English words184
447Find the first repeating element in an array of integers184
448Count Substrings with equal number of 0s, 1s and 2s184
449LRU Cache Implementation184
450Bipartite Graph184
451Reverse Words in a String III LeetCode Solution184
452Minimum Moves to Equal Array Elements Leetcode Solution183
453Kth largest element in an Array Leetcode Solutions183
454Delete a Node from linked list without head pointer183
455The K Weakest Rows in a Matrix Leetcode Solution183
456Maximum Depth of Binary Tree Leetcode Solution183
457Find Minimum In Rotated Sorted Array182
458Reverse a Stack Using Recursion182
459Find the Duplicate Element182
460Count pairs from two linked lists whose sum is equal to a given value182
461Prim’s Algorithm182
462Priority Queue Using Singly Linked List182
463Generate a String With Characters That Have Odd Counts Leetcode Solution182
464Find elements which are present in first array and not in second181
465Concatenation of Array LeetCode Solution181
466Longest Common Subsequence181
467Reverse a String181
468Merge Two Sorted Linked Lists181
469Excel Sheet Column Number Leetcode Solution181
470Sum of Subarray Ranges Leetcode Solution181
471Sorting a Queue without Extra Space181
472Text Justification LeetCode Solution180
473Count and Say180
474Fizz Buzz180
475Find Common Characters Leetcode Solution180
476Next Greater Element I Leetcode Solution180
477Remove Minimum Number of Elements Such That no Common Element Exist in both Array180
478Edit Distance179
479Find First and Last Position of Element in Sorted Array Leetcode Solution179
480Find the Difference Leetcode Solution179
481Reverse a linked list178
482Kth Largest Element in a Stream Leetcode Solution178
483Kids With the Greatest Number of Candies Leetcode Solution178
484MiniMax Algorithm178
485Floyd Warshall Algorithm178
486Multiply Strings Leetcode Solution178
487Word Ladder LeetCode Solution178
488Target Sum178
489Balanced Binary Tree Leetcode Solution178
490Longest Common Prefix using Trie178
491Degree of an array178
492Print all subarrays with 0 sum178
493Top View of Binary Tree177
494Number of Steps to Reduce a Number to Zero Leetcode Solution177
495Priority Queue in C++177
496Move Zeroes LeetCode Solution176
497Merge Overlapping Intervals176
498Iterative Tower of Hanoi176
499Design Parking System Leetcode Solution176
500Longest subarray not having more than K distinct elements176
501Flood Fill LeetCode176
502Pair with given product176
503Peak Index in a Mountain Array175
504Find four elements that sum to a given value (Hashmap)175
505Prefix to Postfix Conversion175
506Koko Eating Bananas Leetcode Solution175
507Shortest Palindrome175
508Max Area of Island175
509Valid Parenthesis String174
510Shuffle String Leetcode Solution174
511Zigzag Conversion LeetCode Solution174
512Postfix to Prefix Conversion174
513Count and Say Leetcode Solution174
514Find missing elements of a range174
515Find subarray with given sum (Handles Negative Numbers)174
516The Stock Span Problem174
517Find any one of the multiple repeating elements in read only array174
518Slowest Key Leetcode Solution174
519Check if a given array contains duplicate elements within k distance from each other174
520Substring With Concatenation Of All Words173
521Jump Game Leetcode Solution173
522Find Index of Closing Bracket for a Given Opening Bracket in an Expression173
523Find distinct elements common to all rows of a matrix173
524Count number of triplets with product equal to given number173
525Intersection of Two Arrays173
526Mobile Numeric Keypad Problem173
527Implement a stack using single queue173
528Find N Unique Integers Sum up to Zero Leetcode Solution173
529Recursion173
530Length of Last Word Leetcode Solution173
531Implement Stack using Queues173
532Smallest Subarray With all Occurrences of a Most Frequent Element172
533K-th Distinct Element in an Array172
534Container with Most Water172
535Contiguous Array Leetcode172
536Convert array into Zig-Zag fashion172
537Excel Sheet Column Title Leetcode Solution172
538Iterative Inorder Traversal of a Binary Tree172
539Next Greater Frequency Element171
540Best Time to Buy and Sell Stock171
541Delete Node in a Linked List Leetcode Solution171
542Maximum sum rectangle in a 2D matrix171
543Last Stone Weight171
544Relative Sort Array Leetcode Solution171
545Build Array From Permutation Leetcode Solution171
546Longest Common Prefix using Sorting171
547Minimum Bracket Reversals170
548Largest Perimeter Triangle Leetcode Solution170
549Convert a normal BST to Balanced BST170
550Valid Sudoku170
551First negative integer in every window of size k170
552Find Words That Can Be Formed by Characters Leetcode Solution170
553Minimum Operations to convert X to Y170
554Is Subsequence Leetcode Solution169
555Shuffle an Array169
556Gold Mine Problem169
557Sum of Left Leaves Leetcode Solutions169
558Arrange given numbers to form the biggest number169
559The Knapsack Problem168
560Group Multiple Occurrence of Array Elements Ordered by first Occurrence168
561Jewels and Stones Leetcode Solution168
562Distribute Candies to People Leetcode Solution168
563Assign Cookies Leetcode Solution168
564Implementation of Deque using circular array168
565Integer to Roman168
566Rearrange a binary string as alternate x and y occurrences168
567Change the Array into Permutation of Numbers From 1 to N168
568Check for Balanced Parentheses in an Expression168
569Minimum Delete Operations to make all Elements of Array Same167
570Valid Anagrams167
571Count all subsequences having product less than K167
572Insert Interval Leetcode Solution167
573Maximum path sum in a triangle167
574Shortest Path in a Grid with Obstacles Elimination LeetCode Solution167
575Isomorphic Strings Leetcode Solution167
576Linked List Cycle II LeetCode Solution167
577How to check if two given sets are disjoint?166
578Hamming Distance166
5793Sum Closest LeetCode Solution166
580Find the smallest positive integer value that cannot be represented as sum of any subset of a given array166
58101 Matrix LeetCode Solution166
582N-th Tribonacci Number Leetcode Solution166
583Convert Sorted Array to Binary Search Tree Leetcode Solution166
584Decode Ways166
585Island Perimeter Leetcode Solution166
586Unique Binary Search Trees166
587Sieve of Eratosthenes166
588Rotate List Leetcode Solution165
589Same Tree LeetCode Solution165
590Remove Linked List Elements Leetcode Solution165
591Count the number of nodes at given level in a tree using BFS165
592Summary Ranges Leetcode Solution164
593Minimum number of distinct elements after removing m items164
594LRU Cache LeetCode Solution164
595Trapping Rain Water LeetCode Solution164
596Minimum Knight Moves LeetCode Solution164
597Maximum Distance in Array164
598Maximum difference between first and last indexes of an element in array164
599K Empty Slots LeetCode164
600Combinations Leetcode Solution164
601Find minimum difference between any two elements163
602Distance Between Bus Stops Leetcode Solution163
603Find Sum of all unique sub-array sum for a given array163
604Minimum number of subsets with distinct elements163
605Word Pattern163
606Rotate Image LeetCode Solution163
607Frog Jump Leetcode Solution162
608Word Wrap Problem162
609Printing brackets in Matrix Chain Multiplication Problem162
610Maximum Number of Chocolates to be Distributed Equally Among k Students162
611Remove All Occurrences of a Substring LeetCode Solution162
612Find if an Expression has Duplicate Parenthesis or Not162
613Coin Change Problem162
614Minimum insertions to form a palindrome with permutations allowed162
615Applications of Breadth First Search and Depth First Search162
616Distance of nearest cell having 1 in a binary matrix162
617Sort Array By Parity LeetCode Solution162
618Replace Elements with Greatest Element on Right Side Leetcode Solution161
619Stone Game LeetCode161
620Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
621XOR Operation in an Array Leetcode Solution161
622Find the Duplicate Number LeetCode Solution161
623Best Time to Buy and Sell Stock LeetCode Solution161
624Permutation in String Leetcode Solution161
625Minimum Cost to Hire K Workers161
626House Robber160
627Find Maximum Level sum in Binary Tree160
628Minimum Depth of Binary Tree Leetcode Solution160
629Sort Characters By Frequency LeetCode Solution160
630Kth Missing Positive Number Leetcode Solution160
631Maximum Consecutive Numbers Present in an Array160
632Defanging an IP Address Leetcode Solution160
633License Key Formatting Leetcode Solution160
634Reverse a stack without using extra space in O(n)159
635Binary Tree Zigzag Level Order Traversal LeetCode Solution159
636Non-overlapping sum of two sets159
637Smallest Good Base159
638Painting Fence Algorithm159
639Longest Increasing Subsequence159
640Segregate 0s and 1s in an Array159
641Best Time to Buy and Sell Stock with Cooldown Leetcode Solution158
642Longest Substring with At Most K Distinct Characters LeetCode Solution158
643Optimal Account Balancing LeetCode Solution158
644Iterative Method to find Height of Binary Tree158
645Power of Four Leetcode Solution158
646Queries for counts of array elements with values in given range158
647Valid Palindrome II Leetcode Solution158
648Tracking current Maximum Element in a Stack158
649Check If It Is a Straight Line Leetcode Solution158
650Count Good Nodes in Binary Tree Leetcode Solution157
651Flipping an Image LeetCode Solution157
652Reorganize String157
653Letter Combinations of a Phone Number157
654Isomorphic Strings157
655GCD Of Two Numbers157
656Sum of All Odd Length Subarrays Leetcode Solution157
657Merge Two Balanced Binary Search Trees157
658Find Largest d in Array such that a + b + c = d157
659Check If Two String Arrays are Equivalent Leetcode Solution157
660Convert an array to reduced form157
661Strobogrammatic Number LeetCode Solution157
662K Empty Slots157
663Check if a queue can be sorted into another queue using a stack156
664Moving Average from Data Stream Leetcode Solution156
665How to Create Mergable Stack?156
666Longest Substring with At Least K Repeating Characters LeetCode Solution156
667Partition Labels LeetCode Solution156
668String to Integer (atoi) LeetCode Solution156
669Wiggle Sort156
670Number of Provinces Leetcode Solution156
671Employee Free Time LeetCode Solution156
672Maximum Number of Coins You Can Get Leetcode Solution155
673Ugly Number Leetcode Solution155
674Find whether an array is subset of another array155
675BFS vs DFS for Binary Tree155
676Inorder Successor of a node in Binary Tree155
677Increasing Decreasing String Leetcode Solution155
678Permutation Sequence LeetCode Solution155
679Form minimum number from given sequence155
680Largest Sum Contiguous Subarray155
681Reservoir Sampling155
682Find the Distance Value Between Two Arrays Leetcode Solution155
683Sum of f(a[i], a[j]) over all pairs in an array of n integers155
684Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
685Reversing a Queue using Recursion154
686Populating Next Right Pointers in Each Node154
687Delete consecutive same words in a sequence154
688Find Leaves of Binary Tree LeetCode Solution154
689Reducing Dishes LeetCode Solution154
690Maximum Number of Occurrences of a Substring Leetcode Solution154
691Lucky Numbers in a Matrix Leetcode Solution154
692Path With Maximum Minimum Value LeetCode Solution154
693Subset Sum Leetcode154
694To Lower Case Leetcode Solution154
695Delete Nth node from the end of the given linked list153
696Find pairs with given sum such that elements of pair are in different rows153
697Longest Increasing Path in a Matrix LeetCode Solution153
698Find the node with minimum value in a Binary Search Tree153
699Sort Array by Increasing Frequency Leetcode Solution153
700Valid Palindrome153
701Valid Perfect Square Leetcode Solution153
702Find the Smallest Divisor given a Threshold Leetcode Solution153
703Majority Element II Leetcode Solution153
704Number of Dice Rolls With Target Sum LeetCode Solution153
705Hamming Distance Leetcode Solution153
706Maximum Product of Three Numbers LeetCode Solution153
707Print the Fibonacci numbers in reverse order153
708Recover Binary Search Tree152
709Partition Array Into Three Parts With Equal Sum Leetcode Solution152
710Decompress Run-Length Encoded List Leetcode Solution152
711Add and Search Word – Data structure design LeetCode152
712Factorial Trailing Zeroes Leetcode Solution152
713Unique Paths II Leetcode Solution152
714Construct BST from given Preorder Traversal152
715Reverse Only Letters LeetCode Solution152
716Dynamic Programming Basics152
717Remove Invalid Parentheses Leetcode Solution152
718Numbers with prime frequencies greater than or equal to k152
719Edit Distance LeetCode Solution152
720Rank Transform of an Array Leetcode Solution151
721Stack Permutations (Check if an array is stack permutation of other)151
722Largest subarray with equal number of 0s and 1s151
723Longest Span with same Sum in two Binary arrays151
724Binary Tree zigzag level order Traversal151
725Convert a Number to Hexadecimal Leetcode Solution151
726Remove Nth Node From End of List Leetcode Solution150
727Queue based approach for first non-repeating character in a stream150
728Merge Two Binary Trees LeetCode Solution150
729Bubble sort using two Stacks150
730Minimum Cost For Tickets Leetcode Solution150
731Deletion in a Binary Tree150
732Find Pair with Greatest Product in Array150
733Keyboard Row Leetcode Solution150
734Find Maximum Depth of Nested Parenthesis in a String150
735Binomial Coefficient150
736Restore IP Addresses Leetcode Solution150
737Maximum Product of Two Elements in an Array Leetcode Solution150
738Elements to be added so that all elements of a range are present in array149
739String Compression LeetCode Solution149
740Find the largest multiple of 3149
741Minimum Distance Between BST Nodes Leetcode Solution149
742Best Meeting Point LeetCode Solution149
743Count quadruples from four sorted arrays whose sum is equal to a given value x149
744Sorted Linked List to Balanced BST149
745Bulb Switcher LeetCode Solution149
746Maximum 69 Number Leetcode Solution149
747k-th missing element in increasing sequence which is not present in a given sequence149
748Binary Tree Maximum Path Sum LeetCode Solution149
749Finding K closest element149
750Student Attendance Record I Leetcode Solution149
751Growable array based stack149
752Symmetric Tree Leetcode Solution149
753Minimum Height Trees149
754Find unique character in a string149
755Merge K Sorted Linked Lists149
756Robot Room Cleaner Leetcode Solution148
757Jump Game148
758Word Pattern LeetCode Solution148
759Maximum Length of a Concatenated String with Unique Characters Leetcode Solution148
760Morris Traversal148
761Generate all possible sorted arrays from alternate elements of two given sorted arrays148
762Race Car LeetCode Solution148
763Invert Binary Tree LeetCode Solution148
764Remove brackets from an algebraic string containing + and – operators148
765Perform String Shifts Leetcode148
766Find All Duplicates in an Array LeetCode Solution147
767Number of NGEs to the Right147
768Largest rectangular sub-matrix whose sum is 0147
769Largest Rectangle in Histogram LeetCode Solution147
770Relative Ranks Leetcode Solution147
771Find Median from Data Stream LeetCode Solution147
772Program for Bridge and Torch problem147
773Maximum Depth of N-ary Tree Leetcode Solution147
774Evaluate Reverse Polish Notation LeetCode Solution147
775Minimize Maximum Pair Sum in Array LeetCode Solution147
776First Unique Character in a String LeetCode Solution147
777Kth ancestor of a node in binary tree147
778Valid Number147
779Minimum time required to rot all oranges147
780Non-decreasing Array LeetCode Solution147
781Diagonal Traversal of Binary Tree147
782Check for Palindrome after every character replacement Query147
783Nested List Weight Sum II LeetCode Solution146
784Get Maximum in Generated Array Leetcode Solution146
785N-Queens LeetCode Solution146
786Snakes and Ladders LeetCode Solution146
787Merge Sorted Array LeetCode Solution146
788Sort an array according to the order defined by another array146
789Minimum number of jumps to reach end146
790Partition to K Equal Sum Subsets Leetcode Solution146
791Special Array With X Elements Greater Than or Equal X Leetcode Solution146
792String comparison containing wildcards146
793Count items common to both the lists but with different prices146
794Search in a Binary Search Tree Leetcode Solution146
795Remove Duplicates from Sorted List LeetCode Solution146
796Tiling Problem146
797Linked List Cycle146
798Number of Islands II LeetCode Solution146
799Check If Array Pairs Are Divisible by k LeetCode Solution145
800Final Prices With a Special Discount in a Shop Leetcode Solution145
801Base 7 Leetcode Solution145
802Alien Dictionary LeetCode Solution145
803Search a 2D Matrix II Leetcode Solution145
804Transpose Graph145
805Check if Two Expressions With Brackets are Same145
806Interval Tree145
807Reorder Data in Log Files LeetCode Solution145
808Print a Binary Tree in Vertical Order145
809Maximum Difference Between Increasing Elements LeetCode Solution145
810Minimum swaps to make sequences increasing145
811Find if Path Exists in Graph Leetcode Solution145
812Crawler Log Folder Leetcode Solution144
813Total Numbers With no Repeated Digits in a Range144
814One Edit Distance LeetCode Solution144
815Number Complement Leetcode Solution144
816Circular Queue144
817Minimum Time Visiting All Points Leetcode Solution144
818Clone Graph LeetCode Solution144
819Nearest Exit from Entrance in Maze LeetCode Solution144
820Iterative Preorder Traversal144
821A Space Optimized DP solution for 0-1 Knapsack Problem144
822Remove Duplicates from Sorted List II144
823Split a String in Balanced Strings Leetcode Solution144
824Friends Pairing Problem144
825Find all triplets with zero sum143
826Longest Subarray Having Count of 1s One More than Count of 0s143
827Sort Array By Parity II Leetcode Solution143
828Last Stone Weight II LeetCode Solution143
829Convert BST to Min Heap143
830Permutation Coefficient143
831Course Schedule II – LeetCode143
832Priority Queue using doubly linked list143
833Guess Number Higher or Lower LeetCode Solution142
834Brightest Position on Street LeetCode Solution142
835Regular Expression Matching142
836Top K Frequent Words LeetCode Solution142
837Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution142
838Sort Colors142
839Maximum Nesting Depth of the Parentheses Leetcode Solution142
840Valid Parentheses Leetcode Solution142
841Subset with sum divisible by m142
842Minimum Swaps to Make Strings Equal Leetcode Solution142
843Subarray Product Less Than K LeetCode Solution142
844Partition List Leetcode Solution142
845Find the Only Repetitive Element Between 1 to N-1142
846Find the subarray with least average142
847Find All Possible Recipes from Given Supplies LeetCode Solution142
848Path with maximum average value142
849Can Place Flowers LeetCode Solution142
850Maximum size subarray sum equals k142
851Design a Stack With Increment Operation Leetcode Solution142
852Count ways to reach the nth stair using step 1, 2 or 3141
853Spiral Matrix II Leetcode Solution141
854Check if an Array is Stack Sortable141
855Sum of nearest smaller and greater number141
856Minimum Jumps to Reach Home LeetCode Solution141
857Subsequence of Size K With the Largest Even Sum LeetCode Solution141
858Maximum Profit in Job Scheduling Leetcode Solution141
859Form Minimum Number From Given Sequence141
860LCS (Longest Common Subsequence) of three strings141
861Sorted Array to Balanced BST141
862Matrix Chain Multiplication141
863Given an Array of Pairs Find all Symmetric Pairs in it141
864Brick Wall LeetCode Solution141
865Check if a given array can represent Preorder Traversal of Binary Search Tree141
866Count Distinct Elements in Every Window of Size K141
867Minimum Number of Taps to Open to Water a Garden LeetCode Solution141
868Check whether a given Binary Tree is Complete or not141
869Binary Search Tree Search and Insertion140
870Tree Traversal (Preorder, Inorder & Postorder)140
871Count Subarrays with Same Even and Odd Elements140
872Level order Traversal in Spiral Form140
873Insert Delete GetRandom140
874Identify and Mark Unmatched Parenthesis in an Expression139
875Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution139
876Find Maximum Sum Possible Equal Sum of Three Stacks139
877Minimum Sum Path in a Triangle139
878Union and Intersection of two Linked Lists139
879Distinct adjacent elements in an array139
880Range sum queries without updates139
881Rearrange an Array Such that arr[i] is equal to i139
882Insert into a Binary Search Tree Leetcode Solution139
883Find all permuted rows of a given row in a matrix139
884Sequences of given length where every element is more than or equal to twice of previous139
885Water Bottles Leetcode Solution139
886Guess Number Higher or Lower II139
887Convert Sorted List to Binary Search Tree138
888Alien Dictionary138
889BFS for Disconnected Graph138
890Rearrange Spaces Between Words Leetcode Solution138
891Lemonade Change Leetcode Solution138
892Maximum Score After Splitting a String Leetcode Solution138
893Balanced Expression with Replacement138
894Set Matrix Zeroes Leetcode Solution138
895Destination City Leetcode Solution138
896Shortest Word Distance Leetcode Solution138
897GCDs of given index ranges in an array138
898Daily Temperatures Leetcode Solution138
899An Interesting Method to generate Binary Numbers from 1 to n138
900Diagonal Traversal LeetCode Solution138
901Minimum sum of multiplications of n numbers138
902Delete And Earn138
903Missing Element in Sorted Array LeetCode Solution138
904A program to check if a binary tree is BST or not138
905Three way partitioning of an array around a given range138
906Find Common Characters Leetcode Solution138
907Find distance between two nodes of a Binary Tree138
908Check if stack elements are pairwise consecutive138
909Count Negative Numbers in a Sorted Matrix LeetCode Solution138
910Number of Days Between Two Dates LeetCode Solution137
911Range LCM Queries137
9124Sum137
913Special Positions in a Binary Matrix Leetcode Solution137
914Check if the given array can represent Level Order Traversal of Binary Search Tree137
915Design Browser History LeetCode Solution137
916Merge Two Sorted Lists Leetcode137
917Repeated Substring Pattern LeetCode Solution137
918Spiral Matrix III LeetCode Solution137
919Construct Complete Binary Tree from its Linked List Representation137
920K’th Largest Element in BST when modification to BST is not allowed136
921Diagonal Traverse LeetCode Solution136
922Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i136
923Queue using Stacks136
924Longest Palindromic Subsequence136
925Palindrome Partitioning Leetcode Solution136
926Least Number of Unique Integers after K Removals Leetcode Solution136
927Vertical sum in a given binary tree136
928Robot Bounded In Circle LeetCode Solution136
929Infix to Postfix136
930Maximum Subarray Sum Excluding Certain Elements136
931Number of Equivalent Domino Pairs Leetcode Solution136
932Number of Distinct Islands Leetcode Solution136
933Stone Game II Leetcode135
934Trim a Binary Search Tree135
935Construct the Rectangle Leetcode Solution135
936Print Fibonacci sequence using 2 variables135
937Queries for GCD of all numbers of an array except elements in a given range135
938Averages of Levels in Binary Tree135
939Three Consecutive Odds Leetcode Solution135
940Can Make Arithmetic Progression From Sequence Leetcode Solution135
941Dividing Array into Pairs With Sum Divisible by K135
942Largest area rectangular sub-matrix with equal number of 1’s and 0’s135
943Lexicographical Numbers Leetcode Solution135
944Analyze User Website Visit Pattern LeetCode Solution134
945Word Break134
946Pattern Occurrences using Stack134
947Median of Two Sorted Arrays134
948Check if any two intervals overlap among a given set of intervals134
949Merging Intervals134
950Remove Duplicates from Sorted List II LeetCode Solution134
951All Unique Triplets that Sum up to a Given Value134
952Difference Array | Range update query in O(1)134
953Binary array after M range toggle operations134
954Maximum Frequency Stack Leetcode Solution134
955Construct BST from its given Level Order Traversal134
956Strongly Connected Component134
9573 Sum134
958Time Based Key-Value Store LeetCode Solution134
959Sliding Window Maximum133
960Symmetric Tree133
961Split Array Into Consecutive Subsequences133
962Binary Tree Longest Consecutive Sequence LeetCode Solution133
963Newman-Conway Sequence133
964Count Submatrices With All Ones LeetCode Solution133
965Iterative Postorder Traversal Using Two Stacks133
966Depth First Search (DFS) for a Graph133
967Largest Substring Between Two Equal Characters Leetcode Solution133
968Maximize Sum of Array after K Negations Leetcode Solution133
969Create Maximum Number133
970Palindrome Partitioning133
971Length of Longest Fibonacci Subsequence132
972Sign of the Product of an Array LeetCode Solution132
973Binary Search Tree Delete Operation132
974Intersection of Two Linked Lists LeetCode Solution132
975Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space132
976Breadth First Search (BFS) for a Graph132
977Maximum Product Subarray132
978Find Maximum of Minimum for Every Window Size in a Given Array132
979Segment Tree132
980Largest divisible pairs subset132
981Climbing stairs132
982My Calendar I LeetCode Solution132
983Minesweeper LeetCode Solution131
984Find the Difference Leetcode Solution131
985Count Primes in Ranges131
986First missing positive131
987Height of a generic tree from parent array131
988Minimum Height Trees LeetCode Solution131
989Find Duplicate Subtrees131
990Asteroid Collision LeetCode Solution131
991Boundary Traversal of binary tree131
992Maximum subsequence sum such that no three are consecutive131
993Reverse Nodes in K-Group131
994Count pair with Given Sum131
995Level Order Traversal of Binary Tree131
996Make The String Great Leetcode Solution130
997Double the first element and move zero to end130
998Kth Smallest Element in a BST Leetcode Solution130
999The Painter’s Partition Problem130
1000Insertion in a Binary Tree130
1001Find the First Circular Tour that visits all the Petrol Pumps130
1002Serialize and Deserialize Binary Tree130
1003Find number of pairs in an array such that their XOR is 0130
1004Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
1005Find postorder traversal of BST from preorder traversal130
1006Count subarrays where second highest lie before highest129
1007Partition Equal Subset Sum129
1008Kill Process LeetCode Solution129
1009Largest Number Leetcode Solution129
1010Compute nCr % p129
1011Shortest Completing Word Leetcode Solution129
1012Rearrange array such that even positioned are greater than odd129
1013Longest Nice Substring LeetCode Solution129
1014Number Of Longest Increasing Subsequence129
1015Product of Array Except Self LeetCode Solution129
1016Level order traversal using two Queues129
1017Unique Paths II129
1018Valid Boomerang Leetcode Solution129
1019Maximum Length of Repeated Subarray129
1020Maximum Number of Ways to Partition an Array LeetCode Solution128
1021Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1022Collect maximum points in a grid using two traversals128
1023Friends Of Appropriate Ages LeetCode Solution128
1024The Maze III LeetCode Solution128
1025Scramble String LeetCode Solution128
1026Minimum Size Subarray Sum128
1027Construction of Longest Increasing Subsequence (N log N)128
1028Binary Search Tree128
1029Graph Valid Tree LeetCode Solution128
1030K Closest Points to Origin Leetcode Solution128
1031Boolean Parenthesization Problem128
1032Longest subsequence such that difference between adjacents is one128
1033Number of palindromic paths in a matrix128
1034String Matching in an Array Leetcode Solution128
1035Construct Binary Tree from given Parent Array representation127
1036Find whether a subarray is in form of a mountain or not127
1037Balanced Binary Tree127
1038Advantages of BST over Hash Table127
1039Ugly Numbers127
1040Design Hit Counter LeetCode Solution127
1041Maximum weight transformation of a given string127
1042Maximum Product of Indexes of Next Greater on Left and Right127
1043Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1044Next Greater Element III LeetCode Solution127
1045Find Peak Element127
1046Build an Array With Stack Operations Leetcode Solution127
1047Morris Inorder Traversal127
1048Invalid Transactions LeetCode Solution127
1049Lowest Common Ancestor126
1050Regular Expression Matching Regular Expression Matching LeetCode Solution126
1051Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1052Iterative Depth First Traversal of Graph126
1053Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1054Implement Trie (Prefix Tree) Leetcode Solution126
1055Available Captures for Rook Leetcode Solution126
1056Populating Next Right Pointers in Each Node Leetcode Solution126
1057Validate Binary Search Tree126
1058Maximum Sum of 3 Non-Overlapping Subarrays126
1059Ugly Number II LeetCode Solution126
1060Minimum Index Sum of Two Lists126
1061Add two numbers126
1062Find the minimum distance between two numbers125
1063Longest Bitonic Subsequence125
1064Custom Sort String Leetcode Solution125
1065Binary Tree Right Side View LeetCode Solution125
1066Maximize Distance to Closest Person LeetCode Solution125
1067Count minimum steps to get the given desired array125
1068Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution125
1069Super Ugly Number125
1070Move all negative elements to end in order with extra space allowed125
1071Path Sum II LeetCode Solution125
1072Bitwise AND of Numbers Range LeetCode Solution125
1073Defanging an IP Address LeetCode Solution125
1074Employee Importance LeetCode Solution125
1075Find a Peak Element II LeetCode Solution125
1076Binary Tree Data Structure124
1077Day of the Year Leetcode Solution124
1078Recover Binary Search Tree Leetcode Solution124
1079Divisible Pairs Counting124
1080Largest BST Subtree LeetCode Solution124
1081Rearrange array such that even index elements are smaller and odd index elements are greater124
1082Types of Binary Tree124
1083Number of Closed Islands Leetcode Solution124
1084Remove Duplicates from Sorted Array II Leetcode Solution124
1085Print Next Greater Number of Q queries123
1086Smallest Common Region Leetcode Solution123
1087Maximum difference between frequency of two elements such that element having greater frequency is also greater123
1088Print all triplets in sorted array that form AP123
1089Subarrays with K Different Integers Leetcode Solution123
1090Number of Students Doing Homework at a Given Time Leetcode Solution123
1091Serialize and Deserialize Binary Tree LeetCode Solution123
1092Count pairs from two sorted arrays whose sum is equal to a given value x123
1093Consecutive Characters LeetCode Solution123
1094Find Smallest Range Containing Elements from k Lists123
1095Generate Parentheses Leetcode Solution123
1096Clone a Binary Tree with Random Pointers123
1097Number of siblings of a given Node in n-ary Tree122
1098Kth Smallest Product of Two Sorted Arrays LeetCode Solution122
1099Maximum Product Subarray122
1100Next Permutation Leetcode Solution122
1101Level of Each node in a Tree from source node122
1102Remove Palindromic Subsequences Leetcode Solution122
1103Root to Leaf path with target sum Leetcode Solutions122
1104Search in Sorted Rotated Array122
1105Combination Sum IV LeetCode Solution122
1106Path Sum122
1107Valid Tic-Tac-Toe State LeetCode Solution121
1108Convert BST into a Min-Heap without using array121
1109Third Maximum Number Leetcode Solution121
1110Print Right View of a Binary Tree121
1111Remove duplicates from sorted array121
1112Distinct Subsequences121
1113Write Code to Determine if Two Trees are Identical121
1114Bottom View of a Binary Tree121
1115Constant time range add operation on an array121
1116Palindrome Permutation LeetCode Solution120
1117Find maximum difference between nearest left and right smaller elements120
1118Search Insert Position120
1119Find Three Element From Different Three Arrays Such That a + b + c = sum120
1120Iterative method to find ancestors of a given binary tree120
1121Products of ranges in an array120
1122Cutting a Rod120
1123Mean of Array After Removing Some Elements Leetcode Solution120
1124Count Largest Group Leetcode Solution120
1125Minimum sum of squares of character counts in a given string after removing k characters120
1126Reformat The String Leetcode Solution119
1127Minimum Score Triangulation of Polygon Leetcode Solution119
1128Moser-de Bruijn Sequence119
1129Maximum Binary Tree119
1130Cells with Odd Values in a Matrix LeetCode Solution119
1131Prime Palindrome LeetCode Solution119
1132Thousand Separator Leetcode Solution119
1133Longest Increasing Consecutive Subsequence119
1134Increasing Triplet Subsequence LeetCode Solution119
1135Print modified array after executing the commands of addition and subtraction119
1136Topological Sorting119
1137Construct K Palindrome Strings LeetCode Solution118
1138Golomb sequence118
1139Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1140Search an Element in Sorted Rotated Array118
1141Longest Subarray of 1’s After Deleting One Element LeetCode Solution118
1142Minimum Absolute Difference in BST Leetcode Solution117
1143Swap Nodes In Pairs117
1144Red-Black Tree Introduction117
1145Kth Smallest Number in Multiplication Table Leetcode Solution117
1146Transform a BST to Greater sum Tree117
1147Longest Repeated Subsequence117
1148Maximum Product of Splitted Binary Tree LeetCode Solution117
1149Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1150K maximum sums of overlapping contiguous sub-arrays117
1151Find maximum length Snake sequence117
1152Queries for Number of Distinct Elements in a Subarray117
1153Binary Tree to Binary Search Tree Conversion117
1154Count even length binary sequences with same sum of first and second half bits117
1155Sum of Even Numbers After Queries117
1156Factorial Trailing Zeroes LeetCode Solution116
1157Merge two BSTs with limited extra space116
1158Priority Queue116
1159Subset Sum Problem in O(sum) space116
1160K’th Largest element in BST using constant extra space116
1161Delete Nodes and Return Forest Leetcode Solution116
1162Possible Bipartition LeetCode Solution116
1163Rotate Array116
1164Maximize sum of consecutive differences in a circular array116
1165Check Array Formation Through Concatenation Leetcode Solution116
1166Palindromic Substrings Leetcode Solution116
1167Decision Tree116
1168Find the smallest binary digit multiple of given number115
1169Search Suggestions System LeetCode Solution115
1170Minimum Cost to Move Chips to The Same Position LeetCode Solution115
1171Bus Routes Leetcode Solution115
1172First Bad Version115
1173Find a sorted subsequence of size 3 in linear time115
1174Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1175Web Crawler LeetCode Solution115
1176Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1177Minimum Sideway Jumps LeetCode Solution114
1178Minimum Moves to Equal Array Elements LeetCode Solution114
1179Count Pairs Whose Products Exist in Array114
1180Closest Binary Search Tree Value Leetcode Solution114
1181Diameter of N-Ary Tree LeetCode Solution114
1182Given a binary tree, how do you remove all the half nodes?113
1183Maximum number of segments of lengths a, b and c113
1184Reverse a Path in BST using Queue113
1185Number of Orders in the Backlog Leetcode Solution113
1186Queue Reconstruction by Height112
1187Contiguous Array LeetCode Solution112
1188Decrease Elements To Make Array Zigzag LeetCode Solution112
1189Find Largest Value in Each Tree Row LeetCode Solution112
1190Swapping Nodes in a Linked List Leetcode Solution112
1191Lowest Common Ancestor in Binary Search Tree112
1192Moving Stones Until Consecutive Leetcode Solution112
1193Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution112
1194Matchsticks to Square Leetcode Solution112
1195Maximum sum bitonic subarray111
1196Array Queries for multiply replacements and product111
1197Kth Smallest Element in a BST111
1198Reformat Date LeetCode Solution111
1199Valid Triangle Number111
1200New 21 Game111
1201Champagne Tower LeetCode Solution111
1202Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1203Closest Leaf in a Binary Tree LeetCode Solution111
1204Sum of Left Leaves LeetCode Solution110
1205Valid Perfect Square LeetCode Solution110
1206Graph and its representation110
1207How to print maximum number of A’s using given four keys110
1208Replace two consecutive equal values with one greater110
1209Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1210Write a function to get the intersection point of two Linked Lists110
1211Range Sum Query using Sparse Table110
1212Maximum sum of pairs with specific difference110
1213Maximum Depth Of Binary Tree110
1214Range Queries for Longest Correct Bracket Subsequence110
1215Integer Break LeetCode Solution110
1216Arithmetic Slices II – Subsequence LeetCode Solution109
1217BST to a Tree with Sum of all Smaller Keys109
1218Lowest Common Ancestor of a Binary Tree Leetcode Solution109
1219Maximum sum of a path in a Right Number Triangle109
1220Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution109
1221Guess The Word109
1222Path Crossing Leetcode Solution109
1223Concatenation of Array LeetCode Solution109
1224Print modified array after multiple array range increment operations109
1225Merge Sort109
1226Divide Two Integers Leetcode Solution109
1227The kth Factor of n Leetcode Solution109
1228Check if each internal node of a BST has exactly one child108
1229Design Skiplist LeetCode Solution108
1230Check Completeness of a Binary Tree LeetCode Solution108
1231Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1232Queries on Probability of Even or Odd Number in given Ranges108
1233Flatten 2D Vector LeetCode Solution108
1234Sliding Window Median Leetcode Solution107
1235Largest Plus Sign Leetcode Solution107
1236Check if all levels of two Binary Tree are anagrams or not107
1237Check for Identical BSTs without building the trees107
1238Perfect Squares LeetCode Solution107
1239Longest Common Prefix Using Word by Word Matching107
1240Power of Two107
1241Graph Cloning107
1242Parallel Courses II LeetCode Solution107
1243Count Subsets Having Distinct Even Numbers107
1244Symmetric Tree LeetCode Solution Leetcode Solution106
1245Bold Words in String LeetCode Solution106
1246Find minimum number of merge operations to make an array palindrome106
1247Mean of range in array106
1248LRU Cache Leetcode Solution106
1249Print n terms of Newman-Conway Sequence106
1250Maximize Elements Using Another Array106
1251Maximum Array from Two given Arrays Keeping Order Same106
1252Find Minimum in Rotated Sorted Array II LeetCode Solution106
1253Count and Toggle Queries on a Binary Array106
1254Find k-th smallest element in BST (Order Statistics in BST)105
1255Contiguous Array105
1256Missing Number105
1257Next greater element104
1258Verify Preorder Serialization of a Binary Tree104
1259Minimum Remove to Make Valid Parentheses LeetCode Solution103
1260Print Ancestors of a Given Binary Tree Node Without Recursion103
1261Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1262Maximum Product Subarray103
1263Merge k Sorted Lists Leetcode Solution103
1264Excel Sheet Column Title LeetCode Solution103
1265Image Overlap LeetCode Solution103
1266Check If a String Can Break Another String Leetcode Solution103
1267Check if two nodes are on the same path in a Tree102
1268Smallest Range II Leetcode Solution102
1269Orderly Queue LeetCode Solution101
1270Palindrome Partitioning101
1271Check in binary array the number represented by a subarray is odd or even101
1272Koko Eating Bananas LeetCode Solution100
1273Newman–Shanks–Williams prime99
1274Check if X can give change to every person in the Queue99
1275Merge Sorted Array99
1276Min Cost Climbing Stairs LeetCode Solution99
1277Different Ways to Add Parentheses Leetcode Solution98
1278Peeking Iterator LeetCode Solution98
1279Number of elements less than or equal to a given number in a given subarray98
1280Range Minimum Query (Square Root Decomposition and Sparse Table)97
1281Maximum Sum Increasing Subsequence97
1282Largest Submatrix With Rearrangements LeetCode Solution97
1283Number of indexes with equal elements in given range96
1284Queries for Decimal Values of Subarrays of a Binary Array96
1285Find maximum average subarray of k length96
1286Longest Substring Without Repeating Characters Leetcode Solution95
1287Maximum product of an increasing subsequence95
1288Minimum Total Space Wasted With K Resizing Operations LeetCode Solution94
1289Array Nesting Leetcode Solution94
1290Check given array of size n can represent BST of n levels or not94
1291Arranging Coins Leetcode Solution93
1292Binary Tree to Binary Search Tree Conversion using STL set93
1293Encoded String With Shortest Length LeetCode Solution92
1294Random Pick Index LeetCode Solution92
1295Minimum Number of People to Teach LeetCode Solution92
1296Find the Winner of the Circular Game LeetCode Solution91
1297Reach a Number LeetCode Solution90
1298Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1299Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1300Queries on XOR of greatest odd divisor of the range90
1301Jump Game IV LeetCode Solution89
1302Convert to Base -2 LeetCode Solution89
1303Insert Delete GetRandom O(1) Leetcode Solution88
1304Vertical Order Traversal of Binary Tree LeetCode Solution86
1305Add Two Numbers II Leetcode Solution86
1306Palindrome Number LeetCode Solution86
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution84
1308Print Maximum Length Chain of Pairs84
1309Design Underground System Leetcode Solution83
1310Continuous Subarray Sum LeetCode Solution82
1311Detect Capital Leetcode Solution81
1312Design A Leaderboard Leetcode Solution78
1313Substring with Concatenation of All Words Leetcode Solution76
1314Minimum Swaps to Group All 1’s Together Leetcode Solution75
1315Minimum Path Sum Leetcode Solution73
1316Top K Frequent Elements LeetCode Solution73
1317Odd Even Linked List Leetcode Solution72
1318Shifting Letters LeetCode Solution71
1319Maximum Population Year LeetCode Solution70
1320Binary Tree Inorder Traversal LeetCode Solution70
1321Decode String Leetcode Solution70
1322Find the Town Judge LeetCode Solution69
1323Shortest Unsorted Continuous Subarray LeetCode Solution69
1324Count Sub Islands LeetCode Solution69
1325Best Meeting Point LeetCode Solution68
1326Longest Common Subsequence LeetCode Solution68
1327Sum Root to Leaf Numbers LeetCode Solution67
1328Find the Town Judge LeetCode Solution66
1329Design Add and Search Words Data Structure LeetCode Solution65
1330Rectangle Overlap LeetCode Solution63
1331Maximum Population Year LeetCode Solution63
1332Insert into a Sorted Circular Linked List LeetCode Solution61
1333Score of Parenthesis LeetCode Solution60
1334Stone Game IV LeetCode Solution60
1335Flatten Binary Tree to Linked List LeetCode Solution59
1336Range Sum Query 2D – Immutable LeetCode Solution59
1337Valid Triangle Number LeetCode Solution58
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution53
1340Divide Chocolate LeetCode Solution49
1341Range Sum of BST LeetCode Solution41
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution39
1343Reverse Integer Leetcode Solution38
1344Sort Colors LeetCode Solution36
1345Find K Closest Elements LeetCode Solution33
1346Excel Sheet Column Number LeetCode Solution30
1347Rotate String LeetCode Solution30
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »