Count Good Nodes in Binary Tree LeetCode Solution

Frequently asked in Amazon Bloomberg Microsoft Salesforce
DRWViews 35

Problem Statement:

Count Good Nodes in Binary Tree LeetCode Solution:

Given a binary tree root, a node X in the tree is named good if in the path from the root to X there are no nodes with a value greater than X.

Return the number of good nodes in the binary tree.


Example 1:

Count Good Nodes in Binary Tree LeetCode SolutionPin


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



Explanation: Nodes in blue are good. Root Node (3) is always a good node. Node 4 -> (3,4) is the maximum value in the path starting from the root. Node 5 -> (3,4,5) is the maximum value in the path Node 3 -> (3,1,3) is the maximum value in the path.

Example 2:

Count Good Nodes in Binary Tree LeetCode Solution:Pin


 root = [3,3,null,4,2]



Explanation:  Node 2 -> (3, 3, 2) is not good, because “3” is higher than it.

Example 3:


 root = [1]



Explanation: Root is considered as good.


  • The number of nodes in the binary tree is in the range [1, 10^5].
  • Each node’s value is between [-10^4, 10^4].



  1. This problem can be solved using the iterative way and also the recursive way. Let’s look into the recursive way as it is easy.
  2. we will traverse the right subtree and left subtree recursive manner.
  3. Update the maximum value found while recursing down to the paths from the root to the leaves.
  4. If node value >= current maximum, we will increase our cnt value.
  5. When the node will be null we will simply end our recursion call.
  6. Total cnt will be our estimated answer.


Count Good Nodes in Binary Tree C++ Code:

