Trapping Rain Water II LeetCode Solution

Difficulty Level Hard
Frequently asked in Amazon Bloomberg Google TwitterViews 24

Problem Statement:

Trapping Rain Water II LeetCode Solution : Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.

Examples:

Input:

 heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]

Output:

 4

Explanation:

After the rain, water is trapped between the blocks.
We have two small ponds 1 and 3 units trapped.
The total volume of water trapped is 4.

Trapping Rain Water II LeetCode SolutionPin

Approach:

Idea:

The idea is to consider all the boundary cells and then slowly cover the entire matrix with the help of BFS. One thing to remember is that the boundary cells can not store any amount of water in them. The idea is using Priority Queue (implemented with Min Heap) to polling out the node with minimum value. Then applying BFS algorithm to traverse through neighbor nodes.

While doing BFS we will check if the internal cells can store some amount of water in them.

First, we add all the boundary cells into a min-heap and then for each element i inside the min heap we do a BFS to its neighboring cells and calculate what amount of water they can store without the water getting spill out, by taking the ith element as the limiting boundary.

Code:

Trapping Rain Water II C++ Solution:

class Solution {
public:
    int trapRainWater(vector<vector<int>>& heightMap) {
        priority_queue<vector<int>> minHeap;
        int m = heightMap.size();
        int n = heightMap[0].size();
        vector<vector<bool>> vis(m,vector<bool>(n,false));
        for(int i=0;i<n;i++){
            minHeap.push({-heightMap[0][i],0,i});
            minHeap.push({-heightMap[m-1][i],m-1,i});
            vis[0][i] = true;
            vis[m-1][i] = true;
        }
        for(int i=1;i<m-1;i++){
            minHeap.push({-heightMap[i][0],i,0});
            minHeap.push({-heightMap[i][n-1],i,n-1});
            vis[i][0] = true;
            vis[i][n-1] = true;
        }
        int ans = 0;
        vector<vector<int>> dirs = {{0,1},{1,0},{0,-1},{-1,0}};
        while(!minHeap.empty()){
            vector<int> top = minHeap.top();
            minHeap.pop();
            for(auto it:dirs){
                int x = it[0] + top[1];
                int y = it[1] + top[2];
                
                if(x>=0 and y>=0 and x<m and y<n and (not vis[x][y])){
                    vis[x][y] = true;

                    if(heightMap[x][y] < heightMap[top[1]][top[2]]){
                        ans += heightMap[top[1]][top[2]] - heightMap[x][y];
                        heightMap[x][y] = heightMap[top[1]][top[2]];
                        minHeap.push({-heightMap[x][y],x,y});
                    }
                    else{
                        minHeap.push({-heightMap[x][y],x,y});
                    }
                }
            }
        }
        return ans;
    }
};

 