class Solution {
    void Count(TreeNode* root,int &count,int maxi){
        if(root==NULL) return;
        if(root->val >= maxi){count++; maxi=max(maxi,root->val);}
    int goodNodes(TreeNode* root){
        int count=0;
        int maxi=root->val;
        return count;

Count Good Nodes in Binary Tree Java Code:

class Solution {
    int cnt=0;
    void rec(TreeNode root,int val)
            return ;
        int k=Math.max(val,root.val);
    public int goodNodes(TreeNode root) {
         int val=Integer.MIN_VALUE;
        return cnt;

Complexity Analysis of Count Good Nodes in Binary Tree Leetcode Solution:

Time Complexity:

Time complexity will be O(n). Where n is the number of nodes, we are visiting every node only once.

Space Complexity:

We are not taking any extra space. So, space complexity will be O(1).

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Palindrome using Recursion2632
3Java program to find the number of Nodes in a Binary Tree2545
4Reverse a string without affecting special characters2529
5Delete a node of a linked list at given position2024
6Quick Sort1773
7Insert nodes in a linked list in a sorted way (Ascending Order)1713
8Find elements pair from array whose sum equal to number1691
9Sort Elements by Frequency of Occurrences1673
10Write a program to print all permutations of a given string1658
11Find Minimum Distance Between Two Numbers in an Array1521
12Create a Doubly Linked List1484
13Reverse an Array1466
14Smallest window in a string containing all characters of another string1441
15Recursively remove all adjacent duplicates1412
16Find a Triplet That Sum to a Given Value1395
17First Repeating Element1387
18Sum of numbers in String1368
19Arrange Even and Odd number such that Odd comes after Even1358
20Smallest Positive Number Missing in an Unsorted Array1327
21Check if the Elements of an Array are Consecutive1294
22Detect a loop in the Linked List1274
23Largest Sum Contiguous Subarray1265
24Quick Sort on SIngly Linked List1261
25Print all Possible Combinations of R Elements in a given Array of size N1253
26Recursive function to do substring search1253
27Subarray with Given Sum1250
28Find the Maximum Repeating Number in Array1208
29Find the First and Second Smallest Elements1157
30Binary Tree Level order traversal in Java1156
31Check if two linked lists are identical1145
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1116
34Find Leaders in an Array1095
35Swap nodes in the linked list1088
36Find the Number Occurring Odd Number of Times in an Array1037
37Find the second most frequent character1036
38Arrange given Numbers to Form the Biggest Number II1028
39Given a string find its first non-repeating character1018
40Find Triplet in Array With a Given Sum1004
41Given a sorted array and a number x, find the pair in array whose sum is closest to x997
42A Program to check if strings are rotations of each other or not993
43Total number of occurrences of a given item in the linked list991
44Print all possible words from phone digits977
45Find the Missing Number968
46Rearrange Positive and Negative Numbers Alternatively in Array954
47Longest Palindromic Substring948
48Segregate even and odd nodes in a linked list939
49Print Longest common subsequence928
50Transform one string to another using minimum number of given operations917
51Union and Intersection of Two Linked Lists906
52Check rearranged string can form a palindrome900
53Rearrange given Array in Maximum Minimum Form879
54Iterative Implementation of Quick Sort871
55Count Possible Triangles860
56Insertion Sort858
57Multiplication of Two Matrices847
58Count of Triplets With Sum Less than Given Value833
59Stock Buy Sell to Maximize Profit831
60Check if the linked list is palindrome830
61Rotate a Linked List829
62Concatenation of two strings808
63Count Number of Substrings with K Distinct Character’s800
64Tug of War799
65Print all duplicates in the input string799
66Find Nearest Greater and Smaller Element788
67Reverse String Without Temporary Variable779
68Find Pythagorean Triplets from Array772
69The Celebrity Problem772
70Remove ‘b’ and ‘ac’ from a given string772
71Find all Common Elements in Given Three Sorted Arrays766
72Remove all duplicates in an unsorted linked list742
73Remove Minimum Characters so that Two Strings Become Anagrams740
74Find the subarray whose sum is equal to a given number X739
75Find the Row with Maximum Number of 1’s739
76Find the Peak Element from an Array737
77Addition of Two Matrices731
78Generate all Binary Strings Without Consecutive 1’s728
79Find Smallest Missing Number in a Sorted Array727
80A Product Array Puzzle725
81Maximum Sum of Non Consecutive Elements713
82Implement Two Stacks in an Array709
83Lexicographic rank of string702
84Check if Two given Matrices are Identical693
85Maximum Product Subarray II690
86Multiplication of Previous and Next684
87Subtraction of Two Matrices678
88Merge K Sorted Arrays and Print Sorted Output671
89Move All the Zeros to the End of the Given Array668
90Divide a string in N equal parts667
91Online Algorithm for Checking Palindrome in a Stream667
92Form Minimum Number from Given Sequence of D’s and I’s666
93Check whether two strings are anagram of each other661
94Remove recurring digits in a given number659
95Sort a stack using a temporary stack657
96Maximum Circular Subarray Sum652
97Sort a linked list that is sorted alternating ascending and descending647
98Subarray and Subsequence640
99Find the Minimum Element in a Sorted and Rotated Array639
100Move last element of the Linked List at first place637
101First Circular Tour to Visit all the Petrol Bunks635
1023Sum Leetcode Solution635
103Compare two strings(linked lists)631
104Palindrome Permutations of a String631
105Maximum Element in an Array which is Increasing and then Decreasing629
106Largest Subarray with Equal Number of 0’s and 1’s627
107Palindromes in a given range625
108Flattening a linked list624
109Run length encoding620
110Minimum insertions to form a shortest palindrome620
111Pangram Checking619
112Majority Element619
113Print all permutations with repetition617
114Elements Appear more than N/K times in Array612
115Minimum Characters to be Added at Front to Make String Palindrome612
116Most repeating character in a string609
117Two Sum Leetcode Solution607
118Repeated Subsequence of Length Two or More607
119Rotate string to get lexicographically minimum string604
120Remove all duplicates in a sorted linked list597
121Merge a linked list into another at alternate positions597
122Rearrange a given linked list in-place597
123Minimum number of Merge Operations to make an Array Palindrome595
124Print all anagrams together in a sequence of words595
125Reorder an Array According to the Given Indexes583
126Pancake Sorting Problem582
127Transpose of a Matrix571
128Merge Overlapping Intervals II570
129Smallest Palindrome after Replacement570
130Longest Palindrome can be Formed by Removing or Rearranging Characters568
131Remove duplicates from a string568
132Clone a Linked List with next and random pointer568
133Remove Extra Spaces from a String566
134Removing Spaces from a String using stringstream564
135Check if a given string is a rotation of a palindrome561
136Maximum Sum Increasing Subsequence560
137Size of The Subarray With Maximum Sum559
138Partition Problem556
139Check whether Strings are K Distance Apart or Not550
140Generate all Binary Strings from Given Pattern547
141Delete Last Occurrence546
142Length of Longest valid Substring543
143Check if Two given Strings are Isomorphic to each other541
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized539
145Program to Toggle all Characters in a String533
146Insert Node in the Sorted Linked List533
147Given string is interleaving of two other strings or not528
148Maximum difference between two elements such as larger element comes after smaller527
149Check length of a String is Equal to the Number Appended at its Last518
150Count Minimum Steps to Get the given Array516
151Check if all Rows of a Matrix are Circular Rotations of Each Other514
152Number of Smaller Elements on Right Side512
153Find Pair with Given Difference509
154Longest Common Prefix using Divide and Conquer509
155Merge sort better than quick sort for linked lists506
156Compare Two Version Numbers504
157Print all interleavings of given two strings502
158Find nth node of the Linked list from the end501
159Sort 0s 1s and 2s in an Array499
160Find a Fixed Point in a Given Array498
161Print Reverse of a string (Recursion)498
162Median of Two Sorted Arrays LeetCode Solution497
163Reorder Array Using Given Indexes495
164Reverse words in a given string494
165Merge two sorted linked lists such that merged list is in reverse order487
166Find the Subarray of given length with Least Average486
167Split linked list using alternate nodes485
168Print all Palindromic Partitions of a String479
169Print string of odd length in ‘X’ format478
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average468
172Swap Kth Node from beginning with Kth Node from End466
173Find Duplicates in an Array in Most Efficient Way464
174Shortest Superstring Problem459
175Check if String Follows Order of Characters by a Pattern or not458
176print all palindromic partitions458
177Maximum Length of Chain Pairs451
178Sort a String According to Another String450
179Flatten a multilevel linked list447
180Sorting a K Sorted Array443
181Program to add two binary digits439
182Recursively print all the sentences that can be formed from list of word lists434
183Caesar Cipher434
184Find a Sorted Subsequence of size 3430
185Longest Span with same Sum in two Binary Arrays II429
186Longest Common Prefix Using Binary Search II429
187Reverse a Linked List in groups429
188Find the two Numbers with Odd Occurrences in an Unsorted Array428
189Kth Non-repeating Character426
190Reverse a Singly Linked List (Iterative/Non-Recursive)424
191Check if String can Become Empty by Recursively Deleting given Substring421
192Longest Common Prefix Word by Word Matching416
193Rearrange a linked list in Zig-Zag412
194Rotate Image by 90 degrees410
195Pancake Sorting409
196Permutations of a Given String Using STL408
197Perfect Reversible String408
198Merging Two Sorted Arrays407
199Find First non-repeating character in a string406
200Maximum occurring character in a string402
2011`s and 2`s complement of binary number402
202Increasing Subsequence of Length three with Maximum Product399
203List items containing all characters of a given word397
204Find the point where a monotonically increasing function becomes positive first time396
205Four Elements that Sum to Given392
206Sort a linked list with 0s, 1s and 2s390
207Longest Common Prefix using Character by Character Matching390
208Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes389
209Valid Parentheses LeetCode Solution386
210Palindrome string (number)386
211Count Number of Occurrences in a Sorted Array386
212Delete N nodes after M382
213Minimum Characters to be Removed to Make a Binary String Alternate381
214Even Substring Count380
215Split a string378
216Recursive Implementation of atoi()377
217Sorting the array of strings375
218Print Shortest Path to Print a String on Screen371
219Convert a String that is Repetition of a Substring of Length K371
220Nth Character in Concatenated Decimal String368
221Check if a Linked list of Strings form a Palindrome367
222Maximum Subarray Leetcode Solution366
223Convert string1 to string2 in one edit364
224Count the number of words362
225Print All Distinct Elements of the Array362
226Reverse a String using Stack362
227Reverse a singly linked list recursively361
228wildcard character matching361
229Matrix Chain Multiplication using Dynamic Programming360
230Find the first Repeating Number in a Given Array360
231Lower Case To Upper Case356
232Can we reverse a linked list in less than O(n) time ?353
233Binary Tree to Doubly linked list350
234Sort Elements by Frequency II349
235Longest Common Subsequence with Permutations348
236Find the Lost Element From a Duplicated Array346
237Split Four Distinct Strings344
238Merge Two Sorted Arrays343
239Roman to Integer Leetcode Solution340
240Move all negative elements to one side of array339
241Find middle of the Linked List339
242Count the Pairs at Same Distance as in English Alphabets338
243Toeplitz Matrix335
244N queen problem332
245Palindrome Permutation330
246Word Search Leetcode Solution327
247Next Greater Element in an Array326
248Sudoku Solver325
249First non Repeating Element322
250Find All Pairs With a Given Difference320
251Count Pairs With Given Sum319
252Reverse Bits319
253Print all Possible Ways to Break a String in Bracket Form318
254Searching a node in a Binary Search Tree318
255Number of Islands LeetCode Solution317
256Fibonacci numbers317
257Find Nth Node317
258String(represents an integer) to value317
259Repeated Substring Pattern315
260Change Gender of a given String314
261Reverse a String314
262Types of Binary Tree314
263Triplet from three linked lists with given sum313
264Sort an array of strings312
265Reverse a linked list312
266Delete a Tree311
267Min Stack311
268How to Efficiently Implement k Stacks in a Single Array?311
269Number of sub-strings which recursively add up to 9310
270Most Frequent Element in an Array310
271Meeting Rooms II LeetCode Solution309
272Delete a node under given conditions309
273Cuckoo sequence program308
274Longest Palindromic Substring LeetCode Solution308
275Dijkstra Algorithm305
276Remove spaces from a string304
277Longest Common Extension302
278House Robber Leetcode Solution301
279Binary Tree301
280Max stack301
281Subset Leetcode295
282Word Search295
283Sliding Window Technique294
284Best Time to Buy and Sell Stock  II Leetcode Solution293
285Shuffle a given Array292
286Remove middle points in a linked list of line segments292
287Number Of 1 bits290
288KMP Algorithm290
289Minimize the maximum difference between the heights290
290Expression Evaluation289
291Find, second, frequent, character289
292Plus One Leetcode Solution288
293Search Insert Position Leetcode Solution287
294Combination Sum Leetcode Solution286
295Pair of Positive Negative Values in an Array286
296Evaluation of Postfix Expression286
297Reverse words in a string285
298Min Stack Leetcode Solution280
299Set Matrix Zeroes279
300Valid Palindrome Leetcode Solution279
301Rabin Karp Algorithm279
302Subarray with 0 sum279
303Backspace String Compare278
304Common elements in all rows of a given matrix276
305Sort linked which is sorted on absolute values275
306Clone a linked list with next and random pointer (Hashing)272
307Merge Sorted Arrays Leetcode Solution272
308Reversing a Queue271
309Sqrt(x) Leetcode Solution271
310Delete middle element of a stack270
311Implementation of Deque using Doubly Linked List270
312Find Top K (or Most Frequent) Numbers in a Stream270
313Contains Duplicate270
314Tower Of Hanoi269
315Count Odd Numbers in an Interval Range Leetcode Solution268
316Count subarrays with equal number of 1’s and 0’s268
317String Compression267
318Product of array except self266
319Combination Sum266
320Intersection of Two Arrays II Leetcode Solution266
321Pascal Triangle Leetcode265
322Contains Duplicate II Leetcode Solution265
323Page Replacement Algorithms in Operating Systems265
324Count of index pairs with equal elements in an array265
325How to Delete a Linked List265
326Reverse individual words265
327Minimum swaps required to bring all elements less than or equal to k together264
328Segregate even and odd numbers263
329Group Words With Same Set of Characters262
330Find sum of non-repeating elements (distinct) elements in an array262
331Single Number Leetcode Solution262
332Second Most Repeated Word in a Sequence262
333Count subarrays having total distinct elements same as original array261
334Integer to Roman Leetcode Solution261
335Sum of minimum and maximum elements of all subarrays of size k260
336Postfix to Infix Conversion260
337Smallest Subarray with k Distinct Numbers260
338Given two unsorted arrays find all pairs whose sum is x260
339Bellman Ford Algorithm260
340Minimum Value to Get Positive Step by Step Sum Leetcode Solution259
341Sorting array using Stacks259
342Next Permutation259
343Sort elements by frequency259
344Arithmetic Expression Evaluation258
345K-th Smallest Element in a Sorted Matrix258
346Top K Frequent Words256
347Convex Hull Algorithm256
348First element occurring k times in an array256
349Add Binary Leetcode Solution256
350Maximum Number of Balloons Leetcode Solution255
351Minimum operation to make all elements equal in array255
352Construct Binary Tree from Given Inorder and Preorder Traversals255
353Longest Common Prefix Leetcode Solution254
354Design a stack that supports getMin() in O(1) time and O(1) extra space254
355Longest Substring Without Repeating Characters LeetCode Solution253
356Scramble String253
357Pow(x, n) Leetcode Solution253
358Palindrome Linked List Leetcode Solution252
359Special Number252
360Kruskal Algorithm250
361Majority Element Leetcode Solution250
362Evaluate Division250
363Find duplicates in a given array when elements are not limited to a range250
364Reversing the First K elements of a Queue250
365Check if two arrays are equal or not250
366Find Lucky Integer in an Array Leetcode Solution250
367Running Sum of 1d Array Leetcode Solution248
368Permutations Leetcode Solution248
369Maximum possible difference of two subsets of an array247
370Third Maximum Number Leetcode Solution247
371Fizz Buzz Leetcode245
372Minimum Path Sum245
373Huffman Coding245
374Maximum Distance Between two Occurrences of Same Element in Array245
375Spiral Matrix LeetCode Solution245
376Smallest Element Repeated Exactly K Times245
377Find the Town Judge Leetcode Solution244
378Number of Good Pairs Leetcode Solution244
379Maximal Square244
380Group Anagrams244
381Find the first repeating element in an array of integers244
382Maximum Subarray244
383Prefix to Infix Conversion244
384Find the Closest Palindrome number243
385Find Numbers with Even Number of Digits Leetcode Solution243
386Convert String To Int243
387Reverse a Number Using Stack243
388Range Sum Query 2D – Immutable Leetcode Solution243
389Minimum Steps to reach target by a Knight242
390Palindrome Substring Queries242
391Count Primes Leetcode Solutions242
392Swap Nodes in Pairs Leetcode Solutions242
393Unique Paths241
394Find top three repeated in array241
395Cumulative Frequency of Count of Each Element in an Unsorted Array241
396Sorting using trivial hash function241
397Minimum Absolute Difference Leetcode Solution241
398Find All Numbers Disappeared in an Array Leetcode Solution240
399Zigzag Conversion240
400Single Number240
401Print all subarrays with 0 sum239
402Remove Minimum Number of Elements Such That no Common Element Exist in both Array239
403Find Number of Employees Under every Employee239
404Expression Contains Redundant Bracket or Not238
405Fizz Buzz238
406Check if Array Contains Contiguous Integers With Duplicates Allowed238
407Pascal’s Triangle II Leetcode Solution238
408Implement Stack and Queue using Deque238
409Sort Array by Increasing Frequency Leetcode Solution238
410Difference between highest and least frequencies in an array237
411Print All Distinct Elements of a Given Integer Array237
412Bipartite Graph237
413How to Implement Stack Using Priority Queue or Heap?237
414Count Substrings with equal number of 0s, 1s and 2s237
415Power of Two Leetcode Solution237
416Leetcode Permutations237
417Matrix Diagonal Sum Leetcode Solution236
418Missing Number Leetcode Solution236
419Subarray Sum Equals k236
420Letter Case Permutation236
421Length of the largest subarray with contiguous elements236
422Sort Integers by The Number of 1 Bit Leetcode Solution235
423Unique Paths Leetcode Solution235
424Subset sum problem235
425Prim’s Algorithm235
426Sort a stack using recursion235
427Decode String235
428LRU Cache Implementation235
429Merge Two Sorted Lists Leetcode Solutions235
430House Robber II Leetcode Solution234
431Maximum Depth of Binary Tree Leetcode Solution234
432Happy Number Leetcode Solution233
433Top K Frequent Elements233
434Reverse Integer233
435Find Median from data Stream233
436Subarrays with distinct elements233
437Find all pairs (a, b) in an array such that a % b = k233
438Nth Catalan Number232
439Search in Rotated Sorted Array Leetcode Solution232
440Find Winner on a Tic Tac Toe Game Leetcode Solution231
441Count pairs from two linked lists whose sum is equal to a given value231
442Coin Change 2 Leetcode Solution231
443Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution231
444Pair with given product230
445Max Consecutive Ones Leetcode Solution230
446Monotonic Array LeetCode Solution230
447How Many Numbers Are Smaller Than the Current Number Leetcode Solution229
448Find elements which are present in first array and not in second229
449Check If N and Its Double Exist Leetcode Solution229
450Capacity To Ship Packages Within D Days Leetcode Solution229
451Valid Parenthesis String228
452Intersection of Two Arrays228
453Find the Difference Leetcode Solution228
454Edit Distance228
455Priority Queue Using Singly Linked List228
456Integer to English words228
457Find The Duplicate Number228
458Reverse a String228
459Reverse a Stack Using Recursion228
460Fibonacci Number LeetCode Solution227
461Find distinct elements common to all rows of a matrix227
462Longest subarray not having more than K distinct elements227
463Find any one of the multiple repeating elements in read only array227
464Find Minimum In Rotated Sorted Array227
465Floyd Warshall Algorithm227
466Find Index of Closing Bracket for a Given Opening Bracket in an Expression227
467Find Common Characters Leetcode Solution227
468Count and Say227
469Subarray Sum Equals K LeetCode Solution227
470Trapping Rain Water Leetcode Solution227
471Subtract the Product and Sum of Digits of an Integer Leetcode Solution227
472Text Justification LeetCode Solution226
473Find four elements that sum to a given value (Hashmap)226
474Reverse Vowels of a String Leetcode Solution226
475Sum of Subarray Ranges Leetcode Solution226
476Check if a given array contains duplicate elements within k distance from each other225
477Longest Common Prefix using Trie225
478Best Time to Buy and Sell Stock III Leetcode Solution225
479Rearrange a binary string as alternate x and y occurrences225
480Kth largest element in an Array Leetcode Solutions224
481Jump Game Leetcode Solution224
482The K Weakest Rows in a Matrix Leetcode Solution224
483Generate a String With Characters That Have Odd Counts Leetcode Solution224
484Target Sum224
485Design Parking System Leetcode Solution224
486Remove Duplicates from Sorted Array Leetcode Solution224
487MiniMax Algorithm223
488Check for Balanced Parentheses in an Expression223
489Find subarray with given sum (Handles Negative Numbers)223
490Delete a Node from linked list without head pointer223
491The Stock Span Problem223
492Iterative Tower of Hanoi222
493Largest Sum Contiguous Subarray222
494Find missing elements of a range222
495Prefix to Postfix Conversion222
496Multiply Strings Leetcode Solution222
497Shortest Palindrome222
498Substring With Concatenation Of All Words221
499Count number of triplets with product equal to given number221
500Valid Sudoku220
501Degree of an array220
502Top View of Binary Tree220
503K-th Distinct Element in an Array220
504Shuffle the Array Leetcode Solution220
505Priority Queue in C++220
506Word Ladder LeetCode Solution220
507Longest Common Prefix using Sorting220
508Shuffle String Leetcode Solution220
509Iterative Inorder Traversal of a Binary Tree220
510Sorting a Queue without Extra Space220
511Max Area of Island219
512Slowest Key Leetcode Solution219
513Flood Fill LeetCode219
514Implement Stack using Queues219
515Container with Most Water219
517Minimum Knight Moves LeetCode Solution219
518Peak Index in a Mountain Array219
519Balanced Binary Tree Leetcode Solution219
520Number of Steps to Reduce a Number to Zero Leetcode Solution219
521Best Time to Buy and Sell Stock LeetCode Solution218
522Next Greater Element I Leetcode Solution218
523Implement a stack using single queue218
524Merge Two Sorted Linked Lists218
525Excel Sheet Column Number Leetcode Solution218
526Next Greater Frequency Element218
527Kids With the Greatest Number of Candies Leetcode Solution218
528Count and Say Leetcode Solution217
529Smallest Subarray With all Occurrences of a Most Frequent Element217
530Arrange given numbers to form the biggest number217
531Find the Duplicate Element217
532Maximum sum rectangle in a 2D matrix217
533Concatenation of Array LeetCode Solution217
534Minimum Delete Operations to make all Elements of Array Same217
535Find First and Last Position of Element in Sorted Array Leetcode Solution217
536Hamming Distance217
537Sum of Left Leaves Leetcode Solutions217
538Convert array into Zig-Zag fashion217
539Longest Common Subsequence217
540Reverse Words in a String III LeetCode Solution217
541Jewels and Stones Leetcode Solution217
542Postfix to Prefix Conversion217
543Move Zeroes LeetCode Solution217
544Find Sum of all unique sub-array sum for a given array216
545How to check if two given sets are disjoint?216
546Linked List Cycle II LeetCode Solution216
547Change the Array into Permutation of Numbers From 1 to N216
548Check if a queue can be sorted into another queue using a stack215
549Shuffle an Array215
550Kth Largest Element in a Stream Leetcode Solution215
551Count the number of nodes at given level in a tree using BFS215
552Minimum Moves to Equal Array Elements Leetcode Solution215
553Group Multiple Occurrence of Array Elements Ordered by first Occurrence214
554Gold Mine Problem214
555N-th Tribonacci Number Leetcode Solution214
556Zigzag Conversion LeetCode Solution214
557Largest Perimeter Triangle Leetcode Solution214
558Valid Anagrams214
559Isomorphic Strings Leetcode Solution213
560Convert a normal BST to Balanced BST213
561Merge Overlapping Intervals213
562Contiguous Array Leetcode213
563Minimum number of subsets with distinct elements212
564Delete Node in a Linked List Leetcode Solution212
565Minimum Bracket Reversals212
566Excel Sheet Column Title Leetcode Solution212
567Find N Unique Integers Sum up to Zero Leetcode Solution212
568Is Subsequence Leetcode Solution212
569Sieve of Eratosthenes212
570Summary Ranges Leetcode Solution211
571Integer to Roman211
572Minimum Cost to Hire K Workers211
573Maximum Distance in Array211
574Last Stone Weight211
575Find if an Expression has Duplicate Parenthesis or Not211
576Mobile Numeric Keypad Problem210
577Maximum path sum in a triangle210
578Word Pattern210
579Koko Eating Bananas Leetcode Solution210
580Smallest Good Base210
581Length of Last Word Leetcode Solution209
582Number of Provinces Leetcode Solution209
583Build Array From Permutation Leetcode Solution209
5843Sum Closest LeetCode Solution209
585Maximum difference between first and last indexes of an element in array209
586Implementation of Deque using circular array209
587Best Time to Buy and Sell Stock209
588Longest Increasing Subsequence209
589Non-overlapping sum of two sets209
590Shortest Path in a Grid with Obstacles Elimination LeetCode Solution209
591Find Words That Can Be Formed by Characters Leetcode Solution208
592Distribute Candies to People Leetcode Solution208
593Frog Jump Leetcode Solution208
594Delete consecutive same words in a sequence208
595Rotate Image LeetCode Solution208
596Relative Sort Array Leetcode Solution208
597Maximum Number of Occurrences of a Substring Leetcode Solution208
598Decode Ways208
599Combinations Leetcode Solution208
600Trapping Rain Water LeetCode Solution207
601Remove All Occurrences of a Substring LeetCode Solution207
602Island Perimeter Leetcode Solution207
603Sort Characters By Frequency LeetCode Solution207
604First negative integer in every window of size k207
605Iterative Method to find Height of Binary Tree207
60601 Matrix LeetCode Solution207
607Minimum Operations to convert X to Y207
608Remove Linked List Elements Leetcode Solution206
609Sum of f(a[i], a[j]) over all pairs in an array of n integers206
610LRU Cache LeetCode Solution206
611Minimum number of distinct elements after removing m items205
612GCD Of Two Numbers205
613Maximum Number of Chocolates to be Distributed Equally Among k Students205
614Minimum insertions to form a palindrome with permutations allowed205
615Find minimum difference between any two elements205
616The Knapsack Problem205
617Reverse a stack without using extra space in O(n)205
618Bubble sort using two Stacks204
619Assign Cookies Leetcode Solution204
620Find the smallest positive integer value that cannot be represented as sum of any subset of a given array204
621Rotate List Leetcode Solution204
622Count all subsequences having product less than K204
623XOR Operation in an Array Leetcode Solution204
624Tracking current Maximum Element in a Stack203
625Permutation in String Leetcode Solution203
626Isomorphic Strings203
627Unique Binary Search Trees203
628Reorganize String203
629How to Create Mergable Stack?203
630Convert an array to reduced form203
631Insert Interval Leetcode Solution203
632Convert Sorted Array to Binary Search Tree Leetcode Solution202
633Form minimum number from given sequence202
634K Empty Slots202
635Find Largest d in Array such that a + b + c = d202
636Stone Game LeetCode202
637Longest Increasing Path in a Matrix LeetCode Solution202
638Find the Duplicate Number LeetCode Solution202
639Employee Free Time LeetCode Solution201
640Distance Between Bus Stops Leetcode Solution201
641Find Pair with Greatest Product in Array201
642Same Tree LeetCode Solution201
643Largest subarray with equal number of 0s and 1s201
644Defanging an IP Address Leetcode Solution201
645Applications of Breadth First Search and Depth First Search201
646Count Good Nodes in Binary Tree Leetcode Solution200
647License Key Formatting Leetcode Solution200
648Optimal Account Balancing LeetCode Solution200
649First Unique Character in a String LeetCode Solution200
650Find the node with minimum value in a Binary Search Tree200
651Maximum Consecutive Numbers Present in an Array199
652Valid Palindrome199
653Minimum Depth of Binary Tree Leetcode Solution199
654Word Wrap Problem199
655Letter Combinations of a Phone Number199
656Convert a Number to Hexadecimal Leetcode Solution199
657Printing brackets in Matrix Chain Multiplication Problem199
658Merge Two Balanced Binary Search Trees199
659Coin Change Problem199
660Robot Room Cleaner Leetcode Solution198
661Find pairs with given sum such that elements of pair are in different rows198
662Replace Elements with Greatest Element on Right Side Leetcode Solution198
663Longest Span with same Sum in two Binary arrays198
664Painting Fence Algorithm197
665Check If It Is a Straight Line Leetcode Solution197
666Numbers with prime frequencies greater than or equal to k197
667Find the Distance Value Between Two Arrays Leetcode Solution197
668House Robber197
669Flipping an Image LeetCode Solution197
670Longest Substring with At Most K Distinct Characters LeetCode Solution197
671Kth Missing Positive Number Leetcode Solution197
672Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions197
673K Empty Slots LeetCode197
674Sort Array By Parity LeetCode Solution197
675Reducing Dishes LeetCode Solution196
676Partition Labels LeetCode Solution196
677String to Integer (atoi) LeetCode Solution196
678Distance of nearest cell having 1 in a binary matrix196
679k-th missing element in increasing sequence which is not present in a given sequence196
680Number of Dice Rolls With Target Sum LeetCode Solution196
681Strobogrammatic Number LeetCode Solution196
682Moving Average from Data Stream Leetcode Solution196
683Count quadruples from four sorted arrays whose sum is equal to a given value x196
684Segregate 0s and 1s in an Array196
685Maximum Product of Two Elements in an Array Leetcode Solution196
686Reservoir Sampling196
687Print the Fibonacci numbers in reverse order195
688String Compression LeetCode Solution195
689Longest Substring with At Least K Repeating Characters LeetCode Solution195
690Valid Palindrome II Leetcode Solution195
691Power of Four Leetcode Solution195
692Generate all possible sorted arrays from alternate elements of two given sorted arrays195
693Dynamic Programming Basics194
694Reverse Only Letters LeetCode Solution194
695Queries for counts of array elements with values in given range194
696Partition Array Into Three Parts With Equal Sum Leetcode Solution194
697Find Maximum Level sum in Binary Tree194
698Find unique character in a string194
699Find Leaves of Binary Tree LeetCode Solution194
700Find the largest multiple of 3193
701Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest193
702Remove Invalid Parentheses Leetcode Solution193
703Snakes and Ladders LeetCode Solution193
704Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
705Binary Tree Maximum Path Sum LeetCode Solution193
706Increasing Decreasing String Leetcode Solution193
707Find whether an array is subset of another array193
708Sum of All Odd Length Subarrays Leetcode Solution193
709Remove brackets from an algebraic string containing + and – operators192
710Check for Palindrome after every character replacement Query192
711Path With Maximum Minimum Value LeetCode Solution192
712Unique Paths II Leetcode Solution192
713To Lower Case Leetcode Solution192
714Stack Permutations (Check if an array is stack permutation of other)192
715Growable array based stack192
716Elements to be added so that all elements of a range are present in array192
717Check If Two String Arrays are Equivalent Leetcode Solution192
718Find the Smallest Divisor given a Threshold Leetcode Solution192
719Wiggle Sort192
720Find Maximum Depth of Nested Parenthesis in a String191
721Lucky Numbers in a Matrix Leetcode Solution191
722Sort Array by Increasing Frequency Leetcode Solution191
723Edit Distance LeetCode Solution191
724Inorder Successor of a node in Binary Tree191
725Valid Perfect Square Leetcode Solution191
726Keyboard Row Leetcode Solution191
727Bulb Switcher LeetCode Solution191
728Binary Tree zigzag level order Traversal191
729Populating Next Right Pointers in Each Node191
730Maximum Number of Coins You Can Get Leetcode Solution191
731Merge Sorted Array LeetCode Solution190
732Base 7 Leetcode Solution190
733Minimum Cost For Tickets Leetcode Solution190
734String comparison containing wildcards190
735BFS vs DFS for Binary Tree190
736Non-decreasing Array LeetCode Solution190
737Majority Element II Leetcode Solution190
738Valid Number190
739Number of NGEs to the Right190
740Merge Two Binary Trees LeetCode Solution190
741Factorial Trailing Zeroes Leetcode Solution190
742Priority Queue using doubly linked list190
743Recover Binary Search Tree190
744Reversing a Queue using Recursion190
745Subset Sum Leetcode190
746Race Car LeetCode Solution190
747Ugly Number Leetcode Solution190
748Binary Tree Zigzag Level Order Traversal LeetCode Solution190
749Delete Nth node from the end of the given linked list190
750Permutation Sequence LeetCode Solution190
751Print a Binary Tree in Vertical Order189
752Tiling Problem189
753Maximum Length of a Concatenated String with Unique Characters Leetcode Solution189
754Perform String Shifts Leetcode189
755Find if Path Exists in Graph Leetcode Solution189
756Student Attendance Record I Leetcode Solution188
757Check if Two Expressions With Brackets are Same188
758Program for Bridge and Torch problem188
759Finding K closest element188
760Maximum 69 Number Leetcode Solution188
761Morris Traversal188
762Regular Expression Matching188
763Minimum sum of multiplications of n numbers188
764Restore IP Addresses Leetcode Solution188
765Maximum Profit in Job Scheduling Leetcode Solution188
766Longest Subarray Having Count of 1s One More than Count of 0s188
767Count items common to both the lists but with different prices188
768Best Meeting Point LeetCode Solution188
769Maximum Product of Three Numbers LeetCode Solution187
770Partition to K Equal Sum Subsets Leetcode Solution187
771Number of Days Between Two Dates LeetCode Solution187
772Add and Search Word – Data structure design LeetCode187
773Construct BST from given Preorder Traversal187
774N-Queens LeetCode Solution187
775Word Pattern LeetCode Solution187
776Circular Queue187
777Minimum Distance Between BST Nodes Leetcode Solution187
778Split a String in Balanced Strings Leetcode Solution187
779Evaluate Reverse Polish Notation LeetCode Solution187
780Check If Array Pairs Are Divisible by k LeetCode Solution186
781Minimum Time Visiting All Points Leetcode Solution186
782Sort an array according to the order defined by another array186
783Minimum Height Trees186
784Binomial Coefficient186
785Find All Duplicates in an Array LeetCode Solution186
786Top K Frequent Words LeetCode Solution186
787Find Median from Data Stream LeetCode Solution186
788Jump Game186
789Hamming Distance Leetcode Solution186
790Symmetric Tree Leetcode Solution186
791Rank Transform of an Array Leetcode Solution186
792Form Minimum Number From Given Sequence186
793Decompress Run-Length Encoded List Leetcode Solution186
794Largest Rectangle in Histogram LeetCode Solution186
795Find All Possible Recipes from Given Supplies LeetCode Solution185
796Invert Binary Tree LeetCode Solution185
797Minimize Maximum Pair Sum in Array LeetCode Solution185
798Maximum Depth of N-ary Tree Leetcode Solution185
799Sorted Linked List to Balanced BST185
800Brick Wall LeetCode Solution185
801Nested List Weight Sum II LeetCode Solution185
802Total Numbers With no Repeated Digits in a Range184
803Linked List Cycle184
804Maximum Nesting Depth of the Parentheses Leetcode Solution184
805Merge K Sorted Linked Lists184
806Find all permuted rows of a given row in a matrix184
807Special Array With X Elements Greater Than or Equal X Leetcode Solution184
808Identify and Mark Unmatched Parenthesis in an Expression184
809Queue based approach for first non-repeating character in a stream184
810Search in a Binary Search Tree Leetcode Solution184
811Largest rectangular sub-matrix whose sum is 0183
812Balanced Expression with Replacement183
813Crawler Log Folder Leetcode Solution183
814Remove Nth Node From End of List Leetcode Solution183
815Nearest Exit from Entrance in Maze LeetCode Solution183
816Number of Islands II LeetCode Solution183
817Kth ancestor of a node in binary tree183
818Maximum Difference Between Increasing Elements LeetCode Solution182
819Minimum Swaps to Make Strings Equal Leetcode Solution182
820Course Schedule II – LeetCode182
821Interval Tree182
822Transpose Graph182
823Minimum time required to rot all oranges182
824Given an Array of Pairs Find all Symmetric Pairs in it182
825Repeated Substring Pattern LeetCode Solution182
826Split Array Into Consecutive Subsequences182
827Diagonal Traversal of Binary Tree182
828Relative Ranks Leetcode Solution182
829One Edit Distance LeetCode Solution182
830A Space Optimized DP solution for 0-1 Knapsack Problem181
831Find Maximum Sum Possible Equal Sum of Three Stacks181
832Brightest Position on Street LeetCode Solution181
833Final Prices With a Special Discount in a Shop Leetcode Solution181
834Deletion in a Binary Tree181
835Insert Delete GetRandom181
836Minimum Number of Taps to Open to Water a Garden LeetCode Solution181
837Permutation Coefficient181
838Lemonade Change Leetcode Solution180
839Subsequence of Size K With the Largest Even Sum LeetCode Solution180
840Check if stack elements are pairwise consecutive180
841Search a 2D Matrix II Leetcode Solution180
842Remove Duplicates from Sorted List II180
843Reorder Data in Log Files LeetCode Solution180
844Subarray Product Less Than K LeetCode Solution180
845Tree Traversal (Preorder, Inorder & Postorder)180
846Design Browser History LeetCode Solution180
847Last Stone Weight II LeetCode Solution180
848Path with maximum average value180
849LCS (Longest Common Subsequence) of three strings179
850Sort Array By Parity II Leetcode Solution179
851Binary Search Tree Search and Insertion179
852Sliding Window Maximum179
853Minimum Jumps to Reach Home LeetCode Solution179
854Clone Graph LeetCode Solution179
855Missing Element in Sorted Array LeetCode Solution179
856Iterative Postorder Traversal Using Two Stacks179
857Least Number of Unique Integers after K Removals Leetcode Solution179
858Iterative Preorder Traversal179
859Valid Parentheses Leetcode Solution179
860Check if an Array is Stack Sortable179
861Distinct adjacent elements in an array179
862Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
863Check if a given array can represent Preorder Traversal of Binary Search Tree179
864Remove Duplicates from Sorted List LeetCode Solution179
865Minimum Sum Path in a Triangle179
866Number Complement Leetcode Solution179
867Find the Only Repetitive Element Between 1 to N-1179
868Daily Temperatures Leetcode Solution179
869Range LCM Queries178
870Can Place Flowers LeetCode Solution178
871Alien Dictionary LeetCode Solution178
872Matrix Chain Multiplication178
873Median of Two Sorted Arrays178
874Maximum Score After Splitting a String Leetcode Solution178
875Spiral Matrix II Leetcode Solution178
876Sort Colors178
877Minimum number of jumps to reach end178
878Sum of nearest smaller and greater number178
879Guess Number Higher or Lower LeetCode Solution178
880Minimum swaps to make sequences increasing177
881Convert BST to Min Heap177
882Count Distinct Elements in Every Window of Size K177
883Union and Intersection of two Linked Lists177
884Dividing Array into Pairs With Sum Divisible by K177
885Get Maximum in Generated Array Leetcode Solution177
886Friends Pairing Problem177
887An Interesting Method to generate Binary Numbers from 1 to n177
888Find distance between two nodes of a Binary Tree177
889Partition List Leetcode Solution177
890Diagonal Traverse LeetCode Solution177
891Maximum size subarray sum equals k177
892Find all triplets with zero sum177
893Count Negative Numbers in a Sorted Matrix LeetCode Solution177
894Infix to Postfix176
895Minesweeper LeetCode Solution176
896Water Bottles Leetcode Solution176
897Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i176
898Count Submatrices With All Ones LeetCode Solution176
899Level order Traversal in Spiral Form176
900Diagonal Traversal LeetCode Solution176
901Design a Stack With Increment Operation Leetcode Solution176
902GCDs of given index ranges in an array176
903Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution176
904A program to check if a binary tree is BST or not176
905Subset with sum divisible by m176
906Sorted Array to Balanced BST176
907Find the subarray with least average176
908Sequences of given length where every element is more than or equal to twice of previous176
909Check whether a given Binary Tree is Complete or not176
910Count ways to reach the nth stair using step 1, 2 or 3176
911Check if any two intervals overlap among a given set of intervals175
912Time Based Key-Value Store LeetCode Solution175
913Delete And Earn175
914Binary array after M range toggle operations175
915Pattern Occurrences using Stack175
916Insert into a Binary Search Tree Leetcode Solution175
917Number of Distinct Islands Leetcode Solution175
918Three way partitioning of an array around a given range174
919Destination City Leetcode Solution174
920Range sum queries without updates174
921Binary Tree Longest Consecutive Sequence LeetCode Solution174
922Convert Sorted List to Binary Search Tree174
923Construct the Rectangle Leetcode Solution174
924Guess Number Higher or Lower II174
925All Unique Triplets that Sum up to a Given Value174
926Averages of Levels in Binary Tree174
927Number of Equivalent Domino Pairs Leetcode Solution173
928Check if the given array can represent Level Order Traversal of Binary Search Tree173
929Queue using Stacks173
930Rearrange Spaces Between Words Leetcode Solution173
931Longest Palindromic Subsequence173
932Shortest Word Distance Leetcode Solution173
933K’th Largest Element in BST when modification to BST is not allowed173
934Rearrange an Array Such that arr[i] is equal to i173
935Product of Array Except Self LeetCode Solution173
936Set Matrix Zeroes Leetcode Solution173
937Trim a Binary Search Tree173
938Robot Bounded In Circle LeetCode Solution173
939Lexicographical Numbers Leetcode Solution173
940Queries for GCD of all numbers of an array except elements in a given range172
941Special Positions in a Binary Matrix Leetcode Solution172
942Analyze User Website Visit Pattern LeetCode Solution172
943Alien Dictionary172
944Construct Complete Binary Tree from its Linked List Representation172
945Difference Array | Range update query in O(1)172
946Find Common Characters Leetcode Solution172
947Print Fibonacci sequence using 2 variables172
948Palindrome Partitioning Leetcode Solution172
950Maximum Frequency Stack Leetcode Solution171
951BFS for Disconnected Graph171
952Intersection of Two Linked Lists LeetCode Solution171
953Depth First Search (DFS) for a Graph171
954Spiral Matrix III LeetCode Solution171
9553 Sum171
956My Calendar I LeetCode Solution171
957Count Subarrays with Same Even and Odd Elements171
958Remove Duplicates from Sorted List II LeetCode Solution170
959Merge Two Sorted Lists Leetcode170
960Climbing stairs170
961Three Consecutive Odds Leetcode Solution170
962Maximize Sum of Array after K Negations Leetcode Solution170
963Symmetric Tree170
964Create Maximum Number170
965Minimum Height Trees LeetCode Solution170
966Vertical sum in a given binary tree170
967Construct BST from its given Level Order Traversal170
968Count Primes in Ranges169
969Word Break169
970Count subarrays where second highest lie before highest169
971Strongly Connected Component169
972Largest area rectangular sub-matrix with equal number of 1’s and 0’s169
973Unique Paths II169
974Merging Intervals169
975Count pair with Given Sum169
976Sign of the Product of an Array LeetCode Solution169
977Breadth First Search (BFS) for a Graph169
978Longest subsequence such that difference between adjacents is one168
979Longest Nice Substring LeetCode Solution168
980Reverse Nodes in K-Group168
981Stone Game II Leetcode168
982Find Maximum of Minimum for Every Window Size in a Given Array168
983Combination Sum IV LeetCode Solution168
984K maximum sums of overlapping contiguous sub-arrays168
985Kth Smallest Element in a BST Leetcode Solution168
986Maximum length subsequence with difference between adjacent elements as either 0 or 1168
987Maximum Subarray Sum Excluding Certain Elements168
988Largest Number Leetcode Solution168
989Design Hit Counter LeetCode Solution168
990Maximum Product Subarray167
991Asteroid Collision LeetCode Solution167
992Largest Substring Between Two Equal Characters Leetcode Solution167
993Next Permutation Leetcode Solution167
994Count pairs from two sorted arrays whose sum is equal to a given value x167
995Serialize and Deserialize Binary Tree167
996Number of palindromic paths in a matrix167
997Valid Boomerang Leetcode Solution167
998Length of Longest Fibonacci Subsequence166
999K Closest Points to Origin Leetcode Solution166
1000Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution166
1001Height of a generic tree from parent array166
1002Find number of pairs in an array such that their XOR is 0166
1003Print Next Greater Number of Q queries166
1004Can Make Arithmetic Progression From Sequence Leetcode Solution166
1005Scramble String LeetCode Solution166
1006Maximum Length of Repeated Subarray166
1007Shuffle 2n integers as without using extra space166
1008Graph Valid Tree LeetCode Solution166
1009Maximum Product of Indexes of Next Greater on Left and Right166
1010String Matching in an Array Leetcode Solution166
1011Segment Tree166
1012Maximum difference between frequency of two elements such that element having greater frequency is also greater166
1013Kth Smallest Element in a Sorted Matrix LeetCode Solution165
1014Friends Of Appropriate Ages LeetCode Solution165
1015Palindrome Partitioning165
1016Find postorder traversal of BST from preorder traversal165
1017Binary Search Tree Delete Operation165
1018Generate Parentheses Leetcode Solution165
1019Find the First Circular Tour that visits all the Petrol Pumps165
1020The Painter’s Partition Problem165
1021Balanced Binary Tree165
1022Remove Duplicates from Sorted Array II Leetcode Solution165
1023Collect maximum points in a grid using two traversals165
1024Shortest Completing Word Leetcode Solution165
1025Find the Difference Leetcode Solution165
1026The Maze III LeetCode Solution165
1027Find a Peak Element II LeetCode Solution164
1028Find Duplicate Subtrees164
1029Build an Array With Stack Operations Leetcode Solution164
1030Boundary Traversal of binary tree164
1031Validate Binary Search Tree164
1032Number Of Longest Increasing Subsequence164
1033Rearrange array such that even positioned are greater than odd164
1034Minimum Index Sum of Two Lists164
1035Consecutive Characters LeetCode Solution164
1036Maximum Number of Ways to Partition an Array LeetCode Solution164
1037Largest divisible pairs subset164
1038Level Order Traversal of Binary Tree164
1039Decrypt String from Alphabet to Integer Mapping Leetcode Solution164
1040Newman-Conway Sequence164
1041Binary Search Tree164
1042Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’163
1043Merge Sort163
1044Move all negative elements to end in order with extra space allowed163
1045Invalid Transactions LeetCode Solution163
1046Path Sum II LeetCode Solution163
1047Construct Binary Tree from given Parent Array representation163
1048Advantages of BST over Hash Table163
1049Boolean Parenthesization Problem163
1050Kill Process LeetCode Solution163
1051Double the first element and move zero to end163
1052Maximum subsequence sum such that no three are consecutive162
1053Bitwise AND of Numbers Range LeetCode Solution162
1054Iterative Depth First Traversal of Graph162
1055Available Captures for Rook Leetcode Solution162
1056Compute nCr % p162
1057Construction of Longest Increasing Subsequence (N log N)162
1058Maximum Sum of 3 Non-Overlapping Subarrays162
1059Insertion in a Binary Tree162
1060Find Three Element From Different Three Arrays Such That a + b + c = sum161
1061Next Greater Element III LeetCode Solution161
1062Custom Sort String Leetcode Solution161
1063Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution161
1064Count minimum steps to get the given desired array161
1065First missing positive161
1066Make The String Great Leetcode Solution161
1067Ugly Numbers161
1068Subarrays with K Different Integers Leetcode Solution161
1069Find Peak Element160
1070Employee Importance LeetCode Solution160
1071Add two numbers160
1072Find maximum difference between nearest left and right smaller elements160
1073Rearrange array such that even index elements are smaller and odd index elements are greater160
1074Recover Binary Search Tree Leetcode Solution160
1075Lowest Common Ancestor160
1076Super Ugly Number159
1077Regular Expression Matching Regular Expression Matching LeetCode Solution159
1078Print all triplets in sorted array that form AP159
1079Partition Equal Subset Sum159
1080Minimum Size Subarray Sum159
1081Number of Closed Islands Leetcode Solution159
1082Maximize Distance to Closest Person LeetCode Solution159
1083Defanging an IP Address LeetCode Solution159
1084Smallest Common Region Leetcode Solution159
1085Print Right View of a Binary Tree159
1086Level order traversal using two Queues159
1087Morris Inorder Traversal159
1088Find whether a subarray is in form of a mountain or not159
1089Maximum weight transformation of a given string159
1090Remove duplicates from sorted array159
1091Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution158
1092Increasing Triplet Subsequence LeetCode Solution158
1093Implement Trie (Prefix Tree) Leetcode Solution158
1094Kth Smallest Product of Two Sorted Arrays LeetCode Solution158
1095Number of siblings of a given Node in n-ary Tree158
1096Valid Tic-Tac-Toe State LeetCode Solution158
1097Largest BST Subtree LeetCode Solution158
1098Remove Palindromic Subsequences Leetcode Solution158
1099Ugly Number II LeetCode Solution157
1100Palindromic Substrings Leetcode Solution157
1101Binary Tree Right Side View LeetCode Solution157
1102Serialize and Deserialize Binary Tree LeetCode Solution157
1103Binary Tree Data Structure157
1104Palindrome Permutation LeetCode Solution157
1105Cells with Odd Values in a Matrix LeetCode Solution157
1106Find the minimum distance between two numbers157
1107Populating Next Right Pointers in Each Node Leetcode Solution156
1108Longest Bitonic Subsequence156
1109Products of ranges in an array156
1110Number of Students Doing Homework at a Given Time Leetcode Solution156
1111Reformat The String Leetcode Solution156
1112Bus Routes Leetcode Solution156
1113Search in Sorted Rotated Array156
1114Count Largest Group Leetcode Solution156
1115Path Sum156
1116Day of the Year Leetcode Solution156
1117Maximum Depth Of Binary Tree155
1118Find Smallest Range Containing Elements from k Lists155
1119Root to Leaf path with target sum Leetcode Solutions155
1120Divisible Pairs Counting155
1121Sum of Even Numbers After Queries155
1122Distinct Subsequences155
1123Search Insert Position155
1124Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution155
1125Write Code to Determine if Two Trees are Identical154
1126Bottom View of a Binary Tree154
1127Prime Palindrome LeetCode Solution154
1128Minimum Score Triangulation of Polygon Leetcode Solution154
1129Thousand Separator Leetcode Solution154
1130Iterative method to find ancestors of a given binary tree154
1131Clone a Binary Tree with Random Pointers154
1132Minimum Absolute Difference in BST Leetcode Solution153
1133Queries for Number of Distinct Elements in a Subarray153
1134Mean of Array After Removing Some Elements Leetcode Solution153
1135Third Maximum Number Leetcode Solution153
1136Longest Repeated Subsequence153
1137Moser-de Bruijn Sequence153
1138Longest Increasing Consecutive Subsequence153
1139Construct K Palindrome Strings LeetCode Solution152
1140Golomb sequence152
1141Reformat Date LeetCode Solution152
1142Minimum sum of squares of character counts in a given string after removing k characters152
1143Level of Each node in a Tree from source node152
1144Longest Subarray of 1’s After Deleting One Element LeetCode Solution152
1145Maximum Product of Splitted Binary Tree LeetCode Solution152
1146Print modified array after executing the commands of addition and subtraction152
1147Closest Binary Search Tree Value Leetcode Solution152
1148Find a sorted subsequence of size 3 in linear time152
1149Diameter of N-Ary Tree LeetCode Solution152
1150Minimum Swaps To Make Sequences Increasing LeetCode Solution152
1151Replace two consecutive equal values with one greater151
1152Maximize sum of consecutive differences in a circular array151
1153Cutting a Rod151
1154Find Largest Value in Each Tree Row LeetCode Solution151
1155Rotate Array151
1156Constant time range add operation on an array151
1157Closest Leaf in a Binary Tree LeetCode Solution151
1158Maximum Product Subarray151
1159Search an Element in Sorted Rotated Array151
1160Minimum Moves to Equal Array Elements LeetCode Solution151
1161Priority Queue151
1162Count even length binary sequences with same sum of first and second half bits151
1163Swap Nodes In Pairs151
1164Delete Nodes and Return Forest Leetcode Solution150
1165Topological Sorting150
1166Minimum Cost to Move Chips to The Same Position LeetCode Solution150
1167Contiguous Array LeetCode Solution150
1168Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1169Find maximum length Snake sequence150
1170Kth Smallest Number in Multiplication Table Leetcode Solution150
1171Convert BST into a Min-Heap without using array150
1172Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution149
1173Web Crawler LeetCode Solution149
1174First Bad Version149
1175Search Suggestions System LeetCode Solution149
1176Factorial Trailing Zeroes LeetCode Solution149
1177Count Pairs Whose Products Exist in Array149
1178Decision Tree149
1179Decrease Elements To Make Array Zigzag LeetCode Solution149
1180Check Array Formation Through Concatenation Leetcode Solution149
1181Subset Sum Problem in O(sum) space149
1182Maximum number of segments of lengths a, b and c148
1183Maximum Binary Tree148
1184Possible Bipartition LeetCode Solution148
1185Merge two BSTs with limited extra space148
1186Perfect Squares LeetCode Solution148
1187Minimum Sideway Jumps LeetCode Solution148
1188Transform a BST to Greater sum Tree147
1189K’th Largest element in BST using constant extra space147
1190Valid Triangle Number147
1191Reverse a Path in BST using Queue147
1192Given a binary tree, how do you remove all the half nodes?147
1193Matchsticks to Square Leetcode Solution147
1194Binary Tree to Binary Search Tree Conversion147
1195Convert Sorted Array to Binary Search Tree LeetCode Solutions146
1196Concatenation of Array LeetCode Solution146
1197Sliding Window Median Leetcode Solution146
1198Red-Black Tree Introduction146
1199Divide Two Integers Leetcode Solution146
1200Sum of Left Leaves LeetCode Solution146
1201Path Crossing Leetcode Solution146
1202Maximum sum of a path in a Right Number Triangle146
1203Number of Orders in the Backlog Leetcode Solution146
1204Maximum Value at a Given Index in a Bounded Array LeetCode Solution146
1205Swapping Nodes in a Linked List Leetcode Solution145
1206Queries on Probability of Even or Odd Number in given Ranges145
1207Maximum sum bitonic subarray145
1208Maximum sum of pairs with specific difference145
1209Champagne Tower LeetCode Solution144
1210Find the smallest binary digit multiple of given number144
1211Integer Break LeetCode Solution144
1212Valid Perfect Square LeetCode Solution144
1213New 21 Game144
1214Queue Reconstruction by Height144
1215How to print maximum number of A’s using given four keys144
1216Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution144
1217Find minimum number of merge operations to make an array palindrome144
1218Lowest Common Ancestor of a Binary Tree Leetcode Solution144
1219Range Queries for Longest Correct Bracket Subsequence143
1220Maximum Array from Two given Arrays Keeping Order Same143
1221Print n terms of Newman-Conway Sequence143
1222Maximum Sum Increasing Subsequence142
1223Flatten 2D Vector LeetCode Solution142
1224Guess The Word142
1225Moving Stones Until Consecutive Leetcode Solution142
1226Graph and its representation142
1227Lowest Common Ancestor in Binary Search Tree142
1228The kth Factor of n Leetcode Solution142
1229LRU Cache Leetcode Solution142
1230Check if all levels of two Binary Tree are anagrams or not142
1231Find Minimum in Rotated Sorted Array II LeetCode Solution142
1232Array Queries for multiply replacements and product142
1233Range Sum Query using Sparse Table142
1234Maximize Elements Using Another Array141
1235Bold Words in String LeetCode Solution141
1236Kth Smallest Element in a BST141
1237Longest Common Prefix Using Word by Word Matching141
1238Largest Plus Sign Leetcode Solution140
1239Merge k Sorted Lists Leetcode Solution140
1240Mean of range in array140
1241Print modified array after multiple array range increment operations140
1242Contiguous Array140
1243Write a function to get the intersection point of two Linked Lists140
1244Arithmetic Slices II – Subsequence LeetCode Solution140
1245BST to a Tree with Sum of all Smaller Keys139
1246Maximum Product Subarray139
1247Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution139
1248Count Subsets Having Distinct Even Numbers139
1249Graph Cloning139
1250Minimum Remove to Make Valid Parentheses LeetCode Solution138
1251Find k-th smallest element in BST (Order Statistics in BST)138
1252Missing Number138
1253Design Skiplist LeetCode Solution138
1254Different Ways to Add Parentheses Leetcode Solution137
1255Check for Identical BSTs without building the trees137
1256Parallel Courses II LeetCode Solution137
1257Power of Two137
1258Check if each internal node of a BST has exactly one child136
1259Min Cost Climbing Stairs LeetCode Solution136
1260Image Overlap LeetCode Solution136
1261Minimum Time to Collect All Apples in a Tree LeetCode Solution136
1262Symmetric Tree LeetCode Solution Leetcode Solution136
1263Check Completeness of a Binary Tree LeetCode Solution135
1264Verify Preorder Serialization of a Binary Tree135
1265Check in binary array the number represented by a subarray is odd or even135
1266Next greater element135
1267Check if two nodes are on the same path in a Tree135
1268Koko Eating Bananas LeetCode Solution134
1269Smallest Range II Leetcode Solution134
1270Print Ancestors of a Given Binary Tree Node Without Recursion134
1271Excel Sheet Column Title LeetCode Solution134
1272Count and Toggle Queries on a Binary Array133
1273Orderly Queue LeetCode Solution133
1274Longest Substring Without Repeating Characters Leetcode Solution133
1275Palindrome Number LeetCode Solution133
1276Vertical Order Traversal of Binary Tree LeetCode Solution132
1277Merge Sorted Array132
1278Number of elements less than or equal to a given number in a given subarray131
1279Arranging Coins Leetcode Solution131
1280Array Nesting Leetcode Solution131
1281Largest Submatrix With Rearrangements LeetCode Solution131
1282Check if X can give change to every person in the Queue131
1283Check If a String Can Break Another String Leetcode Solution130
1284Palindrome Partitioning129
1285Peeking Iterator LeetCode Solution129
1286Continuous Subarray Sum LeetCode Solution129
1287Find maximum average subarray of k length128
1288Find the Winner of the Circular Game LeetCode Solution128
1289Add Two Numbers II Leetcode Solution128
1290Queries for Decimal Values of Subarrays of a Binary Array128
1291Maximum product of an increasing subsequence127
1292Range Minimum Query (Square Root Decomposition and Sparse Table)126
1293Insert Delete GetRandom O(1) Leetcode Solution126
1294Newman–Shanks–Williams prime126
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution125
1296Encoded String With Shortest Length LeetCode Solution124
1297Number of indexes with equal elements in given range123
1298Convert to Base -2 LeetCode Solution123
1299Reach a Number LeetCode Solution123
1300Check given array of size n can represent BST of n levels or not123
1301Jump Game IV LeetCode Solution123
1302Random Pick Index LeetCode Solution122
1303Minimum Number of People to Teach LeetCode Solution121
1304Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1305Binary Tree to Binary Search Tree Conversion using STL set121
1306Convert a BST to a Binary Tree such that sum of all greater keys is added to every key120
1307Minimum Total Space Wasted With K Resizing Operations LeetCode Solution119
1308Design A Leaderboard Leetcode Solution119
1309Design Underground System Leetcode Solution118
1310Queries on XOR of greatest odd divisor of the range118
1311Shifting Letters LeetCode Solution117
1312Print Maximum Length Chain of Pairs116
1313Detect Capital Leetcode Solution113
1314Minimum Swaps to Group All 1’s Together Leetcode Solution113
1315Minimum Path Sum Leetcode Solution111
1316Count Sub Islands LeetCode Solution110
1317Top K Frequent Elements LeetCode Solution110
1318Substring with Concatenation of All Words Leetcode Solution109
1319Odd Even Linked List Leetcode Solution108
1320Monotonic Array Leetcode Solution107
1321Binary Tree Inorder Traversal LeetCode Solution105
1322Maximum Population Year LeetCode Solution105
1323Decode String Leetcode Solution105
1324Find the Town Judge LeetCode Solution104
1325Longest Common Subsequence LeetCode Solution104
1326Shortest Unsorted Continuous Subarray LeetCode Solution99
1327Rectangle Overlap LeetCode Solution97
1328Sum Root to Leaf Numbers LeetCode Solution96
1329Best Meeting Point LeetCode Solution96
1330Find the Town Judge LeetCode Solution95
1331Maximum Population Year LeetCode Solution94
1332Insert into a Sorted Circular Linked List LeetCode Solution94
1333Flatten Binary Tree to Linked List LeetCode Solution94
1334Design Add and Search Words Data Structure LeetCode Solution93
1335Score of Parenthesis LeetCode Solution92
1336Reveal Cards In Increasing Order Leetcode Solution91
1337Stone Game IV LeetCode Solution91
1338Valid Triangle Number LeetCode Solution90
1339Is Graph Bipartite? LeetCode Solution90
1340Range Sum Query 2D – Immutable LeetCode Solution90
1341Divide Chocolate LeetCode Solution84
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution71
1344Reverse Integer Leetcode Solution71
1345Rotate String LeetCode Solution69
1346Find K Closest Elements LeetCode Solution67
1347Sort Colors LeetCode Solution65
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution64
1349Excel Sheet Column Number LeetCode Solution61
1350Maximum Size Subarray Sum Equals k Leetcode Solution55
1351Valid Anagram Leetcode Solution47
1352Camelcase Matching Leetcode Solution47
1353H-Index Leetcode Solution47
1354Most Stones Removed with Same Row or Column LeetCode Solution46
1355Sliding Window Maximum LeetCode Solution46
1356Container With Most Water LeetCode Solution45
1357Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution44
1358Next Permutation LeetCode Solution44
1359Group Anagrams LeetCode Solution44
1360Binary Search LeetCode Solution43
1361High Five LeetCode Solution43
1362Find Peak Element LeetCode Solution43
1363Paint House LeetCode Solution42
1364Group Shifted Strings Leetcode Solution40
1365Flatten Binary Tree to Linked List LeetCode Solution39
1366The Number of Weak Characters in the Game LeetCode Solution38
1367Next Greater Element I Leetcode Solution38
1368Minimum Number of Arrows to Burst Balloons LeetCode Solution38
1369Sentence Screen Fitting LeetCode Solution38
1370Split Linked List in Parts Leetcode Solution38
1371Isomorphic Strings LeetCode Solution37
1372Valid Triangle Number LeetCode Solution36
1373Unique Binary Search Trees LeetCode Solution36
1374Count Good Nodes in Binary Tree LeetCode Solution35
1375Peak Index in a Mountain Array LeetCode Solution34
1376Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution34
1377Break a Palindrome LeetCode Solution34
1378Closest Binary Search Tree Value II LeetCode Solution33
1379All Possible Full Binary Trees LeetCode Solution33
1380Minimum Increment to Make Array Unique Leetcode Solution33
1381Best Time to Buy and Sell Stock IV LeetCode Solution33
1382Swim in Rising Water LeetCode Solution33
1383Max Sum of Two Non-Overlapping Subarrays LeetCode Solution32
1384Single Element in a Sorted Array LeetCode Solution32
1385Implement Rand10() Using Rand7() Leetcode Solution31
1386Remove All Ones With Row and Column Flips Leetcode Solution31
1387Contains Duplicate LeetCode Solution31
1388Trapping Rain Water II LeetCode Solution30
1389Validate Stack Sequences LeetCode Solution30
1390Find First and Last Position of Element in Sorted Array LeetCode Solution30
1391Lowest Common Ancestor of a Binary Search Tree Leetcode Solution30
1392Greatest Sum Divisible by Three LeetCode Solution28
1393Reverse Nodes in k-Group LeetCode Solution28
1394Implement strStr() LeetCode Solution27
1395Detect Squares LeetCode Solution27
1396Stone Game IV LeetCode Solution26
1397Fibonacci Number LeetCode Solution24
1398Invert Binary Tree LeetCode Solution24
1399Design Bounded Blocking Queue LeetCode Solution23
1400Total Hamming Distance LeetCode Solution23
1401Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution22
1402Unique Paths III LeetCode Solution20
1403Candy LeetCode Solution18
Translate »