Complexity Analysis of Trapping Rain Water II LeetCode Solution:

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Java program to find the number of Nodes in a Binary Tree2542
3Reverse a string without affecting special characters2524
4Palindrome using Recursion2488
5Delete a node of a linked list at given position2022
6Quick Sort1769
7Insert nodes in a linked list in a sorted way (Ascending Order)1709
8Find elements pair from array whose sum equal to number1688
9Sort Elements by Frequency of Occurrences1672
10Write a program to print all permutations of a given string1655
11Find Minimum Distance Between Two Numbers in an Array1518
12Create a Doubly Linked List1484
13Reverse an Array1464
14Smallest window in a string containing all characters of another string1437
15Recursively remove all adjacent duplicates1406
16Find a Triplet That Sum to a Given Value1391
17First Repeating Element1385
18Sum of numbers in String1362
19Arrange Even and Odd number such that Odd comes after Even1357
20Smallest Positive Number Missing in an Unsorted Array1326
21Check if the Elements of an Array are Consecutive1291
22Detect a loop in the Linked List1272
23Largest Sum Contiguous Subarray1263
24Quick Sort on SIngly Linked List1257
25Subarray with Given Sum1247
26Print all Possible Combinations of R Elements in a given Array of size N1247
27Recursive function to do substring search1245
28Find the Maximum Repeating Number in Array1205
29Find the First and Second Smallest Elements1155
30Binary Tree Level order traversal in Java1155
31Check if two linked lists are identical1143
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1114
34Find Leaders in an Array1092
35Swap nodes in the linked list1085
36Find the second most frequent character1034
37Find the Number Occurring Odd Number of Times in an Array1033
38Arrange given Numbers to Form the Biggest Number II1027
39Given a string find its first non-repeating character1014
40Find Triplet in Array With a Given Sum1002
41Given a sorted array and a number x, find the pair in array whose sum is closest to x994
42Total number of occurrences of a given item in the linked list991
43A Program to check if strings are rotations of each other or not989
44Print all possible words from phone digits972
45Find the Missing Number963
46Rearrange Positive and Negative Numbers Alternatively in Array950
47Longest Palindromic Substring944
48Segregate even and odd nodes in a linked list933
49Print Longest common subsequence925
50Transform one string to another using minimum number of given operations913
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome895
53Rearrange given Array in Maximum Minimum Form876
54Iterative Implementation of Quick Sort868
55Insertion Sort858
56Count Possible Triangles856
57Multiplication of Two Matrices840
58Count of Triplets With Sum Less than Given Value830
59Stock Buy Sell to Maximize Profit827
60Check if the linked list is palindrome827
61Rotate a Linked List825
62Concatenation of two strings805
63Tug of War798
64Print all duplicates in the input string796
65Count Number of Substrings with K Distinct Character’s794
66Find Nearest Greater and Smaller Element782
67Reverse String Without Temporary Variable777
68The Celebrity Problem771
69Remove ‘b’ and ‘ac’ from a given string770
70Find Pythagorean Triplets from Array768
71Find all Common Elements in Given Three Sorted Arrays763
72Remove all duplicates in an unsorted linked list740
73Find the Row with Maximum Number of 1’s737
74Find the subarray whose sum is equal to a given number X736
75Find the Peak Element from an Array735
76Remove Minimum Characters so that Two Strings Become Anagrams735
77Addition of Two Matrices729
78Find Smallest Missing Number in a Sorted Array725
79Generate all Binary Strings Without Consecutive 1’s724
80A Product Array Puzzle722
81Maximum Sum of Non Consecutive Elements710
82Implement Two Stacks in an Array707
83Lexicographic rank of string697
84Check if Two given Matrices are Identical690
85Maximum Product Subarray II686
86Multiplication of Previous and Next681
87Subtraction of Two Matrices673
88Merge K Sorted Arrays and Print Sorted Output668
89Divide a string in N equal parts665
90Move All the Zeros to the End of the Given Array665
91Form Minimum Number from Given Sequence of D’s and I’s664
92Online Algorithm for Checking Palindrome in a Stream664
93Remove recurring digits in a given number656
94Check whether two strings are anagram of each other656
95Sort a stack using a temporary stack651
96Maximum Circular Subarray Sum649
97Sort a linked list that is sorted alternating ascending and descending645
98Subarray and Subsequence639
99Find the Minimum Element in a Sorted and Rotated Array637
100Move last element of the Linked List at first place632
101First Circular Tour to Visit all the Petrol Bunks632
102Compare two strings(linked lists)628
1033Sum Leetcode Solution628
104Maximum Element in an Array which is Increasing and then Decreasing627
105Largest Subarray with Equal Number of 0’s and 1’s626
106Palindrome Permutations of a String626
107Flattening a linked list623
108Palindromes in a given range621
109Majority Element618
110Minimum insertions to form a shortest palindrome617
111Pangram Checking616
112Run length encoding615
113Print all permutations with repetition613
114Elements Appear more than N/K times in Array611
115Minimum Characters to be Added at Front to Make String Palindrome608
116Most repeating character in a string605
117Two Sum Leetcode Solution601
118Rotate string to get lexicographically minimum string601
119Repeated Subsequence of Length Two or More598
120Merge a linked list into another at alternate positions596
121Remove all duplicates in a sorted linked list595
122Rearrange a given linked list in-place594
123Minimum number of Merge Operations to make an Array Palindrome593
124Print all anagrams together in a sequence of words591
125Reorder an Array According to the Given Indexes580
126Pancake Sorting Problem578
127Merge Overlapping Intervals II567
128Remove duplicates from a string565
129Clone a Linked List with next and random pointer565
130Smallest Palindrome after Replacement565
131Transpose of a Matrix565
132Longest Palindrome can be Formed by Removing or Rearranging Characters565
133Remove Extra Spaces from a String563
134Removing Spaces from a String using stringstream560
135Maximum Sum Increasing Subsequence559
136Size of The Subarray With Maximum Sum558
137Check if a given string is a rotation of a palindrome558
138Partition Problem552
139Generate all Binary Strings from Given Pattern546
140Check whether Strings are K Distance Apart or Not545
141Length of Longest valid Substring541
142Delete Last Occurrence538
143Check if Two given Strings are Isomorphic to each other537
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized535
145Insert Node in the Sorted Linked List532
146Program to Toggle all Characters in a String527
147Given string is interleaving of two other strings or not525
148Maximum difference between two elements such as larger element comes after smaller525
149Check length of a String is Equal to the Number Appended at its Last515
150Count Minimum Steps to Get the given Array514
151Number of Smaller Elements on Right Side512
152Check if all Rows of a Matrix are Circular Rotations of Each Other507
153Longest Common Prefix using Divide and Conquer506
154Find Pair with Given Difference506
155Merge sort better than quick sort for linked lists505
156Compare Two Version Numbers501
157Find nth node of the Linked list from the end497
158Print all interleavings of given two strings496
159Print Reverse of a string (Recursion)495
160Median of Two Sorted Arrays LeetCode Solution495
161Find a Fixed Point in a Given Array494
162Sort 0s 1s and 2s in an Array493
163Reorder Array Using Given Indexes493
164Reverse words in a given string491
165Find the Subarray of given length with Least Average485
166Merge two sorted linked lists such that merged list is in reverse order484
167Split linked list using alternate nodes483
168Print all Palindromic Partitions of a String475
169Print string of odd length in ‘X’ format471
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average465
172Swap Kth Node from beginning with Kth Node from End461
173Find Duplicates in an Array in Most Efficient Way459
174Shortest Superstring Problem454
175print all palindromic partitions454
176Check if String Follows Order of Characters by a Pattern or not450
177Maximum Length of Chain Pairs448
178Sort a String According to Another String446
179Flatten a multilevel linked list445
180Sorting a K Sorted Array440
181Program to add two binary digits433
182Find a Sorted Subsequence of size 3428
183Recursively print all the sentences that can be formed from list of word lists427
184Longest Span with same Sum in two Binary Arrays II426
185Reverse a Linked List in groups426
186Longest Common Prefix Using Binary Search II425
187Caesar Cipher425
188Find the two Numbers with Odd Occurrences in an Unsorted Array424
189Kth Non-repeating Character421
190Reverse a Singly Linked List (Iterative/Non-Recursive)420
191Check if String can Become Empty by Recursively Deleting given Substring416
192Longest Common Prefix Word by Word Matching412
193Rearrange a linked list in Zig-Zag410
194Rotate Image by 90 degrees406
195Permutations of a Given String Using STL406
196Perfect Reversible String404
197Pancake Sorting404
198Merging Two Sorted Arrays401
199Find First non-repeating character in a string400
2001`s and 2`s complement of binary number398
201List items containing all characters of a given word394
202Increasing Subsequence of Length three with Maximum Product394
203Maximum occurring character in a string393
204Find the point where a monotonically increasing function becomes positive first time392
205Four Elements that Sum to Given390
206Sort a linked list with 0s, 1s and 2s389
207Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes387
208Longest Common Prefix using Character by Character Matching385
209Count Number of Occurrences in a Sorted Array383
210Palindrome string (number)382
211Valid Parentheses LeetCode Solution380
212Delete N nodes after M379
213Minimum Characters to be Removed to Make a Binary String Alternate377
214Even Substring Count375
215Split a string374
216Recursive Implementation of atoi()371
217Sorting the array of strings371
218Convert a String that is Repetition of a Substring of Length K369
219Check if a Linked list of Strings form a Palindrome367
220Print Shortest Path to Print a String on Screen364
221Maximum Subarray Leetcode Solution363
222Print All Distinct Elements of the Array360
223Convert string1 to string2 in one edit359
224Reverse a String using Stack359
225Nth Character in Concatenated Decimal String358
226Count the number of words358
227Matrix Chain Multiplication using Dynamic Programming358
228Find the first Repeating Number in a Given Array358
229wildcard character matching357
230Reverse a singly linked list recursively357
231Lower Case To Upper Case353
232Can we reverse a linked list in less than O(n) time ?351
233Binary Tree to Doubly linked list349
234Sort Elements by Frequency II345
235Longest Common Subsequence with Permutations344
236Find the Lost Element From a Duplicated Array344
237Merge Two Sorted Arrays341
238Split Four Distinct Strings340
239Find middle of the Linked List337
240Count the Pairs at Same Distance as in English Alphabets335
241Roman to Integer Leetcode Solution335
242Toeplitz Matrix330
243Palindrome Permutation328
244Next Greater Element in an Array325
245Word Search Leetcode Solution325
246Move all negative elements to one side of array323
247N queen problem322
248Searching a node in a Binary Search Tree317
249Find All Pairs With a Given Difference317
250Sudoku Solver315
251Find Nth Node315
252Reverse Bits314
253First non Repeating Element314
254Print all Possible Ways to Break a String in Bracket Form314
255Count Pairs With Given Sum313
256Number of Islands LeetCode Solution313
257String(represents an integer) to value313
258Reverse a String312
259Triplet from three linked lists with given sum311
260Types of Binary Tree311
261Delete a Tree311
262Change Gender of a given String311
263Repeated Substring Pattern310
264Meeting Rooms II LeetCode Solution308
265Sort an array of strings308
266How to Efficiently Implement k Stacks in a Single Array?308
267Reverse a linked list308
268Fibonacci numbers307
269Delete a node under given conditions307
270Number of sub-strings which recursively add up to 9306
271Min Stack304
272Most Frequent Element in an Array304
273Longest Palindromic Substring LeetCode Solution304
274Cuckoo sequence program302
275Dijkstra Algorithm302
276Longest Common Extension300
277Binary Tree298
278Remove spaces from a string296
279House Robber Leetcode Solution296
280Max stack295
281Best Time to Buy and Sell Stock  II Leetcode Solution293
282Subset Leetcode293
283Word Search290
284Shuffle a given Array289
285KMP Algorithm288
286Remove middle points in a linked list of line segments288
287Expression Evaluation287
288Find, second, frequent, character287
289Minimize the maximum difference between the heights287
290Plus One Leetcode Solution287
291Combination Sum Leetcode Solution285
292Search Insert Position Leetcode Solution284
293Number Of 1 bits282
294Reverse words in a string282
295Evaluation of Postfix Expression280
296Pair of Positive Negative Values in an Array280
297Set Matrix Zeroes279
298Sliding Window Technique279
299Min Stack Leetcode Solution277
300Subarray with 0 sum277
301Valid Palindrome Leetcode Solution276
302Rabin Karp Algorithm276
303Backspace String Compare275
304Sort linked which is sorted on absolute values273
305Common elements in all rows of a given matrix273
306Merge Sorted Arrays Leetcode Solution272
307Clone a linked list with next and random pointer (Hashing)272
308Sqrt(x) Leetcode Solution270
309Delete middle element of a stack269
310Reversing a Queue268
311Implementation of Deque using Doubly Linked List266
312Contains Duplicate II Leetcode Solution265
313String Compression264
314Count of index pairs with equal elements in an array264
315Intersection of Two Arrays II Leetcode Solution264
316Product of array except self264
317Contains Duplicate263
318Tower Of Hanoi263
319Combination Sum263
320Count subarrays with equal number of 1’s and 0’s263
321Find Top K (or Most Frequent) Numbers in a Stream263
322Count Odd Numbers in an Interval Range Leetcode Solution262
323Pascal Triangle Leetcode262
324Reverse individual words262
325Page Replacement Algorithms in Operating Systems261
326How to Delete a Linked List261
327Minimum swaps required to bring all elements less than or equal to k together260
328Integer to Roman Leetcode Solution259
329Group Words With Same Set of Characters258
330Single Number Leetcode Solution258
331Segregate even and odd numbers258
332Second Most Repeated Word in a Sequence257
333Bellman Ford Algorithm257
334Sum of minimum and maximum elements of all subarrays of size k256
335Sorting array using Stacks256
336Find sum of non-repeating elements (distinct) elements in an array256
337Postfix to Infix Conversion256
338Smallest Subarray with k Distinct Numbers255
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution255
340Add Binary Leetcode Solution255
341Arithmetic Expression Evaluation255
342Sort elements by frequency255
343Top K Frequent Words254
344K-th Smallest Element in a Sorted Matrix254
345Next Permutation253
346Construct Binary Tree from Given Inorder and Preorder Traversals252
347Minimum operation to make all elements equal in array252
348Maximum Number of Balloons Leetcode Solution252
349Pow(x, n) Leetcode Solution251
350Count subarrays having total distinct elements same as original array251
351Palindrome Linked List Leetcode Solution250
352Given two unsorted arrays find all pairs whose sum is x250
353Longest Substring Without Repeating Characters LeetCode Solution250
354Convex Hull Algorithm250
355First element occurring k times in an array250
356Scramble String249
357Longest Common Prefix Leetcode Solution249
358Special Number249
359Design a stack that supports getMin() in O(1) time and O(1) extra space249
360Majority Element Leetcode Solution249
361Permutations Leetcode Solution248
362Kruskal Algorithm248
363Find Lucky Integer in an Array Leetcode Solution248
364Find duplicates in a given array when elements are not limited to a range247
365Third Maximum Number Leetcode Solution246
366Evaluate Division246
367Reversing the First K elements of a Queue243
368Running Sum of 1d Array Leetcode Solution243
369Check if two arrays are equal or not243
370Spiral Matrix LeetCode Solution243
371Prefix to Infix Conversion243
372Fizz Buzz Leetcode243
373Maximum possible difference of two subsets of an array243
374Reverse a Number Using Stack243
375Number of Good Pairs Leetcode Solution242
376Minimum Path Sum242
377Find Numbers with Even Number of Digits Leetcode Solution241
378Maximum Subarray241
379Huffman Coding241
380Maximal Square240
381Find the Town Judge Leetcode Solution240
382Unique Paths240
383Swap Nodes in Pairs Leetcode Solutions240
384Minimum Steps to reach target by a Knight239
385Group Anagrams239
386Range Sum Query 2D – Immutable Leetcode Solution239
387Count Primes Leetcode Solutions239
388Find the Closest Palindrome number238
389Single Number238
390Minimum Absolute Difference Leetcode Solution238
391Sort Array by Increasing Frequency Leetcode Solution238
392Maximum Distance Between two Occurrences of Same Element in Array238
393Smallest Element Repeated Exactly K Times237
394Find the first repeating element in an array of integers237
395Sorting using trivial hash function237
396Find top three repeated in array237
397Zigzag Conversion237
398Find All Numbers Disappeared in an Array Leetcode Solution236
399Remove Minimum Number of Elements Such That no Common Element Exist in both Array236
400Pascal’s Triangle II Leetcode Solution236
401Find Number of Employees Under every Employee236
402Palindrome Substring Queries236
403Cumulative Frequency of Count of Each Element in an Unsorted Array236
404Implement Stack and Queue using Deque236
405Power of Two Leetcode Solution235
406Leetcode Permutations235
407Convert String To Int235
408Count Substrings with equal number of 0s, 1s and 2s234
409Sort Integers by The Number of 1 Bit Leetcode Solution234
410Matrix Diagonal Sum Leetcode Solution234
411Check if Array Contains Contiguous Integers With Duplicates Allowed234
412Print All Distinct Elements of a Given Integer Array233
413Merge Two Sorted Lists Leetcode Solutions233
414Letter Case Permutation233
415Difference between highest and least frequencies in an array233
416Print all subarrays with 0 sum233
417Missing Number Leetcode Solution233
418Expression Contains Redundant Bracket or Not233
419Subarray Sum Equals k233
420How to Implement Stack Using Priority Queue or Heap?233
421Length of the largest subarray with contiguous elements232
422Prim’s Algorithm232
423Decode String232
424House Robber II Leetcode Solution232
425Bipartite Graph232
426Fizz Buzz232
427Unique Paths Leetcode Solution231
428Sort a stack using recursion231
429Subset sum problem231
430Maximum Depth of Binary Tree Leetcode Solution231
431LRU Cache Implementation231
432Top K Frequent Elements231
433Happy Number Leetcode Solution231
434Find all pairs (a, b) in an array such that a % b = k230
435Count pairs from two linked lists whose sum is equal to a given value230
436Subarrays with distinct elements230
437Search in Rotated Sorted Array Leetcode Solution230
438Find Median from data Stream230
439Reverse Integer229
440Find Winner on a Tic Tac Toe Game Leetcode Solution229
441Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution229
442Check If N and Its Double Exist Leetcode Solution228
443Reverse a Stack Using Recursion228
444Monotonic Array LeetCode Solution228
445Coin Change 2 Leetcode Solution228
446Max Consecutive Ones Leetcode Solution228
447Find the Difference Leetcode Solution228
448Find elements which are present in first array and not in second227
449Nth Catalan Number227
450Capacity To Ship Packages Within D Days Leetcode Solution227
451Pair with given product226
452Text Justification LeetCode Solution226
453Subarray Sum Equals K LeetCode Solution226
454Find The Duplicate Number226
455How Many Numbers Are Smaller Than the Current Number Leetcode Solution226
456Trapping Rain Water Leetcode Solution225
457Sum of Subarray Ranges Leetcode Solution225
458Integer to English words225
459Best Time to Buy and Sell Stock III Leetcode Solution224
460Find distinct elements common to all rows of a matrix224
461Edit Distance224
462Priority Queue Using Singly Linked List224
463Fibonacci Number LeetCode Solution224
464Find Minimum In Rotated Sorted Array224
465Reverse Vowels of a String Leetcode Solution224
466Remove Duplicates from Sorted Array Leetcode Solution224
467Count and Say224
468Floyd Warshall Algorithm224
469Find Index of Closing Bracket for a Given Opening Bracket in an Expression223
470Target Sum223
471Valid Parenthesis String223
472Subtract the Product and Sum of Digits of an Integer Leetcode Solution223
473Kth largest element in an Array Leetcode Solutions223
474Reverse a String222
475Find any one of the multiple repeating elements in read only array222
476Find four elements that sum to a given value (Hashmap)222
477Design Parking System Leetcode Solution222
478Generate a String With Characters That Have Odd Counts Leetcode Solution221
479Longest subarray not having more than K distinct elements221
480Longest Common Prefix using Trie221
481Jump Game Leetcode Solution221
482The K Weakest Rows in a Matrix Leetcode Solution221
483Delete a Node from linked list without head pointer221
484Word Ladder LeetCode Solution220
485MiniMax Algorithm220
486Shuffle the Array Leetcode Solution220
487Sorting a Queue without Extra Space220
488Rearrange a binary string as alternate x and y occurrences220
489Check if a given array contains duplicate elements within k distance from each other220
490Find Common Characters Leetcode Solution220
491Prefix to Postfix Conversion220
492Shuffle String Leetcode Solution220
493Flood Fill LeetCode219
494Intersection of Two Arrays219
495The Stock Span Problem218
496Degree of an array218
497Count number of triplets with product equal to given number218
498Multiply Strings Leetcode Solution218
499Top View of Binary Tree218
500Find missing elements of a range218
501Balanced Binary Tree Leetcode Solution218
502Excel Sheet Column Number Leetcode Solution217
503Shortest Palindrome217
504Iterative Tower of Hanoi217
505Find subarray with given sum (Handles Negative Numbers)217
506Best Time to Buy and Sell Stock LeetCode Solution217
507Merge Two Sorted Linked Lists217
508Substring With Concatenation Of All Words217
509Longest Common Subsequence216
510Concatenation of Array LeetCode Solution216
511Postfix to Prefix Conversion216
512Count and Say Leetcode Solution216
513Peak Index in a Mountain Array216
514Longest Common Prefix using Sorting216
515Kids With the Greatest Number of Candies Leetcode Solution216
516Number of Steps to Reduce a Number to Zero Leetcode Solution216
517Find the Duplicate Element216
518Slowest Key Leetcode Solution216
519Iterative Inorder Traversal of a Binary Tree216
520Priority Queue in C++216
521Reverse Words in a String III LeetCode Solution216
522Move Zeroes LeetCode Solution216
523Next Greater Element I Leetcode Solution216
524K-th Distinct Element in an Array215
525Max Area of Island215
526Implement Stack using Queues215
527Sum of Left Leaves Leetcode Solutions215
528Check for Balanced Parentheses in an Expression215
529Valid Sudoku215
530Minimum Knight Moves LeetCode Solution214
531Recursion214
532Arrange given numbers to form the biggest number214
533Minimum Moves to Equal Array Elements Leetcode Solution214
534Convert array into Zig-Zag fashion214
535Container with Most Water214
536Linked List Cycle II LeetCode Solution214
537Find Sum of all unique sub-array sum for a given array213
538Hamming Distance213
539Kth Largest Element in a Stream Leetcode Solution213
540Implement a stack using single queue213
541Merge Overlapping Intervals213
542Find First and Last Position of Element in Sorted Array Leetcode Solution213
543Minimum Delete Operations to make all Elements of Array Same212
544Largest Sum Contiguous Subarray212
545Excel Sheet Column Title Leetcode Solution212
546Largest Perimeter Triangle Leetcode Solution212
547Is Subsequence Leetcode Solution212
548Jewels and Stones Leetcode Solution212
549Gold Mine Problem211
550Next Greater Frequency Element211
551Group Multiple Occurrence of Array Elements Ordered by first Occurrence211
552Isomorphic Strings Leetcode Solution211
553Find N Unique Integers Sum up to Zero Leetcode Solution211
554Zigzag Conversion LeetCode Solution211
555Smallest Subarray With all Occurrences of a Most Frequent Element211
556Check if a queue can be sorted into another queue using a stack211
557Last Stone Weight210
558Change the Array into Permutation of Numbers From 1 to N210
559Contiguous Array Leetcode210
560Delete Node in a Linked List Leetcode Solution210
561How to check if two given sets are disjoint?210
562Maximum sum rectangle in a 2D matrix209
563Shuffle an Array209
564N-th Tribonacci Number Leetcode Solution209
565Koko Eating Bananas Leetcode Solution209
566Minimum Bracket Reversals209
567Convert a normal BST to Balanced BST209
568Minimum Cost to Hire K Workers208
5693Sum Closest LeetCode Solution208
570Mobile Numeric Keypad Problem208
571Valid Anagrams208
572Minimum number of subsets with distinct elements208
573Best Time to Buy and Sell Stock208
574Count the number of nodes at given level in a tree using BFS208
575Summary Ranges Leetcode Solution208
576Distribute Candies to People Leetcode Solution208
577Length of Last Word Leetcode Solution208
578Maximum Distance in Array207
579Decode Ways207
580Number of Provinces Leetcode Solution207
581Shortest Path in a Grid with Obstacles Elimination LeetCode Solution207
582Find Words That Can Be Formed by Characters Leetcode Solution207
583Implementation of Deque using circular array207
584Find if an Expression has Duplicate Parenthesis or Not207
585Build Array From Permutation Leetcode Solution206
586Frog Jump Leetcode Solution206
587Trapping Rain Water LeetCode Solution206
588Smallest Good Base206
589Maximum path sum in a triangle206
590Longest Increasing Subsequence206
591Maximum difference between first and last indexes of an element in array205
592Rotate Image LeetCode Solution205
59301 Matrix LeetCode Solution205
594First negative integer in every window of size k205
595Sort Characters By Frequency LeetCode Solution205
596Integer to Roman205
597Remove All Occurrences of a Substring LeetCode Solution205
598LRU Cache LeetCode Solution205
599Combinations Leetcode Solution205
600Relative Sort Array Leetcode Solution205
601Maximum Number of Occurrences of a Substring Leetcode Solution205
602Non-overlapping sum of two sets204
603Iterative Method to find Height of Binary Tree204
604Island Perimeter Leetcode Solution204
605Remove Linked List Elements Leetcode Solution204
606Delete consecutive same words in a sequence204
607Assign Cookies Leetcode Solution204
608Minimum Operations to convert X to Y204
609Minimum number of distinct elements after removing m items203
610Word Pattern203
611XOR Operation in an Array Leetcode Solution203
612Count all subsequences having product less than K203
613Sieve of Eratosthenes203
614The Knapsack Problem202
615Find the smallest positive integer value that cannot be represented as sum of any subset of a given array202
616Minimum insertions to form a palindrome with permutations allowed202
617Find minimum difference between any two elements202
618Convert Sorted Array to Binary Search Tree Leetcode Solution201
619GCD Of Two Numbers201
620Insert Interval Leetcode Solution201
621Reverse a stack without using extra space in O(n)201
622Permutation in String Leetcode Solution201
623Stone Game LeetCode201
624Bubble sort using two Stacks201
625Maximum Number of Chocolates to be Distributed Equally Among k Students201
626Rotate List Leetcode Solution201
627Applications of Breadth First Search and Depth First Search200
628Tracking current Maximum Element in a Stack200
629Find Largest d in Array such that a + b + c = d200
630Unique Binary Search Trees200
631Same Tree LeetCode Solution200
632Sum of f(a[i], a[j]) over all pairs in an array of n integers200
633Defanging an IP Address Leetcode Solution200
634Isomorphic Strings199
635K Empty Slots199
636Count Good Nodes in Binary Tree Leetcode Solution199
637Find the Duplicate Number LeetCode Solution199
638Longest Increasing Path in a Matrix LeetCode Solution199
639Reorganize String199
640Distance Between Bus Stops Leetcode Solution199
641First Unique Character in a String LeetCode Solution198
642How to Create Mergable Stack?198
643Form minimum number from given sequence198
644License Key Formatting Leetcode Solution198
645Printing brackets in Matrix Chain Multiplication Problem198
646Employee Free Time LeetCode Solution198
647Convert an array to reduced form198
648Optimal Account Balancing LeetCode Solution198
649Letter Combinations of a Phone Number197
650Word Wrap Problem197
651Minimum Depth of Binary Tree Leetcode Solution197
652Find pairs with given sum such that elements of pair are in different rows197
653Painting Fence Algorithm197
654Convert a Number to Hexadecimal Leetcode Solution196
655Replace Elements with Greatest Element on Right Side Leetcode Solution196
656Reducing Dishes LeetCode Solution196
657Find Pair with Greatest Product in Array196
658Sort Array By Parity LeetCode Solution196
659House Robber196
660Merge Two Balanced Binary Search Trees196
661Longest Substring with At Most K Distinct Characters LeetCode Solution196
662Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
663K Empty Slots LeetCode195
664Coin Change Problem195
665Robot Room Cleaner Leetcode Solution195
666Maximum Consecutive Numbers Present in an Array195
667Segregate 0s and 1s in an Array195
668Check If It Is a Straight Line Leetcode Solution195
669Strobogrammatic Number LeetCode Solution195
670Longest Span with same Sum in two Binary arrays194
671Partition Labels LeetCode Solution194
672Queries for counts of array elements with values in given range194
673Kth Missing Positive Number Leetcode Solution194
674Largest subarray with equal number of 0s and 1s194
675Moving Average from Data Stream Leetcode Solution194
676Partition Array Into Three Parts With Equal Sum Leetcode Solution193
677Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
678Find Maximum Level sum in Binary Tree193
679String to Integer (atoi) LeetCode Solution193
680Longest Substring with At Least K Repeating Characters LeetCode Solution193
681Sum of All Odd Length Subarrays Leetcode Solution193
682Valid Palindrome II Leetcode Solution193
683Distance of nearest cell having 1 in a binary matrix193
684Find the node with minimum value in a Binary Search Tree193
685Maximum Product of Two Elements in an Array Leetcode Solution193
686Reservoir Sampling193
687Check If Two String Arrays are Equivalent Leetcode Solution192
688Flipping an Image LeetCode Solution192
689Find the Distance Value Between Two Arrays Leetcode Solution192
690Dynamic Programming Basics192
691Generate all possible sorted arrays from alternate elements of two given sorted arrays192
692Valid Palindrome192
693Print the Fibonacci numbers in reverse order192
694String Compression LeetCode Solution192
695Power of Four Leetcode Solution192
696Find unique character in a string191
697Numbers with prime frequencies greater than or equal to k191
698Remove Invalid Parentheses Leetcode Solution191
699Binary Tree Maximum Path Sum LeetCode Solution191
700Reverse Only Letters LeetCode Solution191
701Increasing Decreasing String Leetcode Solution191
702Find Leaves of Binary Tree LeetCode Solution191
703Find the Smallest Divisor given a Threshold Leetcode Solution191
704Path With Maximum Minimum Value LeetCode Solution191
705Unique Paths II Leetcode Solution190
706Delete Nth node from the end of the given linked list190
707Find the largest multiple of 3190
708To Lower Case Leetcode Solution190
709Number of Dice Rolls With Target Sum LeetCode Solution190
710Inorder Successor of a node in Binary Tree190
711Wiggle Sort190
712Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest189
713Stack Permutations (Check if an array is stack permutation of other)189
714Merge Two Binary Trees LeetCode Solution189
715Sort Array by Increasing Frequency Leetcode Solution189
716Find whether an array is subset of another array189
717Subset Sum Leetcode189
718Factorial Trailing Zeroes Leetcode Solution189
719Edit Distance LeetCode Solution189
720Bulb Switcher LeetCode Solution189
721Maximum Number of Coins You Can Get Leetcode Solution189
722Non-decreasing Array LeetCode Solution189
723Lucky Numbers in a Matrix Leetcode Solution189
724k-th missing element in increasing sequence which is not present in a given sequence188
725Permutation Sequence LeetCode Solution188
726Count quadruples from four sorted arrays whose sum is equal to a given value x188
727Valid Perfect Square Leetcode Solution188
728Reversing a Queue using Recursion188
729Recover Binary Search Tree188
730Populating Next Right Pointers in Each Node188
731Race Car LeetCode Solution188
732Remove brackets from an algebraic string containing + and – operators188
733Merge Sorted Array LeetCode Solution188
734Maximum Length of a Concatenated String with Unique Characters Leetcode Solution188
735Find if Path Exists in Graph Leetcode Solution188
736Perform String Shifts Leetcode188
737BFS vs DFS for Binary Tree188
738Snakes and Ladders LeetCode Solution188
739Minimum Cost For Tickets Leetcode Solution187
740Tiling Problem187
741Majority Element II Leetcode Solution187
742Student Attendance Record I Leetcode Solution187
743Binary Tree zigzag level order Traversal187
744Maximum 69 Number Leetcode Solution187
745Evaluate Reverse Polish Notation LeetCode Solution187
746Keyboard Row Leetcode Solution187
747Ugly Number Leetcode Solution187
748Binary Tree Zigzag Level Order Traversal LeetCode Solution187
749Find Maximum Depth of Nested Parenthesis in a String187
750Add and Search Word – Data structure design LeetCode186
751Best Meeting Point LeetCode Solution186
752Construct BST from given Preorder Traversal186
753Word Pattern LeetCode Solution186
754N-Queens LeetCode Solution186
755Rank Transform of an Array Leetcode Solution186
756Number of NGEs to the Right186
757Morris Traversal186
758Minimum sum of multiplications of n numbers186
759Growable array based stack186
760Valid Number186
761Restore IP Addresses Leetcode Solution186
762Split a String in Balanced Strings Leetcode Solution186
763Base 7 Leetcode Solution186
764String comparison containing wildcards186
765Print a Binary Tree in Vertical Order186
766Finding K closest element185
767Check if Two Expressions With Brackets are Same185
768Hamming Distance Leetcode Solution185
769Priority Queue using doubly linked list185
770Maximum Product of Three Numbers LeetCode Solution185
771Find All Possible Recipes from Given Supplies LeetCode Solution185
772Find Median from Data Stream LeetCode Solution185
773Symmetric Tree Leetcode Solution185
774Program for Bridge and Torch problem185
775Maximum Profit in Job Scheduling Leetcode Solution185
776Binomial Coefficient185
777Number of Days Between Two Dates LeetCode Solution185
778Elements to be added so that all elements of a range are present in array185
779Minimize Maximum Pair Sum in Array LeetCode Solution184
780Sorted Linked List to Balanced BST184
781Find All Duplicates in an Array LeetCode Solution184
782Brick Wall LeetCode Solution184
783Check for Palindrome after every character replacement Query184
784Check If Array Pairs Are Divisible by k LeetCode Solution184
785Regular Expression Matching184
786Top K Frequent Words LeetCode Solution184
787Partition to K Equal Sum Subsets Leetcode Solution184
788Special Array With X Elements Greater Than or Equal X Leetcode Solution184
789Linked List Cycle183
790Largest Rectangle in Histogram LeetCode Solution183
791Decompress Run-Length Encoded List Leetcode Solution183
792Merge K Sorted Linked Lists183
793Jump Game183
794Form Minimum Number From Given Sequence183
795Total Numbers With no Repeated Digits in a Range183
796Sort an array according to the order defined by another array183
797Search in a Binary Search Tree Leetcode Solution183
798Minimum Distance Between BST Nodes Leetcode Solution183
799One Edit Distance LeetCode Solution182
800Kth ancestor of a node in binary tree182
801Invert Binary Tree LeetCode Solution182
802Minimum Height Trees182
803Remove Nth Node From End of List Leetcode Solution182
804Queue based approach for first non-repeating character in a stream182
805Nearest Exit from Entrance in Maze LeetCode Solution182
806Longest Subarray Having Count of 1s One More than Count of 0s182
807Maximum Nesting Depth of the Parentheses Leetcode Solution182
808Largest rectangular sub-matrix whose sum is 0182
809Maximum Depth of N-ary Tree Leetcode Solution182
810Minimum Time Visiting All Points Leetcode Solution182
811Maximum Difference Between Increasing Elements LeetCode Solution182
812Given an Array of Pairs Find all Symmetric Pairs in it181
813Circular Queue181
814Count items common to both the lists but with different prices181
815Final Prices With a Special Discount in a Shop Leetcode Solution181
816Number of Islands II LeetCode Solution181
817Balanced Expression with Replacement181
818Identify and Mark Unmatched Parenthesis in an Expression181
819Minimum time required to rot all oranges180
820Relative Ranks Leetcode Solution180
821Transpose Graph180
822Repeated Substring Pattern LeetCode Solution180
823Diagonal Traversal of Binary Tree180
824Nested List Weight Sum II LeetCode Solution180
825LCS (Longest Common Subsequence) of three strings179
826Minimum Number of Taps to Open to Water a Garden LeetCode Solution179
827Reorder Data in Log Files LeetCode Solution179
828Minimum Jumps to Reach Home LeetCode Solution179
829Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
830Minimum Swaps to Make Strings Equal Leetcode Solution179
831Last Stone Weight II LeetCode Solution179
832Crawler Log Folder Leetcode Solution179
833Permutation Coefficient179
834Daily Temperatures Leetcode Solution179
835Search a 2D Matrix II Leetcode Solution179
836Deletion in a Binary Tree179
837Subarray Product Less Than K LeetCode Solution178
838Clone Graph LeetCode Solution178
839Distinct adjacent elements in an array178
840Remove Duplicates from Sorted List II178
841Binary Search Tree Search and Insertion178
842Course Schedule II – LeetCode178
843Number Complement Leetcode Solution178
844Sort Array By Parity II Leetcode Solution178
845Lemonade Change Leetcode Solution178
846Split Array Into Consecutive Subsequences178
847Missing Element in Sorted Array LeetCode Solution178
848Design Browser History LeetCode Solution178
849Subsequence of Size K With the Largest Even Sum LeetCode Solution178
850A Space Optimized DP solution for 0-1 Knapsack Problem177
851Iterative Preorder Traversal177
852Check if an Array is Stack Sortable177
853Insert Delete GetRandom177
854Find all permuted rows of a given row in a matrix177
855Find Maximum Sum Possible Equal Sum of Three Stacks177
856Minimum number of jumps to reach end177
857Check if a given array can represent Preorder Traversal of Binary Search Tree177
858Check if stack elements are pairwise consecutive177
859Sliding Window Maximum177
860Tree Traversal (Preorder, Inorder & Postorder)176
861Guess Number Higher or Lower LeetCode Solution176
862Count Distinct Elements in Every Window of Size K176
863An Interesting Method to generate Binary Numbers from 1 to n176
864Union and Intersection of two Linked Lists176
865Path with maximum average value176
866Matrix Chain Multiplication176
867Minimum Sum Path in a Triangle176
868Minimum swaps to make sequences increasing176
869Sum of nearest smaller and greater number176
870Valid Parentheses Leetcode Solution176
871Find the subarray with least average176
872Partition List Leetcode Solution176
873Find the Only Repetitive Element Between 1 to N-1176
874Subset with sum divisible by m176
875Alien Dictionary LeetCode Solution176
876Remove Duplicates from Sorted List LeetCode Solution176
877Count ways to reach the nth stair using step 1, 2 or 3175
878Get Maximum in Generated Array Leetcode Solution175
879Design a Stack With Increment Operation Leetcode Solution175
880Spiral Matrix II Leetcode Solution175
881Interval Tree175
882Dividing Array into Pairs With Sum Divisible by K175
883Convert BST to Min Heap175
884Can Place Flowers LeetCode Solution175
885Sorted Array to Balanced BST175
886Find distance between two nodes of a Binary Tree174
887Number of Distinct Islands Leetcode Solution174
888Brightest Position on Street LeetCode Solution174
889Sort Colors174
890Minesweeper LeetCode Solution174
891Infix to Postfix174
892Level order Traversal in Spiral Form174
893Time Based Key-Value Store LeetCode Solution174
894Check whether a given Binary Tree is Complete or not174
895Least Number of Unique Integers after K Removals Leetcode Solution174
896GCDs of given index ranges in an array174
897Sequences of given length where every element is more than or equal to twice of previous174
898Range LCM Queries173
899Set Matrix Zeroes Leetcode Solution173
900Median of Two Sorted Arrays173
901Maximum Score After Splitting a String Leetcode Solution173
902Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i173
903Shortest Word Distance Leetcode Solution173
904Maximum size subarray sum equals k173
905Pattern Occurrences using Stack173
906Destination City Leetcode Solution173
907Diagonal Traverse LeetCode Solution173
908Find all triplets with zero sum173
909Diagonal Traversal LeetCode Solution173
910Count Negative Numbers in a Sorted Matrix LeetCode Solution173
911Guess Number Higher or Lower II173
912Water Bottles Leetcode Solution173
913Friends Pairing Problem173
914Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution173
915Range sum queries without updates173
916Iterative Postorder Traversal Using Two Stacks173
917Robot Bounded In Circle LeetCode Solution172
918Lexicographical Numbers Leetcode Solution172
919Check if any two intervals overlap among a given set of intervals172
920Insert into a Binary Search Tree Leetcode Solution172
921Rearrange an Array Such that arr[i] is equal to i172
922Delete And Earn172
923Count Submatrices With All Ones LeetCode Solution171
924Averages of Levels in Binary Tree171
925Convert Sorted List to Binary Search Tree171
926Alien Dictionary171
927Difference Array | Range update query in O(1)171
928All Unique Triplets that Sum up to a Given Value171
929A program to check if a binary tree is BST or not171
930Find Common Characters Leetcode Solution170
931My Calendar I LeetCode Solution170
932Construct Complete Binary Tree from its Linked List Representation170
933Binary array after M range toggle operations170
934Special Positions in a Binary Matrix Leetcode Solution170
935Spiral Matrix III LeetCode Solution170
936Check if the given array can represent Level Order Traversal of Binary Search Tree170
937Construct the Rectangle Leetcode Solution170
938Rearrange Spaces Between Words Leetcode Solution170
939Three way partitioning of an array around a given range170
940Analyze User Website Visit Pattern LeetCode Solution170
941Three Consecutive Odds Leetcode Solution170
942K’th Largest Element in BST when modification to BST is not allowed170
943Binary Tree Longest Consecutive Sequence LeetCode Solution170
944Count Subarrays with Same Even and Odd Elements170
945Product of Array Except Self LeetCode Solution170
946Trim a Binary Search Tree170
947Minimum Height Trees LeetCode Solution169
948Remove Duplicates from Sorted List II LeetCode Solution169
949Palindrome Partitioning Leetcode Solution169
950Create Maximum Number169
951Number of Equivalent Domino Pairs Leetcode Solution169
952Queue using Stacks169
953Maximum Frequency Stack Leetcode Solution169
954Vertical sum in a given binary tree169
955Intersection of Two Linked Lists LeetCode Solution169
956Merge Two Sorted Lists Leetcode169
957BFS for Disconnected Graph168
958Longest Palindromic Subsequence168
959Strongly Connected Component168
960Largest area rectangular sub-matrix with equal number of 1’s and 0’s168
961Queries for GCD of all numbers of an array except elements in a given range168
962Word Break168
963Maximize Sum of Array after K Negations Leetcode Solution168
964Longest subsequence such that difference between adjacents is one167
965Kth Smallest Element in a BST Leetcode Solution167
966Maximum Product Subarray167
967Construct BST from its given Level Order Traversal167
968Sign of the Product of an Array LeetCode Solution167
969Print Fibonacci sequence using 2 variables167
970Reverse Nodes in K-Group167
9714Sum167
972Climbing stairs167
973Count subarrays where second highest lie before highest167
974Depth First Search (DFS) for a Graph167
9753 Sum167
976Count Primes in Ranges167
977Symmetric Tree167
978Stone Game II Leetcode166
979Combination Sum IV LeetCode Solution166
980Number of palindromic paths in a matrix166
981Count pair with Given Sum166
982Unique Paths II166
983Merging Intervals166
984Largest Number Leetcode Solution165
985Design Hit Counter LeetCode Solution165
986Serialize and Deserialize Binary Tree165
987Breadth First Search (BFS) for a Graph165
988The Maze III LeetCode Solution165
989Scramble String LeetCode Solution165
990Longest Nice Substring LeetCode Solution165
991Find Maximum of Minimum for Every Window Size in a Given Array165
992Find the First Circular Tour that visits all the Petrol Pumps165
993Maximum Subarray Sum Excluding Certain Elements165
994Find number of pairs in an array such that their XOR is 0165
995String Matching in an Array Leetcode Solution165
996Palindrome Partitioning164
997Height of a generic tree from parent array164
998Maximum Product of Indexes of Next Greater on Left and Right164
999Binary Search Tree Delete Operation164
1000Maximum Length of Repeated Subarray164
1001Find the Difference Leetcode Solution164
1002K Closest Points to Origin Leetcode Solution164
1003Valid Boomerang Leetcode Solution164
1004Can Make Arithmetic Progression From Sequence Leetcode Solution164
1005Largest Substring Between Two Equal Characters Leetcode Solution164
1006Next Permutation Leetcode Solution164
1007Asteroid Collision LeetCode Solution164
1008Count pairs from two sorted arrays whose sum is equal to a given value x163
1009Remove Duplicates from Sorted Array II Leetcode Solution163
1010K maximum sums of overlapping contiguous sub-arrays163
1011The Painter’s Partition Problem163
1012Graph Valid Tree LeetCode Solution163
1013Consecutive Characters LeetCode Solution163
1014Newman-Conway Sequence163
1015Kth Smallest Element in a Sorted Matrix LeetCode Solution163
1016Print Next Greater Number of Q queries163
1017Shortest Completing Word Leetcode Solution163
1018Balanced Binary Tree163
1019Maximum length subsequence with difference between adjacent elements as either 0 or 1163
1020Generate Parentheses Leetcode Solution162
1021Maximum difference between frequency of two elements such that element having greater frequency is also greater162
1022Collect maximum points in a grid using two traversals162
1023Minimum Index Sum of Two Lists162
1024Maximum Sum of 3 Non-Overlapping Subarrays162
1025Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space162
1026Length of Longest Fibonacci Subsequence162
1027Segment Tree162
1028Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution162
1029Decrypt String from Alphabet to Integer Mapping Leetcode Solution162
1030Friends Of Appropriate Ages LeetCode Solution162
1031Level Order Traversal of Binary Tree162
1032Find postorder traversal of BST from preorder traversal162
1033Validate Binary Search Tree162
1034Invalid Transactions LeetCode Solution162
1035Maximum Number of Ways to Partition an Array LeetCode Solution162
1036Find Duplicate Subtrees162
1037Number Of Longest Increasing Subsequence161
1038Next Greater Element III LeetCode Solution161
1039Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’161
1040Move all negative elements to end in order with extra space allowed161
1041First missing positive161
1042Merge Sort161
1043Find a Peak Element II LeetCode Solution161
1044Boolean Parenthesization Problem161
1045Largest divisible pairs subset161
1046Available Captures for Rook Leetcode Solution161
1047Make The String Great Leetcode Solution161
1048Boundary Traversal of binary tree160
1049Binary Search Tree160
1050Custom Sort String Leetcode Solution160
1051Compute nCr % p160
1052Bitwise AND of Numbers Range LeetCode Solution160
1053Construct Binary Tree from given Parent Array representation160
1054Advantages of BST over Hash Table160
1055Construction of Longest Increasing Subsequence (N log N)160
1056Build an Array With Stack Operations Leetcode Solution160
1057Kill Process LeetCode Solution160
1058Insertion in a Binary Tree160
1059Rearrange array such that even positioned are greater than odd160
1060Minimum Size Subarray Sum159
1061Rearrange array such that even index elements are smaller and odd index elements are greater159
1062Iterative Depth First Traversal of Graph159
1063Print Right View of a Binary Tree159
1064Count minimum steps to get the given desired array159
1065Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution159
1066Maximum subsequence sum such that no three are consecutive158
1067Employee Importance LeetCode Solution158
1068Subarrays with K Different Integers Leetcode Solution158
1069Double the first element and move zero to end158
1070Defanging an IP Address LeetCode Solution158
1071Largest BST Subtree LeetCode Solution158
1072Path Sum II LeetCode Solution158
1073Remove Palindromic Subsequences Leetcode Solution158
1074Find Peak Element158
1075Partition Equal Subset Sum158
1076Morris Inorder Traversal157
1077Recover Binary Search Tree Leetcode Solution157
1078Add two numbers157
1079Maximum weight transformation of a given string157
1080Level order traversal using two Queues157
1081Find maximum difference between nearest left and right smaller elements157
1082Regular Expression Matching Regular Expression Matching LeetCode Solution157
1083Smallest Common Region Leetcode Solution157
1084Ugly Numbers156
1085Remove duplicates from sorted array156
1086Longest Bitonic Subsequence156
1087Ugly Number II LeetCode Solution156
1088Lowest Common Ancestor156
1089Implement Trie (Prefix Tree) Leetcode Solution156
1090Binary Tree Right Side View LeetCode Solution156
1091Palindrome Permutation LeetCode Solution156
1092Find whether a subarray is in form of a mountain or not156
1093Bus Routes Leetcode Solution155
1094Number of siblings of a given Node in n-ary Tree155
1095Number of Closed Islands Leetcode Solution155
1096Super Ugly Number155
1097Increasing Triplet Subsequence LeetCode Solution155
1098Populating Next Right Pointers in Each Node Leetcode Solution155
1099Maximize Distance to Closest Person LeetCode Solution155
1100Palindromic Substrings Leetcode Solution155
1101Valid Tic-Tac-Toe State LeetCode Solution154
1102Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution154
1103Iterative method to find ancestors of a given binary tree154
1104Divisible Pairs Counting154
1105Path Sum154
1106Print all triplets in sorted array that form AP154
1107Reformat The String Leetcode Solution154
1108Sum of Even Numbers After Queries154
1109Binary Tree Data Structure153
1110Cells with Odd Values in a Matrix LeetCode Solution153
1111Moser-de Bruijn Sequence153
1112Thousand Separator Leetcode Solution153
1113Search in Sorted Rotated Array153
1114Find the minimum distance between two numbers153
1115Find Three Element From Different Three Arrays Such That a + b + c = sum153
1116Day of the Year Leetcode Solution153
1117Level of Each node in a Tree from source node152
1118Mean of Array After Removing Some Elements Leetcode Solution152
1119Count Largest Group Leetcode Solution152
1120Root to Leaf path with target sum Leetcode Solutions152
1121Find Smallest Range Containing Elements from k Lists152
1122Products of ranges in an array152
1123Search Insert Position152
1124Minimum Absolute Difference in BST Leetcode Solution152
1125Number of Students Doing Homework at a Given Time Leetcode Solution152
1126Kth Smallest Product of Two Sorted Arrays LeetCode Solution152
1127Distinct Subsequences151
1128Write Code to Determine if Two Trees are Identical151
1129Longest Increasing Consecutive Subsequence151
1130Serialize and Deserialize Binary Tree LeetCode Solution151
1131Bottom View of a Binary Tree151
1132Clone a Binary Tree with Random Pointers151
1133Maximum Product Subarray150
1134Minimum Moves to Equal Array Elements LeetCode Solution150
1135Maximum Product of Splitted Binary Tree LeetCode Solution150
1136Constant time range add operation on an array150
1137Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1138Longest Subarray of 1’s After Deleting One Element LeetCode Solution150
1139Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution150
1140Construct K Palindrome Strings LeetCode Solution150
1141Closest Leaf in a Binary Tree LeetCode Solution150
1142Minimum sum of squares of character counts in a given string after removing k characters150
1143Maximum Depth Of Binary Tree150
1144Third Maximum Number Leetcode Solution150
1145Topological Sorting150
1146Convert BST into a Min-Heap without using array150
1147Prime Palindrome LeetCode Solution150
1148Find maximum length Snake sequence150
1149Rotate Array149
1150Golomb sequence149
1151Diameter of N-Ary Tree LeetCode Solution149
1152Swap Nodes In Pairs149
1153Queries for Number of Distinct Elements in a Subarray149
1154Longest Repeated Subsequence149
1155Search an Element in Sorted Rotated Array148
1156Subset Sum Problem in O(sum) space148
1157Count even length binary sequences with same sum of first and second half bits148
1158Priority Queue148
1159Minimum Score Triangulation of Polygon Leetcode Solution148
1160Print modified array after executing the commands of addition and subtraction148
1161Web Crawler LeetCode Solution148
1162Reformat Date LeetCode Solution148
1163Search Suggestions System LeetCode Solution148
1164Contiguous Array LeetCode Solution147
1165Find Largest Value in Each Tree Row LeetCode Solution147
1166Closest Binary Search Tree Value Leetcode Solution147
1167Delete Nodes and Return Forest Leetcode Solution147
1168Cutting a Rod147
1169Find a sorted subsequence of size 3 in linear time147
1170Maximize sum of consecutive differences in a circular array147
1171Kth Smallest Number in Multiplication Table Leetcode Solution147
1172Count Pairs Whose Products Exist in Array146
1173Given a binary tree, how do you remove all the half nodes?146
1174Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1175Decision Tree146
1176Transform a BST to Greater sum Tree146
1177Matchsticks to Square Leetcode Solution146
1178Red-Black Tree Introduction146
1179Maximum Binary Tree146
1180Minimum Swaps To Make Sequences Increasing LeetCode Solution145
1181Reverse a Path in BST using Queue145
1182Possible Bipartition LeetCode Solution145
1183Maximum sum of a path in a Right Number Triangle145
1184Minimum Sideway Jumps LeetCode Solution145
1185Binary Tree to Binary Search Tree Conversion145
1186K’th Largest element in BST using constant extra space145
1187Sum of Left Leaves LeetCode Solution144
1188Factorial Trailing Zeroes LeetCode Solution144
1189First Bad Version144
1190Valid Triangle Number144
1191Decrease Elements To Make Array Zigzag LeetCode Solution144
1192Find the smallest binary digit multiple of given number144
1193Path Crossing Leetcode Solution144
1194Maximum Value at a Given Index in a Bounded Array LeetCode Solution144
1195Check Array Formation Through Concatenation Leetcode Solution144
1196Replace two consecutive equal values with one greater144
1197Maximum number of segments of lengths a, b and c144
1198Concatenation of Array LeetCode Solution144
1199Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution144
1200Merge two BSTs with limited extra space144
1201Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution143
1202Maximum sum of pairs with specific difference143
1203Maximum sum bitonic subarray143
1204Print n terms of Newman-Conway Sequence143
1205Number of Orders in the Backlog Leetcode Solution143
1206Perfect Squares LeetCode Solution143
1207Guess The Word142
1208Queue Reconstruction by Height142
1209Swapping Nodes in a Linked List Leetcode Solution142
1210Valid Perfect Square LeetCode Solution142
1211Queries on Probability of Even or Odd Number in given Ranges142
1212Divide Two Integers Leetcode Solution142
1213Convert Sorted Array to Binary Search Tree LeetCode Solutions142
1214Sliding Window Median Leetcode Solution142
1215New 21 Game141
1216How to print maximum number of A’s using given four keys141
1217Integer Break LeetCode Solution141
1218Kth Smallest Element in a BST140
1219Lowest Common Ancestor in Binary Search Tree140
1220Check if all levels of two Binary Tree are anagrams or not140
1221Find minimum number of merge operations to make an array palindrome140
1222Champagne Tower LeetCode Solution140
1223Graph and its representation140
1224Lowest Common Ancestor of a Binary Tree Leetcode Solution140
1225Array Queries for multiply replacements and product140
1226Maximum Array from Two given Arrays Keeping Order Same139
1227Range Sum Query using Sparse Table139
1228Moving Stones Until Consecutive Leetcode Solution139
1229Find Minimum in Rotated Sorted Array II LeetCode Solution139
1230Flatten 2D Vector LeetCode Solution139
1231Merge k Sorted Lists Leetcode Solution139
1232Longest Common Prefix Using Word by Word Matching139
1233Contiguous Array138
1234The kth Factor of n Leetcode Solution138
1235Design Skiplist LeetCode Solution138
1236BST to a Tree with Sum of all Smaller Keys138
1237Range Queries for Longest Correct Bracket Subsequence138
1238Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution138
1239Mean of range in array138
1240Write a function to get the intersection point of two Linked Lists138
1241Largest Plus Sign Leetcode Solution137
1242Maximize Elements Using Another Array137
1243LRU Cache Leetcode Solution137
1244Find k-th smallest element in BST (Order Statistics in BST)137
1245Maximum Sum Increasing Subsequence137
1246Missing Number137
1247Maximum Product Subarray137
1248Print modified array after multiple array range increment operations137
1249Bold Words in String LeetCode Solution137
1250Min Cost Climbing Stairs LeetCode Solution136
1251Minimum Remove to Make Valid Parentheses LeetCode Solution136
1252Parallel Courses II LeetCode Solution136
1253Count Subsets Having Distinct Even Numbers136
1254Power of Two135
1255Graph Cloning135
1256Check in binary array the number represented by a subarray is odd or even135
1257Check Completeness of a Binary Tree LeetCode Solution134
1258Check if each internal node of a BST has exactly one child134
1259Different Ways to Add Parentheses Leetcode Solution134
1260Image Overlap LeetCode Solution134
1261Verify Preorder Serialization of a Binary Tree134
1262Minimum Time to Collect All Apples in a Tree LeetCode Solution134
1263Arithmetic Slices II – Subsequence LeetCode Solution134
1264Smallest Range II Leetcode Solution133
1265Check for Identical BSTs without building the trees133
1266Check if two nodes are on the same path in a Tree133
1267Longest Substring Without Repeating Characters Leetcode Solution132
1268Orderly Queue LeetCode Solution132
1269Print Ancestors of a Given Binary Tree Node Without Recursion132
1270Koko Eating Bananas LeetCode Solution132
1271Symmetric Tree LeetCode Solution Leetcode Solution132
1272Next greater element131
1273Excel Sheet Column Title LeetCode Solution131
1274Arranging Coins Leetcode Solution130
1275Count and Toggle Queries on a Binary Array129
1276Vertical Order Traversal of Binary Tree LeetCode Solution129
1277Number of elements less than or equal to a given number in a given subarray129
1278Merge Sorted Array129
1279Largest Submatrix With Rearrangements LeetCode Solution128
1280Palindrome Partitioning128
1281Array Nesting Leetcode Solution128
1282Palindrome Number LeetCode Solution127
1283Newman–Shanks–Williams prime126
1284Add Two Numbers II Leetcode Solution126
1285Maximum product of an increasing subsequence126
1286Check If a String Can Break Another String Leetcode Solution126
1287Peeking Iterator LeetCode Solution126
1288Find the Winner of the Circular Game LeetCode Solution126
1289Check if X can give change to every person in the Queue125
1290Insert Delete GetRandom O(1) Leetcode Solution125
1291Range Minimum Query (Square Root Decomposition and Sparse Table)125
1292Queries for Decimal Values of Subarrays of a Binary Array125
1293Find maximum average subarray of k length124
1294Continuous Subarray Sum LeetCode Solution123
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution123
1296Encoded String With Shortest Length LeetCode Solution123
1297Check given array of size n can represent BST of n levels or not123
1298Jump Game IV LeetCode Solution121
1299Random Pick Index LeetCode Solution121
1300Binary Tree to Binary Search Tree Conversion using STL set121
1301Reach a Number LeetCode Solution120
1302Number of indexes with equal elements in given range120
1303Minimum Number of People to Teach LeetCode Solution120
1304Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution120
1305Convert a BST to a Binary Tree such that sum of all greater keys is added to every key118
1306Minimum Total Space Wasted With K Resizing Operations LeetCode Solution117
1307Convert to Base -2 LeetCode Solution116
1308Design A Leaderboard Leetcode Solution116
1309Queries on XOR of greatest odd divisor of the range115
1310Design Underground System Leetcode Solution114
1311Shifting Letters LeetCode Solution113
1312Print Maximum Length Chain of Pairs111
1313Detect Capital Leetcode Solution111
1314Minimum Swaps to Group All 1’s Together Leetcode Solution110
1315Top K Frequent Elements LeetCode Solution110
1316Minimum Path Sum Leetcode Solution108
1317Count Sub Islands LeetCode Solution108
1318Substring with Concatenation of All Words Leetcode Solution107
1319Odd Even Linked List Leetcode Solution107
1320Monotonic Array Leetcode Solution105
1321Longest Common Subsequence LeetCode Solution102
1322Find the Town Judge LeetCode Solution101
1323Decode String Leetcode Solution101
1324Binary Tree Inorder Traversal LeetCode Solution101
1325Maximum Population Year LeetCode Solution100
1326Shortest Unsorted Continuous Subarray LeetCode Solution96
1327Rectangle Overlap LeetCode Solution95
1328Best Meeting Point LeetCode Solution94
1329Maximum Population Year LeetCode Solution93
1330Find the Town Judge LeetCode Solution92
1331Flatten Binary Tree to Linked List LeetCode Solution92
1332Sum Root to Leaf Numbers LeetCode Solution91
1333Insert into a Sorted Circular Linked List LeetCode Solution91
1334Design Add and Search Words Data Structure LeetCode Solution90
1335Reveal Cards In Increasing Order Leetcode Solution88
1336Stone Game IV LeetCode Solution88
1337Range Sum Query 2D – Immutable LeetCode Solution87
1338Is Graph Bipartite? LeetCode Solution87
1339Valid Triangle Number LeetCode Solution86
1340Score of Parenthesis LeetCode Solution85
1341Divide Chocolate LeetCode Solution81
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution70
1344Reverse Integer Leetcode Solution68
1345Rotate String LeetCode Solution65
1346Find K Closest Elements LeetCode Solution64
1347Sort Colors LeetCode Solution63
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution61
1349Excel Sheet Column Number LeetCode Solution57
1350Maximum Size Subarray Sum Equals k Leetcode Solution51
1351H-Index Leetcode Solution46
1352Camelcase Matching Leetcode Solution45
1353Valid Anagram Leetcode Solution44
1354Most Stones Removed with Same Row or Column LeetCode Solution44
1355Container With Most Water LeetCode Solution43
1356High Five LeetCode Solution43
1357Group Anagrams LeetCode Solution42
1358Sliding Window Maximum LeetCode Solution42
1359Next Permutation LeetCode Solution41
1360Find Peak Element LeetCode Solution40
1361Binary Search LeetCode Solution40
1362Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution39
1363Paint House LeetCode Solution37
1364Valid Triangle Number LeetCode Solution36
1365Flatten Binary Tree to Linked List LeetCode Solution36
1366Minimum Number of Arrows to Burst Balloons LeetCode Solution36
1367Unique Binary Search Trees LeetCode Solution35
1368Isomorphic Strings LeetCode Solution35
1369Next Greater Element I Leetcode Solution35
1370Sentence Screen Fitting LeetCode Solution35
1371Count Good Nodes in Binary Tree LeetCode Solution34
1372The Number of Weak Characters in the Game LeetCode Solution34
1373Group Shifted Strings Leetcode Solution34
1374Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution32
1375Split Linked List in Parts Leetcode Solution32
1376Swim in Rising Water LeetCode Solution32
1377Closest Binary Search Tree Value II LeetCode Solution31
1378Peak Index in a Mountain Array LeetCode Solution31
1379Single Element in a Sorted Array LeetCode Solution31
1380Best Time to Buy and Sell Stock IV LeetCode Solution29
1381Find First and Last Position of Element in Sorted Array LeetCode Solution29
1382Max Sum of Two Non-Overlapping Subarrays LeetCode Solution28
1383All Possible Full Binary Trees LeetCode Solution28
1384Minimum Increment to Make Array Unique Leetcode Solution27
1385Validate Stack Sequences LeetCode Solution27
1386Lowest Common Ancestor of a Binary Search Tree Leetcode Solution27
1387Break a Palindrome LeetCode Solution25
1388Detect Squares LeetCode Solution25
1389Implement strStr() LeetCode Solution25
1390Implement Rand10() Using Rand7() Leetcode Solution25
1391Greatest Sum Divisible by Three LeetCode Solution24
1392Trapping Rain Water II LeetCode Solution24
1393Stone Game IV LeetCode Solution23
1394Reverse Nodes in k-Group LeetCode Solution23
1395Remove All Ones With Row and Column Flips Leetcode Solution22
1396Contains Duplicate LeetCode Solution22
1397Invert Binary Tree LeetCode Solution22
1398Fibonacci Number LeetCode Solution21
1399Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution20
1400Design Bounded Blocking Queue LeetCode Solution20
1401Total Hamming Distance LeetCode Solution16
1402Candy LeetCode Solution16
1403Unique Paths III LeetCode Solution14
Translate »