Swim in Rising Water LeetCode Solution

Difficulty Level Hard
Frequently asked in Amazon Apple DoorDash Facebook Google MicrosoftViews 4

Problem Statement:

Swim in Rising Water LeetCode Solution : You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j).

The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a square to another 4-directionally adjacent square if and only if the elevation of both squares individually is at most t. You can swim infinite distances in zero time. Of course, you must stay within the boundaries of the grid during your swim.

Return the least time until you can reach the bottom right square (n - 1, n - 1) if you start at the top left square (0, 0).

Examples:

Input:

 grid = [[0,2],[1,3]]

Output:

 3
Explanation:
At time 0, you are in grid location (0, 0).
You cannot go anywhere else because 4-directionally adjacent neighbors have a higher elevation than t = 0.
You cannot reach point (1, 1) until time 3.
When the depth of water is 3, we can swim anywhere inside the grid.

Approach:

Idea:

We will be solving the problem using Binary Search and BFS.  The idea is to use a binary search for the minimum time T for which you can reach the end. For every possible value of T, we will check if it’s possible to reach the last cell or not and will try to minimize this value.

Swim in Rising Water LeetCode SolutionPin

Code for Swim in Rising Water LeetCode Solution:

Swim in Rising Water C++ Solution:

class Solution {
public:
    int n;
    bool search(vector<vector<int>>& grid, int depth){
        queue<pair<int,int>> q;
        q.push({0,0});
        
        vector<vector<int>> dirs = {{0,1},{1,0},{0,-1},{-1,0}};
        set<pair<int,int>> vis;
        while(!q.empty()){
            pair<int,int> top = q.front();
            q.pop();
            for(auto it:dirs){
                int x = top.first + it[0];
                int y = top.second + it[1];
                if(x==n-1 and y==n-1 and grid[x][y]<=depth)
                    return true;
                if(x>=0 and y>=0 and x<n and y<n and grid[x][y]<=depth and !vis.count({x,y})){
                    q.push({x,y});
                    vis.insert({x,y});
                }
            }
        }
        return false;
    }
    
    int swimInWater(vector<vector<int>>& grid) {
        n = grid.size();
        if(n==1)
            return 0;
        int l = grid[0][0];
        int r = 2500;
        int ans = INT_MAX;
        while(l<=r){
            int m = (l+r)/2;
            if(search(grid,m)){
                ans = min(ans,m);
                r = m-1;
            }
            else{
                l = m+1;
            }
        }
        return ans;
    }
};

Complexity Analysis of Swim in Rising Water LeetCode Solution:

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2831
2Java program to find the number of Nodes in a Binary Tree2508
3Reverse a string without affecting special characters2469
4Delete a node of a linked list at given position1982
5Palindrome using Recursion1882
6Insert nodes in a linked list in a sorted way (Ascending Order)1668
7Find elements pair from array whose sum equal to number1655
8Sort Elements by Frequency of Occurrences1638
9Write a program to print all permutations of a given string1614
10Quick Sort1545
11Find Minimum Distance Between Two Numbers in an Array1479
12Create a Doubly Linked List1453
13Reverse an Array1417
14Smallest window in a string containing all characters of another string1402
15Find a Triplet That Sum to a Given Value1364
16Recursively remove all adjacent duplicates1362
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1326
19Sum of numbers in String1324
20Smallest Positive Number Missing in an Unsorted Array1292
21Check if the Elements of an Array are Consecutive1261
22Detect a loop in the Linked List1246
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1223
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1208
27Recursive function to do substring search1206
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1130
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1112
32Maximum Subarray Sum using Divide and Conquer1107
33Remove characters from first string which are in second1075
34Find Leaders in an Array1064
35Swap nodes in the linked list1043
36Find the Number Occurring Odd Number of Times in an Array1008
37Arrange given Numbers to Form the Biggest Number II997
38Find the second most frequent character993
39Given a string find its first non-repeating character975
40Find Triplet in Array With a Given Sum968
41Total number of occurrences of a given item in the linked list959
42Given a sorted array and a number x, find the pair in array whose sum is closest to x959
43A Program to check if strings are rotations of each other or not952
44Print all possible words from phone digits939
45Find the Missing Number929
46Rearrange Positive and Negative Numbers Alternatively in Array925
47Longest Palindromic Substring910
48Segregate even and odd nodes in a linked list892
49Print Longest common subsequence887
50Union and Intersection of Two Linked Lists879
51Transform one string to another using minimum number of given operations873
52Check rearranged string can form a palindrome854
53Rearrange given Array in Maximum Minimum Form851
54Iterative Implementation of Quick Sort839
55Count Possible Triangles825
56Multiplication of Two Matrices808
57Check if the linked list is palindrome801
58Count of Triplets With Sum Less than Given Value800
59Rotate a Linked List800
60Stock Buy Sell to Maximize Profit797
61Insertion Sort770
62Concatenation of two strings768
63Tug of War766
64Print all duplicates in the input string762
65Count Number of Substrings with K Distinct Character’s761
66Find Nearest Greater and Smaller Element750
67The Celebrity Problem744
68Find Pythagorean Triplets from Array742
69Remove ‘b’ and ‘ac’ from a given string737
70Reverse String Without Temporary Variable737
71Find all Common Elements in Given Three Sorted Arrays734
72Remove all duplicates in an unsorted linked list714
73Find the Row with Maximum Number of 1’s712
74Find the Peak Element from an Array704
75Find the subarray whose sum is equal to a given number X700
76Remove Minimum Characters so that Two Strings Become Anagrams697
77Addition of Two Matrices691
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s682
81Implement Two Stacks in an Array681
82Maximum Sum of Non Consecutive Elements674
83Maximum Product Subarray II661
84Lexicographic rank of string660
85Check if Two given Matrices are Identical653
86Multiplication of Previous and Next653
87Subtraction of Two Matrices641
88Move All the Zeros to the End of the Given Array637
89Merge K Sorted Arrays and Print Sorted Output637
90Divide a string in N equal parts631
91Online Algorithm for Checking Palindrome in a Stream629
92Form Minimum Number from Given Sequence of D’s and I’s628
93Remove recurring digits in a given number622
94Check whether two strings are anagram of each other621
95Maximum Circular Subarray Sum616
96Sort a linked list that is sorted alternating ascending and descending614
97Sort a stack using a temporary stack613
98Move last element of the Linked List at first place610
99Find the Minimum Element in a Sorted and Rotated Array610
100Subarray and Subsequence606
101First Circular Tour to Visit all the Petrol Bunks603
102Largest Subarray with Equal Number of 0’s and 1’s602
103Compare two strings(linked lists)599
104Flattening a linked list599
105Maximum Element in an Array which is Increasing and then Decreasing595
106Palindrome Permutations of a String591
107Elements Appear more than N/K times in Array584
108Palindromes in a given range584
109Run length encoding582
110Print all permutations with repetition582
111Majority Element581
112Minimum insertions to form a shortest palindrome578
113Pangram Checking578
114Merge a linked list into another at alternate positions570
115Minimum Characters to be Added at Front to Make String Palindrome570
116Remove all duplicates in a sorted linked list569
117Rearrange a given linked list in-place569
118Most repeating character in a string568
119Minimum number of Merge Operations to make an Array Palindrome567
120Rotate string to get lexicographically minimum string564
121Repeated Subsequence of Length Two or More561
122Print all anagrams together in a sequence of words559
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem546
125Two Sum Leetcode Solution544
126Merge Overlapping Intervals II542
127Clone a Linked List with next and random pointer541
1283Sum Leetcode Solution539
129Transpose of a Matrix533
130Size of The Subarray With Maximum Sum530
131Remove Extra Spaces from a String529
132Removing Spaces from a String using stringstream527
133Remove duplicates from a string526
134Partition Problem524
135Check if a given string is a rotation of a palindrome524
136Smallest Palindrome after Replacement523
137Maximum Sum Increasing Subsequence522
138Longest Palindrome can be Formed by Removing or Rearranging Characters522
139Check whether Strings are K Distance Apart or Not514
140Generate all Binary Strings from Given Pattern510
141Length of Longest valid Substring507
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized506
143Insert Node in the Sorted Linked List505
144Delete Last Occurrence504
145Check if Two given Strings are Isomorphic to each other500
146Maximum difference between two elements such as larger element comes after smaller494
147Program to Toggle all Characters in a String492
148Given string is interleaving of two other strings or not489
149Count Minimum Steps to Get the given Array485
150Merge sort better than quick sort for linked lists482
151Number of Smaller Elements on Right Side481
152Check length of a String is Equal to the Number Appended at its Last479
153Find Pair with Given Difference479
154Check if all Rows of a Matrix are Circular Rotations of Each Other477
155Longest Common Prefix using Divide and Conquer474
156Find nth node of the Linked list from the end473
157Find a Fixed Point in a Given Array467
158Sort 0s 1s and 2s in an Array466
159Print all interleavings of given two strings464
160Compare Two Version Numbers464
161Reverse words in a given string462
162Find the Subarray of given length with Least Average461
163Merge two sorted linked lists such that merged list is in reverse order459
164Print Reverse of a string (Recursion)459
165Reorder Array Using Given Indexes459
166Split linked list using alternate nodes457
167Median of Two Sorted Arrays LeetCode Solution456
168Print string of odd length in ‘X’ format445
169Print all Palindromic Partitions of a String440
170Find K Length Subarray of Maximum Average440
171Find Element Using Binary Search in Sorted Array439
172Swap Kth Node from beginning with Kth Node from End437
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions425
175Flatten a multilevel linked list423
176Shortest Superstring Problem421
177Maximum Length of Chain Pairs420
178Check if String Follows Order of Characters by a Pattern or not417
179Sorting a K Sorted Array413
180Sort a String According to Another String411
181Longest Span with same Sum in two Binary Arrays II404
182Reverse a Linked List in groups401
183Find a Sorted Subsequence of size 3400
184Program to add two binary digits397
185Recursively print all the sentences that can be formed from list of word lists397
186Find the two Numbers with Odd Occurrences in an Unsorted Array393
187Longest Common Prefix Using Binary Search II392
188Reverse a Singly Linked List (Iterative/Non-Recursive)389
189Caesar Cipher388
190Kth Non-repeating Character386
191Rearrange a linked list in Zig-Zag384
192Check if String can Become Empty by Recursively Deleting given Substring383
193Longest Common Prefix Word by Word Matching380
194Rotate Image by 90 degrees380
195Pancake Sorting380
196Permutations of a Given String Using STL373
197Perfect Reversible String371
198Increasing Subsequence of Length three with Maximum Product368
199Merging Two Sorted Arrays368
2001`s and 2`s complement of binary number365
201Find First non-repeating character in a string365
202Sort a linked list with 0s, 1s and 2s365
203Find the point where a monotonically increasing function becomes positive first time364
204Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes363
205Four Elements that Sum to Given362
206List items containing all characters of a given word360
207Delete N nodes after M357
208Longest Common Prefix using Character by Character Matching353
209Count Number of Occurrences in a Sorted Array351
210Palindrome string (number)349
211Split a string347
212Minimum Characters to be Removed to Make a Binary String Alternate343
213Recursive Implementation of atoi()341
214Check if a Linked list of Strings form a Palindrome340
215Sorting the array of strings337
216Print All Distinct Elements of the Array337
217Even Substring Count336
218Maximum occurring character in a string334
219Convert a String that is Repetition of a Substring of Length K334
220Valid Parentheses LeetCode Solution332
221Find the first Repeating Number in a Given Array332
222Reverse a singly linked list recursively331
223Print Shortest Path to Print a String on Screen329
224Can we reverse a linked list in less than O(n) time ?328
225Reverse a String using Stack326
226Binary Tree to Doubly linked list326
227Convert string1 to string2 in one edit325
228wildcard character matching325
229Sort Elements by Frequency II323
230Nth Character in Concatenated Decimal String323
231Maximum Subarray Leetcode Solution321
232Lower Case To Upper Case318
233Count the number of words318
234Merge Two Sorted Arrays316
235Split Four Distinct Strings315
236Find the Lost Element From a Duplicated Array313
237Find middle of the Linked List311
238Longest Common Subsequence with Permutations309
239Count the Pairs at Same Distance as in English Alphabets306
240Matrix Chain Multiplication using Dynamic Programming302
241Next Greater Element in an Array301
242Palindrome Permutation295
243Roman to Integer Leetcode Solution292
244Find All Pairs With a Given Difference290
245Find Nth Node289
246Searching a node in a Binary Search Tree288
247Triplet from three linked lists with given sum286
248Delete a Tree283
249String(represents an integer) to value283
250Reverse a String283
251Word Search Leetcode Solution281
252Reverse Bits281
253Delete a node under given conditions280
254Print all Possible Ways to Break a String in Bracket Form280
255Change Gender of a given String278
256Binary Tree278
257How to Efficiently Implement k Stacks in a Single Array?275
258Sort an array of strings275
259First non Repeating Element274
260Meeting Rooms II LeetCode Solution271
261Longest Common Extension271
262Number of sub-strings which recursively add up to 9271
263Count Pairs With Given Sum271
264Toeplitz Matrix270
265Remove middle points in a linked list of line segments270
266Move all negative elements to one side of array269
267Repeated Substring Pattern269
268Remove spaces from a string266
269Longest Palindromic Substring LeetCode Solution266
270N queen problem265
271Shuffle a given Array264
272Min Stack262
273Number of Islands LeetCode Solution260
274Cuckoo sequence program259
275Dijkstra Algorithm257
276Max stack256
277House Robber Leetcode Solution256
278Find, second, frequent, character255
279Most Frequent Element in an Array254
280Minimize the maximum difference between the heights253
281Clone a linked list with next and random pointer (Hashing)252
282Search Insert Position Leetcode Solution251
283Expression Evaluation250
284Fibonacci numbers250
285Sort linked which is sorted on absolute values249
286Plus One Leetcode Solution247
287Sudoku Solver247
288Valid Palindrome Leetcode Solution247
289Subset Leetcode247
290KMP Algorithm246
291Number Of 1 bits246
292Combination Sum Leetcode Solution245
293Reverse words in a string244
294How to Delete a Linked List244
295Min Stack Leetcode Solution243
296Evaluation of Postfix Expression243
297Word Search242
298Backspace String Compare239
299Set Matrix Zeroes237
300Sqrt(x) Leetcode Solution236
301Merge Sorted Arrays Leetcode Solution235
302Reversing a Queue235
303Pair of Positive Negative Values in an Array234
304Rabin Karp Algorithm234
305Subarray with 0 sum233
306Common elements in all rows of a given matrix233
307Tower Of Hanoi231
308Contains Duplicate II Leetcode Solution230
309Delete middle element of a stack230
310Product of array except self229
311Intersection of Two Arrays II Leetcode Solution228
312Combination Sum228
313Integer to Roman Leetcode Solution227
314Pascal Triangle Leetcode227
315String Compression227
316Reverse individual words225
317Count subarrays with equal number of 1’s and 0’s225
318Bellman Ford Algorithm224
319Minimum swaps required to bring all elements less than or equal to k together224
320Count of index pairs with equal elements in an array224
321Find Top K (or Most Frequent) Numbers in a Stream223
322Sliding Window Technique223
323Single Number Leetcode Solution223
324Implementation of Deque using Doubly Linked List223
325Construct Binary Tree from Given Inorder and Preorder Traversals222
326Minimum Value to Get Positive Step by Step Sum Leetcode Solution221
327Arithmetic Expression Evaluation221
328Add Binary Leetcode Solution221
329Contains Duplicate220
330Sort elements by frequency220
331Segregate even and odd numbers220
332Pow(x, n) Leetcode Solution219
333Second Most Repeated Word in a Sequence219
334Page Replacement Algorithms in Operating Systems219
335Palindrome Linked List Leetcode Solution219
336Postfix to Infix Conversion218
337Find sum of non-repeating elements (distinct) elements in an array218
338Group Words With Same Set of Characters217
339Design a stack that supports getMin() in O(1) time and O(1) extra space217
340Next Permutation217
341Count Odd Numbers in an Interval Range Leetcode Solution217
342Kruskal Algorithm216
343Maximum Number of Balloons Leetcode Solution216
344Smallest Subarray with k Distinct Numbers215
345Third Maximum Number Leetcode Solution215
346Scramble String214
347Convex Hull Algorithm214
348Top K Frequent Words213
349K-th Smallest Element in a Sorted Matrix213
350Find Lucky Integer in an Array Leetcode Solution213
351Longest Substring Without Repeating Characters LeetCode Solution213
352Permutations Leetcode Solution213
353Sum of minimum and maximum elements of all subarrays of size k213
354Find the Town Judge Leetcode Solution212
355Longest Common Prefix Leetcode Solution211
356Maximum Subarray211
357Sorting array using Stacks211
358Minimum operation to make all elements equal in array210
359Find Numbers with Even Number of Digits Leetcode Solution210
360Evaluate Division210
361Majority Element Leetcode Solution210
362First element occurring k times in an array209
363Count subarrays having total distinct elements same as original array209
364Special Number208
365Spiral Matrix LeetCode Solution208
366Number of Good Pairs Leetcode Solution208
367Prefix to Infix Conversion207
368Minimum Path Sum207
369Given two unsorted arrays find all pairs whose sum is x207
370Huffman Coding207
371Swap Nodes in Pairs Leetcode Solutions207
372Pascal’s Triangle II Leetcode Solution206
373Missing Number Leetcode Solution206
374Check if two arrays are equal or not206
375Best Time to Buy and Sell Stock  II Leetcode Solution205
376Reverse a Number Using Stack205
377Count Primes Leetcode Solutions205
378Merge Two Sorted Lists Leetcode Solutions205
379Reversing the First K elements of a Queue205
380Search in Rotated Sorted Array Leetcode Solution205
381Single Number204
382Sort Array by Increasing Frequency Leetcode Solution204
383Minimum Steps to reach target by a Knight204
384Find duplicates in a given array when elements are not limited to a range204
385Minimum Absolute Difference Leetcode Solution204
386Power of Two Leetcode Solution203
387Maximal Square203
388Group Anagrams203
389Matrix Diagonal Sum Leetcode Solution202
390House Robber II Leetcode Solution202
391Find All Numbers Disappeared in an Array Leetcode Solution202
392Top K Frequent Elements202
393Convert String To Int201
394Maximum possible difference of two subsets of an array201
395Sorting using trivial hash function201
396Fizz Buzz Leetcode201
397Unique Paths Leetcode Solution201
398Maximum Distance Between two Occurrences of Same Element in Array201
399Running Sum of 1d Array Leetcode Solution201
400How to Implement Stack Using Priority Queue or Heap?200
401Expression Contains Redundant Bracket or Not200
402Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
403Find Minimum In Rotated Sorted Array200
404Zigzag Conversion199
405Unique Paths199
406How Many Numbers Are Smaller Than the Current Number Leetcode Solution199
407Range Sum Query 2D – Immutable Leetcode Solution199
408Find the first repeating element in an array of integers199
409Subarray Sum Equals k199
410Max Consecutive Ones Leetcode Solution199
411Leetcode Permutations198
412Sort Integers by The Number of 1 Bit Leetcode Solution198
413Happy Number Leetcode Solution198
414Coin Change 2 Leetcode Solution198
415Find the Closest Palindrome number198
416Find Number of Employees Under every Employee198
417Subarray Sum Equals K LeetCode Solution197
418Find Winner on a Tic Tac Toe Game Leetcode Solution197
419Letter Case Permutation197
420Smallest Element Repeated Exactly K Times197
421Difference between highest and least frequencies in an array197
422Subset sum problem197
423Palindrome Substring Queries197
424Cumulative Frequency of Count of Each Element in an Unsorted Array197
425Decode String197
426Remove Duplicates from Sorted Array Leetcode Solution196
427Length of the largest subarray with contiguous elements196
428Check if Array Contains Contiguous Integers With Duplicates Allowed196
429Reverse Integer196
430Monotonic Array LeetCode Solution196
431Sort a stack using recursion195
432Best Time to Buy and Sell Stock III Leetcode Solution195
433Find top three repeated in array195
434Implement Stack and Queue using Deque195
435Reverse Vowels of a String Leetcode Solution194
436Capacity To Ship Packages Within D Days Leetcode Solution194
437Nth Catalan Number194
438Fibonacci Number LeetCode Solution194
439Count Substrings with equal number of 0s, 1s and 2s194
440Find The Duplicate Number193
441Reverse a Stack Using Recursion193
442Find Median from data Stream193
443Sum of Subarray Ranges Leetcode Solution193
444Generate a String With Characters That Have Odd Counts Leetcode Solution193
445LRU Cache Implementation193
446Reverse Words in a String III LeetCode Solution193
447Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
448Maximum Depth of Binary Tree Leetcode Solution193
449Print All Distinct Elements of a Given Integer Array193
450Print all subarrays with 0 sum193
451Integer to English words192
452Shuffle the Array Leetcode Solution192
453Delete a Node from linked list without head pointer192
454Trapping Rain Water Leetcode Solution192
455Subarrays with distinct elements192
456Check If N and Its Double Exist Leetcode Solution192
457Bipartite Graph192
458Prim’s Algorithm192
459Find the Duplicate Element191
460Merge Two Sorted Linked Lists191
461Find Common Characters Leetcode Solution190
462Priority Queue Using Singly Linked List190
463Kth largest element in an Array Leetcode Solutions190
464Sorting a Queue without Extra Space190
465Target Sum190
466Excel Sheet Column Number Leetcode Solution190
467Reverse a String190
468Find the Difference Leetcode Solution190
469Iterative Tower of Hanoi190
470Find all pairs (a, b) in an array such that a % b = k189
471Edit Distance189
472Fizz Buzz189
473Longest Common Subsequence189
474Balanced Binary Tree Leetcode Solution189
475Count and Say188
476Count pairs from two linked lists whose sum is equal to a given value188
477Kids With the Greatest Number of Candies Leetcode Solution188
478Concatenation of Array LeetCode Solution188
479Minimum Moves to Equal Array Elements Leetcode Solution188
480Reverse a linked list187
481Floyd Warshall Algorithm187
482Kth Largest Element in a Stream Leetcode Solution187
483Remove Minimum Number of Elements Such That no Common Element Exist in both Array187
484The K Weakest Rows in a Matrix Leetcode Solution187
485Find First and Last Position of Element in Sorted Array Leetcode Solution187
486Degree of an array187
487Number of Steps to Reduce a Number to Zero Leetcode Solution187
488Find elements which are present in first array and not in second187
489Next Greater Element I Leetcode Solution187
490Word Ladder LeetCode Solution187
491Find subarray with given sum (Handles Negative Numbers)186
492Merge Overlapping Intervals186
493Text Justification LeetCode Solution186
494Design Parking System Leetcode Solution186
495Longest Common Prefix using Trie186
496Zigzag Conversion LeetCode Solution185
497Multiply Strings Leetcode Solution185
498Shortest Palindrome185
499Count and Say Leetcode Solution185
500Find four elements that sum to a given value (Hashmap)185
501Prefix to Postfix Conversion185
502Flood Fill LeetCode185
503MiniMax Algorithm185
504Move Zeroes LeetCode Solution184
505Jump Game Leetcode Solution184
506Longest subarray not having more than K distinct elements184
507Valid Parenthesis String184
508Max Area of Island184
509Slowest Key Leetcode Solution184
510Top View of Binary Tree184
511Find N Unique Integers Sum up to Zero Leetcode Solution184
512Priority Queue in C++183
513Mobile Numeric Keypad Problem183
514Recursion183
515The Stock Span Problem183
516Length of Last Word Leetcode Solution183
517Pair with given product183
518Next Greater Frequency Element183
519Peak Index in a Mountain Array183
520Convert array into Zig-Zag fashion183
521Substring With Concatenation Of All Words183
522Shuffle String Leetcode Solution182
523Check if a given array contains duplicate elements within k distance from each other182
524Iterative Inorder Traversal of a Binary Tree182
525Longest Common Prefix using Sorting182
526Find distinct elements common to all rows of a matrix182
527Implement a stack using single queue182
528Count number of triplets with product equal to given number182
529Intersection of Two Arrays182
530Find any one of the multiple repeating elements in read only array182
531Relative Sort Array Leetcode Solution181
532Last Stone Weight181
533Find missing elements of a range181
534Postfix to Prefix Conversion181
535Delete Node in a Linked List Leetcode Solution181
536Find Index of Closing Bracket for a Given Opening Bracket in an Expression181
537Largest Sum Contiguous Subarray180
538Smallest Subarray With all Occurrences of a Most Frequent Element180
539Contiguous Array Leetcode180
540Excel Sheet Column Title Leetcode Solution180
541Koko Eating Bananas Leetcode Solution180
542Implement Stack using Queues180
543N-th Tribonacci Number Leetcode Solution179
544Convert a normal BST to Balanced BST179
545Container with Most Water178
546Isomorphic Strings Leetcode Solution178
547Change the Array into Permutation of Numbers From 1 to N178
548Is Subsequence Leetcode Solution178
549Implementation of Deque using circular array178
550Minimum Bracket Reversals178
551Best Time to Buy and Sell Stock178
552K-th Distinct Element in an Array178
553Rearrange a binary string as alternate x and y occurrences178
554Distribute Candies to People Leetcode Solution178
555Linked List Cycle II LeetCode Solution178
556Gold Mine Problem177
557Find Words That Can Be Formed by Characters Leetcode Solution177
558Jewels and Stones Leetcode Solution177
559Group Multiple Occurrence of Array Elements Ordered by first Occurrence177
560Valid Sudoku177
561Largest Perimeter Triangle Leetcode Solution177
562Valid Anagrams177
563Check for Balanced Parentheses in an Expression177
564Build Array From Permutation Leetcode Solution177
565Minimum Operations to convert X to Y177
566Integer to Roman177
567First negative integer in every window of size k177
568Convert Sorted Array to Binary Search Tree Leetcode Solution177
569Assign Cookies Leetcode Solution177
570Arrange given numbers to form the biggest number176
571Remove Linked List Elements Leetcode Solution176
572Shuffle an Array176
573Sum of Left Leaves Leetcode Solutions176
574Minimum Knight Moves LeetCode Solution176
57501 Matrix LeetCode Solution176
576Unique Binary Search Trees176
577Island Perimeter Leetcode Solution176
578Combinations Leetcode Solution176
579Hamming Distance176
580Count all subsequences having product less than K175
581Minimum Delete Operations to make all Elements of Array Same175
582Rotate List Leetcode Solution175
583Summary Ranges Leetcode Solution175
584The Knapsack Problem174
585Count the number of nodes at given level in a tree using BFS174
586LRU Cache LeetCode Solution174
587Maximum sum rectangle in a 2D matrix174
588Decode Ways174
589Shortest Path in a Grid with Obstacles Elimination LeetCode Solution173
590Maximum path sum in a triangle173
591Trapping Rain Water LeetCode Solution173
592Distance Between Bus Stops Leetcode Solution173
593Maximum Number of Chocolates to be Distributed Equally Among k Students173
594Find the smallest positive integer value that cannot be represented as sum of any subset of a given array173
5953Sum Closest LeetCode Solution173
596Insert Interval Leetcode Solution173
597Maximum Distance in Array172
598Minimum number of distinct elements after removing m items172
599How to check if two given sets are disjoint?171
600Sort Characters By Frequency LeetCode Solution171
601Minimum number of subsets with distinct elements171
602Stone Game LeetCode171
603Rotate Image LeetCode Solution171
604Find minimum difference between any two elements171
605Same Tree LeetCode Solution171
606Minimum insertions to form a palindrome with permutations allowed171
607Painting Fence Algorithm170
608Sieve of Eratosthenes170
609K Empty Slots LeetCode170
610Word Pattern170
611Sort Array By Parity LeetCode Solution170
612Bubble sort using two Stacks170
613Word Wrap Problem170
614Permutation in String Leetcode Solution170
615Find if an Expression has Duplicate Parenthesis or Not170
616XOR Operation in an Array Leetcode Solution170
617Remove All Occurrences of a Substring LeetCode Solution170
618Frog Jump Leetcode Solution170
619Best Time to Buy and Sell Stock LeetCode Solution169
620Tracking current Maximum Element in a Stack169
621Reverse a stack without using extra space in O(n)169
622Isomorphic Strings169
623Printing brackets in Matrix Chain Multiplication Problem169
624Applications of Breadth First Search and Depth First Search169
625House Robber169
626Minimum Depth of Binary Tree Leetcode Solution169
627Defanging an IP Address Leetcode Solution169
628Replace Elements with Greatest Element on Right Side Leetcode Solution169
629Smallest Good Base169
630Distance of nearest cell having 1 in a binary matrix169
631Non-overlapping sum of two sets168
632Find the Duplicate Number LeetCode Solution168
633Find Sum of all unique sub-array sum for a given array168
634Longest Increasing Subsequence168
635Longest Substring with At Most K Distinct Characters LeetCode Solution168
636License Key Formatting Leetcode Solution168
637Minimum Cost to Hire K Workers168
638Maximum Consecutive Numbers Present in an Array168
639Segregate 0s and 1s in an Array168
640Find Maximum Level sum in Binary Tree167
641Count Good Nodes in Binary Tree Leetcode Solution167
642Valid Palindrome II Leetcode Solution167
643Wiggle Sort167
644Coin Change Problem167
645Maximum difference between first and last indexes of an element in array167
646Optimal Account Balancing LeetCode Solution167
647Binary Tree Zigzag Level Order Traversal LeetCode Solution167
648Iterative Method to find Height of Binary Tree167
649Moving Average from Data Stream Leetcode Solution167
650Maximum Number of Occurrences of a Substring Leetcode Solution166
651Merge Two Balanced Binary Search Trees166
652Kth Missing Positive Number Leetcode Solution166
653Best Time to Buy and Sell Stock with Cooldown Leetcode Solution166
654Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions166
655How to Create Mergable Stack?166
656GCD Of Two Numbers166
657Check If It Is a Straight Line Leetcode Solution166
658Queries for counts of array elements with values in given range166
659Employee Free Time LeetCode Solution166
660Sum of All Odd Length Subarrays Leetcode Solution166
661Valid Palindrome165
662Strobogrammatic Number LeetCode Solution165
663Path With Maximum Minimum Value LeetCode Solution165
664Convert an array to reduced form165
665Letter Combinations of a Phone Number165
666Find Largest d in Array such that a + b + c = d165
667Longest Substring with At Least K Repeating Characters LeetCode Solution165
668Find the Distance Value Between Two Arrays Leetcode Solution165
669Flipping an Image LeetCode Solution165
670Delete consecutive same words in a sequence164
671Find pairs with given sum such that elements of pair are in different rows164
672Reorganize String164
673Number of Provinces Leetcode Solution164
674Maximum Number of Coins You Can Get Leetcode Solution164
675Partition Labels LeetCode Solution164
676Number of Dice Rolls With Target Sum LeetCode Solution163
677Populating Next Right Pointers in Each Node163
678Edit Distance LeetCode Solution163
679Longest Increasing Path in a Matrix LeetCode Solution163
680Recover Binary Search Tree163
681Print the Fibonacci numbers in reverse order163
682Permutation Sequence LeetCode Solution163
683Valid Perfect Square Leetcode Solution163
684Inorder Successor of a node in Binary Tree163
685Power of Four Leetcode Solution163
686K Empty Slots163
687Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest163
688Reducing Dishes LeetCode Solution163
689Check If Two String Arrays are Equivalent Leetcode Solution163
690Increasing Decreasing String Leetcode Solution162
691Factorial Trailing Zeroes Leetcode Solution162
692Lucky Numbers in a Matrix Leetcode Solution162
693Check if a queue can be sorted into another queue using a stack162
694Dynamic Programming Basics162
695Partition Array Into Three Parts With Equal Sum Leetcode Solution162
696Remove Invalid Parentheses Leetcode Solution162
697Sort Array by Increasing Frequency Leetcode Solution162
698Form minimum number from given sequence162
699Construct BST from given Preorder Traversal162
700BFS vs DFS for Binary Tree162
701String to Integer (atoi) LeetCode Solution162
702Merge Two Binary Trees LeetCode Solution162
703To Lower Case Leetcode Solution161
704Binary Tree zigzag level order Traversal161
705Convert a Number to Hexadecimal Leetcode Solution161
706Maximum Product of Two Elements in an Array Leetcode Solution161
707Unique Paths II Leetcode Solution161
708Ugly Number Leetcode Solution161
709Reservoir Sampling161
710Reversing a Queue using Recursion161
711Find whether an array is subset of another array161
712Subset Sum Leetcode161
713Robot Room Cleaner Leetcode Solution161
714Reverse Only Letters LeetCode Solution160
715Find the Smallest Divisor given a Threshold Leetcode Solution160
716Find Leaves of Binary Tree LeetCode Solution160
717Delete Nth node from the end of the given linked list160
718Keyboard Row Leetcode Solution160
719Binomial Coefficient160
720Majority Element II Leetcode Solution160
721Restore IP Addresses Leetcode Solution160
722Perform String Shifts Leetcode159
723Check if Two Expressions With Brackets are Same159
724Add and Search Word – Data structure design LeetCode159
725Find the largest multiple of 3159
726Decompress Run-Length Encoded List Leetcode Solution159
727Bulb Switcher LeetCode Solution159
728Numbers with prime frequencies greater than or equal to k159
729Finding K closest element158
730Maximum Product of Three Numbers LeetCode Solution158
731Maximum 69 Number Leetcode Solution158
732Find Pair with Greatest Product in Array158
733Minimum Cost For Tickets Leetcode Solution158
734Number of Islands II LeetCode Solution158
735Morris Traversal158
736Sum of f(a[i], a[j]) over all pairs in an array of n integers158
737Find the node with minimum value in a Binary Search Tree158
738Hamming Distance Leetcode Solution158
739Tiling Problem157
740Maximum Depth of N-ary Tree Leetcode Solution157
741Find Maximum Depth of Nested Parenthesis in a String157
742Minimum Distance Between BST Nodes Leetcode Solution157
743String Compression LeetCode Solution157
744Student Attendance Record I Leetcode Solution157
745First Unique Character in a String LeetCode Solution157
746Sorted Linked List to Balanced BST157
747Generate all possible sorted arrays from alternate elements of two given sorted arrays157
748Diagonal Traversal of Binary Tree157
749Invert Binary Tree LeetCode Solution157
750Word Pattern LeetCode Solution157
751Merge K Sorted Linked Lists157
752Find unique character in a string156
753Binary Tree Maximum Path Sum LeetCode Solution156
754Special Array With X Elements Greater Than or Equal X Leetcode Solution156
755Longest Span with same Sum in two Binary arrays156
756Minimum Height Trees156
757Rank Transform of an Array Leetcode Solution156
758Find All Duplicates in an Array LeetCode Solution156
759Non-decreasing Array LeetCode Solution156
760Check If Array Pairs Are Divisible by k LeetCode Solution156
761Queue based approach for first non-repeating character in a stream156
762Best Meeting Point LeetCode Solution156
763Kth ancestor of a node in binary tree156
764Largest subarray with equal number of 0s and 1s156
765Minimum time required to rot all oranges156
766Symmetric Tree Leetcode Solution156
767Final Prices With a Special Discount in a Shop Leetcode Solution155
768Evaluate Reverse Polish Notation LeetCode Solution155
769Race Car LeetCode Solution155
770Largest Rectangle in Histogram LeetCode Solution155
771Maximum Length of a Concatenated String with Unique Characters Leetcode Solution155
772Search a 2D Matrix II Leetcode Solution155
773Find Median from Data Stream LeetCode Solution155
774Jump Game155
775Find if Path Exists in Graph Leetcode Solution155
776Elements to be added so that all elements of a range are present in array155
777Remove brackets from an algebraic string containing + and – operators155
778Minimize Maximum Pair Sum in Array LeetCode Solution155
779Largest rectangular sub-matrix whose sum is 0155
780Stack Permutations (Check if an array is stack permutation of other)155
781Snakes and Ladders LeetCode Solution154
782Count items common to both the lists but with different prices154
783k-th missing element in increasing sequence which is not present in a given sequence154
784Remove Nth Node From End of List Leetcode Solution154
785Linked List Cycle154
786Split a String in Balanced Strings Leetcode Solution154
787Maximum Difference Between Increasing Elements LeetCode Solution154
788Partition to K Equal Sum Subsets Leetcode Solution154
789Valid Number154
790Program for Bridge and Torch problem154
791Transpose Graph154
792Sort an array according to the order defined by another array153
793Search in a Binary Search Tree Leetcode Solution153
794Deletion in a Binary Tree153
795N-Queens LeetCode Solution153
796Last Stone Weight II LeetCode Solution153
797Print a Binary Tree in Vertical Order153
798Count quadruples from four sorted arrays whose sum is equal to a given value x153
799Minimum Jumps to Reach Home LeetCode Solution153
800Growable array based stack153
801Get Maximum in Generated Array Leetcode Solution153
802Nearest Exit from Entrance in Maze LeetCode Solution153
803Number of NGEs to the Right153
804Maximum Profit in Job Scheduling Leetcode Solution152
805Minimum number of jumps to reach end152
806Crawler Log Folder Leetcode Solution152
807A Space Optimized DP solution for 0-1 Knapsack Problem152
808Merge Sorted Array LeetCode Solution152
809Iterative Preorder Traversal152
810Remove Duplicates from Sorted List LeetCode Solution152
811Interval Tree152
812Minimum swaps to make sequences increasing152
813Reorder Data in Log Files LeetCode Solution152
814String comparison containing wildcards152
815Minimum Time Visiting All Points Leetcode Solution152
816Check for Palindrome after every character replacement Query152
817Circular Queue152
818Priority Queue using doubly linked list152
819Total Numbers With no Repeated Digits in a Range152
820Subarray Product Less Than K LeetCode Solution152
821Remove Duplicates from Sorted List II152
822Relative Ranks Leetcode Solution152
823Number Complement Leetcode Solution152
824Course Schedule II – LeetCode152
825Nested List Weight Sum II LeetCode Solution152
826Form Minimum Number From Given Sequence151
827Longest Subarray Having Count of 1s One More than Count of 0s151
828One Edit Distance LeetCode Solution151
829Spiral Matrix II Leetcode Solution151
830Base 7 Leetcode Solution151
831Sort Array By Parity II Leetcode Solution151
832Find all triplets with zero sum151
833Maximum size subarray sum equals k151
834Given an Array of Pairs Find all Symmetric Pairs in it150
835Regular Expression Matching150
836Valid Parentheses Leetcode Solution150
837Convert BST to Min Heap150
838Maximum Nesting Depth of the Parentheses Leetcode Solution150
839Brick Wall LeetCode Solution150
840Alien Dictionary LeetCode Solution150
841Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution150
842Path with maximum average value150
843Insert into a Binary Search Tree Leetcode Solution149
844Find All Possible Recipes from Given Supplies LeetCode Solution149
845Check whether a given Binary Tree is Complete or not149
846Sort Colors149
847Friends Pairing Problem149
848Can Place Flowers LeetCode Solution149
849Subsequence of Size K With the Largest Even Sum LeetCode Solution149
850Check if a given array can represent Preorder Traversal of Binary Search Tree149
851Binary Search Tree Search and Insertion149
852Find the subarray with least average149
853Clone Graph LeetCode Solution149
854Level order Traversal in Spiral Form149
855Subset with sum divisible by m149
856Partition List Leetcode Solution149
857Top K Frequent Words LeetCode Solution149
858Minimum Number of Taps to Open to Water a Garden LeetCode Solution149
859Tree Traversal (Preorder, Inorder & Postorder)148
860Find Maximum Sum Possible Equal Sum of Three Stacks148
861Design a Stack With Increment Operation Leetcode Solution148
862Guess Number Higher or Lower LeetCode Solution148
863Find the Only Repetitive Element Between 1 to N-1148
864Permutation Coefficient148
865Matrix Chain Multiplication148
866Count Distinct Elements in Every Window of Size K148
867Count Negative Numbers in a Sorted Matrix LeetCode Solution148
868Sequences of given length where every element is more than or equal to twice of previous148
869Missing Element in Sorted Array LeetCode Solution148
870Minimum Sum Path in a Triangle147
871Water Bottles Leetcode Solution147
872Repeated Substring Pattern LeetCode Solution147
873Balanced Expression with Replacement147
874Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution147
875Identify and Mark Unmatched Parenthesis in an Expression147
876Diagonal Traverse LeetCode Solution147
877Number of Days Between Two Dates LeetCode Solution147
878Design Browser History LeetCode Solution147
879Distinct adjacent elements in an array147
880Sum of nearest smaller and greater number147
881An Interesting Method to generate Binary Numbers from 1 to n147
882Range LCM Queries147
883Diagonal Traversal LeetCode Solution147
884Maximum Score After Splitting a String Leetcode Solution146
885Union and Intersection of two Linked Lists146
886Daily Temperatures Leetcode Solution146
887GCDs of given index ranges in an array146
888Check if an Array is Stack Sortable146
889Three way partitioning of an array around a given range146
890Brightest Position on Street LeetCode Solution146
891BFS for Disconnected Graph146
892Convert Sorted List to Binary Search Tree146
893Check if stack elements are pairwise consecutive146
894Time Based Key-Value Store LeetCode Solution146
895K’th Largest Element in BST when modification to BST is not allowed146
896Sorted Array to Balanced BST146
897Insert Delete GetRandom146
898Shortest Word Distance Leetcode Solution146
899LCS (Longest Common Subsequence) of three strings146
900Rearrange an Array Such that arr[i] is equal to i146
901Guess Number Higher or Lower II146
902Minimum sum of multiplications of n numbers146
903Spiral Matrix III LeetCode Solution145
904Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i145
905Find distance between two nodes of a Binary Tree145
906Check if the given array can represent Level Order Traversal of Binary Search Tree145
907Delete And Earn145
908Destination City Leetcode Solution145
909Lemonade Change Leetcode Solution145
910Least Number of Unique Integers after K Removals Leetcode Solution145
911Range sum queries without updates145
912Count ways to reach the nth stair using step 1, 2 or 3145
913Robot Bounded In Circle LeetCode Solution145
914Minimum Swaps to Make Strings Equal Leetcode Solution145
915Palindrome Partitioning Leetcode Solution144
916Find Common Characters Leetcode Solution144
917Rearrange Spaces Between Words Leetcode Solution144
918Vertical sum in a given binary tree144
919Print Fibonacci sequence using 2 variables144
920Number of Distinct Islands Leetcode Solution144
9214Sum144
922Merge Two Sorted Lists Leetcode144
923Construct BST from its given Level Order Traversal144
924Construct the Rectangle Leetcode Solution143
925Maximum Frequency Stack Leetcode Solution143
926Alien Dictionary143
927Stone Game II Leetcode143
928Maximum Subarray Sum Excluding Certain Elements143
929Special Positions in a Binary Matrix Leetcode Solution143
930Construct Complete Binary Tree from its Linked List Representation143
931A program to check if a binary tree is BST or not143
932Split Array Into Consecutive Subsequences143
9333 Sum143
934Averages of Levels in Binary Tree143
935Minimum Height Trees LeetCode Solution143
936Longest Palindromic Subsequence142
937Check if any two intervals overlap among a given set of intervals142
938Binary Tree Longest Consecutive Sequence LeetCode Solution142
939Difference Array | Range update query in O(1)142
940Iterative Postorder Traversal Using Two Stacks142
941Strongly Connected Component142
942Infix to Postfix142
943Queries for GCD of all numbers of an array except elements in a given range142
944Trim a Binary Search Tree142
945Set Matrix Zeroes Leetcode Solution142
946Remove Duplicates from Sorted List II LeetCode Solution142
947Lexicographical Numbers Leetcode Solution142
948Queue using Stacks142
949Count Subarrays with Same Even and Odd Elements142
950Largest area rectangular sub-matrix with equal number of 1’s and 0’s142
951Unique Paths II141
952Sliding Window Maximum141
953All Unique Triplets that Sum up to a Given Value141
954Binary array after M range toggle operations141
955Analyze User Website Visit Pattern LeetCode Solution141
956Collect maximum points in a grid using two traversals141
957Find all permuted rows of a given row in a matrix141
958Number of Equivalent Domino Pairs Leetcode Solution141
959Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space141
960Count Submatrices With All Ones LeetCode Solution141
961Sign of the Product of an Array LeetCode Solution140
962Reverse Nodes in K-Group140
963Dividing Array into Pairs With Sum Divisible by K140
964Minesweeper LeetCode Solution140
965Create Maximum Number140
966Count subarrays where second highest lie before highest140
967Word Break140
968Pattern Occurrences using Stack140
969Merging Intervals140
970Can Make Arithmetic Progression From Sequence Leetcode Solution140
971Find postorder traversal of BST from preorder traversal140
972Three Consecutive Odds Leetcode Solution140
973Intersection of Two Linked Lists LeetCode Solution140
974Palindrome Partitioning139
975Level Order Traversal of Binary Tree139
976Count Primes in Ranges139
977Length of Longest Fibonacci Subsequence139
978The Painter’s Partition Problem139
979Median of Two Sorted Arrays139
980Product of Array Except Self LeetCode Solution139
981Find the Difference Leetcode Solution139
982Kth Smallest Element in a BST Leetcode Solution139
983Maximum Product Subarray139
984Binary Search Tree Delete Operation139
985Symmetric Tree139
986Longest Nice Substring LeetCode Solution139
987Count pair with Given Sum139
988Height of a generic tree from parent array139
989Newman-Conway Sequence139
990My Calendar I LeetCode Solution138
991Climbing stairs138
992Find Maximum of Minimum for Every Window Size in a Given Array138
993Segment Tree138
994Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution138
995Asteroid Collision LeetCode Solution138
996K Closest Points to Origin Leetcode Solution138
997Maximize Sum of Array after K Negations Leetcode Solution138
998Merge Sort137
999Double the first element and move zero to end137
1000Largest Number Leetcode Solution137
1001Maximum Product of Indexes of Next Greater on Left and Right137
1002Boundary Traversal of binary tree137
1003Number Of Longest Increasing Subsequence137
1004Find Duplicate Subtrees137
1005Shortest Completing Word Leetcode Solution137
1006Compute nCr % p137
1007Find the First Circular Tour that visits all the Petrol Pumps137
1008Maximum subsequence sum such that no three are consecutive137
1009Largest divisible pairs subset137
1010Friends Of Appropriate Ages LeetCode Solution137
1011Maximum Length of Repeated Subarray137
1012The Maze III LeetCode Solution137
1013Valid Boomerang Leetcode Solution137
1014Depth First Search (DFS) for a Graph137
1015Number of palindromic paths in a matrix136
1016Construct Binary Tree from given Parent Array representation136
1017Maximum weight transformation of a given string136
1018Graph Valid Tree LeetCode Solution136
1019Make The String Great Leetcode Solution136
1020First missing positive136
1021Binary Search Tree136
1022Boolean Parenthesization Problem136
1023String Matching in an Array Leetcode Solution136
1024Kill Process LeetCode Solution136
1025Partition Equal Subset Sum136
1026Insertion in a Binary Tree136
1027Maximum Number of Ways to Partition an Array LeetCode Solution136
1028Level order traversal using two Queues136
1029Breadth First Search (BFS) for a Graph136
1030Construction of Longest Increasing Subsequence (N log N)136
1031Serialize and Deserialize Binary Tree136
1032Morris Inorder Traversal136
1033Largest Substring Between Two Equal Characters Leetcode Solution136
1034Minimum Index Sum of Two Lists136
1035Design Hit Counter LeetCode Solution135
1036Advantages of BST over Hash Table135
1037Count minimum steps to get the given desired array135
1038Decrypt String from Alphabet to Integer Mapping Leetcode Solution135
1039Longest subsequence such that difference between adjacents is one135
1040Scramble String LeetCode Solution135
1041Find number of pairs in an array such that their XOR is 0135
1042Next Greater Element III LeetCode Solution135
1043K maximum sums of overlapping contiguous sub-arrays135
1044Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’135
1045Build an Array With Stack Operations Leetcode Solution135
1046Rearrange array such that even positioned are greater than odd134
1047Balanced Binary Tree134
1048Ugly Numbers134
1049Custom Sort String Leetcode Solution134
1050Maximum Sum of 3 Non-Overlapping Subarrays134
1051Validate Binary Search Tree134
1052Available Captures for Rook Leetcode Solution134
1053Maximum difference between frequency of two elements such that element having greater frequency is also greater133
1054Bitwise AND of Numbers Range LeetCode Solution133
1055Employee Importance LeetCode Solution133
1056Defanging an IP Address LeetCode Solution133
1057Invalid Transactions LeetCode Solution133
1058Add two numbers133
1059Ugly Number II LeetCode Solution133
1060Implement Trie (Prefix Tree) Leetcode Solution133
1061Iterative Depth First Traversal of Graph133
1062Super Ugly Number132
1063Path Sum II LeetCode Solution132
1064Generate Parentheses Leetcode Solution132
1065Search in Sorted Rotated Array132
1066Regular Expression Matching Regular Expression Matching LeetCode Solution132
1067Recover Binary Search Tree Leetcode Solution132
1068Populating Next Right Pointers in Each Node Leetcode Solution132
1069Move all negative elements to end in order with extra space allowed132
1070Count pairs from two sorted arrays whose sum is equal to a given value x132
1071Lowest Common Ancestor132
1072Maximum length subsequence with difference between adjacent elements as either 0 or 1132
1073Find Peak Element132
1074Remove Duplicates from Sorted Array II Leetcode Solution131
1075Subarrays with K Different Integers Leetcode Solution131
1076Kth Smallest Element in a Sorted Matrix LeetCode Solution131
1077Find a Peak Element II LeetCode Solution131
1078Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution131
1079Binary Tree Right Side View LeetCode Solution131
1080Number of Students Doing Homework at a Given Time Leetcode Solution131
1081Largest BST Subtree LeetCode Solution131
1082Root to Leaf path with target sum Leetcode Solutions131
1083Longest Bitonic Subsequence131
1084Number of siblings of a given Node in n-ary Tree130
1085Minimum Size Subarray Sum130
1086Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1087Combination Sum IV LeetCode Solution130
1088Day of the Year Leetcode Solution130
1089Smallest Common Region Leetcode Solution130
1090Maximize Distance to Closest Person LeetCode Solution130
1091Rearrange array such that even index elements are smaller and odd index elements are greater130
1092Number of Closed Islands Leetcode Solution130
1093Clone a Binary Tree with Random Pointers130
1094Find whether a subarray is in form of a mountain or not130
1095Find Smallest Range Containing Elements from k Lists129
1096Serialize and Deserialize Binary Tree LeetCode Solution129
1097Count Largest Group Leetcode Solution129
1098Minimum Absolute Difference in BST Leetcode Solution129
1099Binary Tree Data Structure129
1100Consecutive Characters LeetCode Solution129
1101Increasing Triplet Subsequence LeetCode Solution129
1102Remove Palindromic Subsequences Leetcode Solution129
1103Find maximum difference between nearest left and right smaller elements129
1104Level of Each node in a Tree from source node129
1105Find the minimum distance between two numbers129
1106Distinct Subsequences129
1107Next Permutation Leetcode Solution129
1108Convert BST into a Min-Heap without using array129
1109Types of Binary Tree129
1110Remove duplicates from sorted array128
1111Constant time range add operation on an array128
1112Valid Tic-Tac-Toe State LeetCode Solution128
1113Print all triplets in sorted array that form AP128
1114Divisible Pairs Counting128
1115Find Three Element From Different Three Arrays Such That a + b + c = sum128
1116Cutting a Rod128
1117Path Sum128
1118Third Maximum Number Leetcode Solution128
1119Iterative method to find ancestors of a given binary tree128
1120Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution128
1121Prime Palindrome LeetCode Solution127
1122Palindrome Permutation LeetCode Solution127
1123Sum of Even Numbers After Queries127
1124Maximum Product Subarray127
1125Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1126Reformat The String Leetcode Solution127
1127Products of ranges in an array127
1128Write Code to Determine if Two Trees are Identical126
1129Cells with Odd Values in a Matrix LeetCode Solution126
1130Delete Nodes and Return Forest Leetcode Solution126
1131Bottom View of a Binary Tree126
1132Mean of Array After Removing Some Elements Leetcode Solution126
1133Print Right View of a Binary Tree126
1134Print Next Greater Number of Q queries126
1135Thousand Separator Leetcode Solution126
1136Search Insert Position126
1137Minimum Score Triangulation of Polygon Leetcode Solution126
1138Topological Sorting125
1139Moser-de Bruijn Sequence125
1140Longest Increasing Consecutive Subsequence125
1141Merge two BSTs with limited extra space125
1142Search an Element in Sorted Rotated Array125
1143Construct K Palindrome Strings LeetCode Solution124
1144Minimum sum of squares of character counts in a given string after removing k characters124
1145Maximum Binary Tree124
1146Closest Binary Search Tree Value Leetcode Solution124
1147Subset Sum Problem in O(sum) space124
1148Priority Queue124
1149Palindromic Substrings Leetcode Solution124
1150Red-Black Tree Introduction124
1151Swap Nodes In Pairs124
1152Print modified array after executing the commands of addition and subtraction123
1153Possible Bipartition LeetCode Solution123
1154Find maximum length Snake sequence123
1155Golomb sequence123
1156Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution123
1157Check Array Formation Through Concatenation Leetcode Solution123
1158Bus Routes Leetcode Solution123
1159Diameter of N-Ary Tree LeetCode Solution123
1160Web Crawler LeetCode Solution122
1161Transform a BST to Greater sum Tree122
1162Kth Smallest Number in Multiplication Table Leetcode Solution122
1163Search Suggestions System LeetCode Solution122
1164Find Largest Value in Each Tree Row LeetCode Solution122
1165Queries for Number of Distinct Elements in a Subarray122
1166Maximum Product of Splitted Binary Tree LeetCode Solution122
1167Rotate Array122
1168Maximize sum of consecutive differences in a circular array122
1169Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution122
1170Find a sorted subsequence of size 3 in linear time122
1171Minimum Sideway Jumps LeetCode Solution122
1172Count even length binary sequences with same sum of first and second half bits121
1173Minimum Cost to Move Chips to The Same Position LeetCode Solution121
1174Compare Strings by Frequency of the Smallest Character Leetcode Solution121
1175Decision Tree121
1176Binary Tree to Binary Search Tree Conversion121
1177Longest Repeated Subsequence121
1178Find the smallest binary digit multiple of given number121
1179First Bad Version120
1180Graph and its representation120
1181Factorial Trailing Zeroes LeetCode Solution120
1182Matchsticks to Square Leetcode Solution120
1183Swapping Nodes in a Linked List Leetcode Solution120
1184Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1185Lowest Common Ancestor in Binary Search Tree120
1186Sum of Left Leaves LeetCode Solution119
1187Minimum Moves to Equal Array Elements LeetCode Solution119
1188Contiguous Array LeetCode Solution119
1189Queue Reconstruction by Height119
1190Valid Triangle Number119
1191Maximum sum bitonic subarray119
1192K’th Largest element in BST using constant extra space119
1193Reverse a Path in BST using Queue119
1194Number of Orders in the Backlog Leetcode Solution119
1195Decrease Elements To Make Array Zigzag LeetCode Solution119
1196How to print maximum number of A’s using given four keys118
1197Moving Stones Until Consecutive Leetcode Solution118
1198Maximum sum of pairs with specific difference118
1199Maximum number of segments of lengths a, b and c118
1200Lowest Common Ancestor of a Binary Tree Leetcode Solution118
1201Range Queries for Longest Correct Bracket Subsequence118
1202Given a binary tree, how do you remove all the half nodes?118
1203Reformat Date LeetCode Solution118
1204Count Pairs Whose Products Exist in Array118
1205Closest Leaf in a Binary Tree LeetCode Solution118
1206Kth Smallest Element in a BST117
1207Champagne Tower LeetCode Solution117
1208Guess The Word117
1209Array Queries for multiply replacements and product117
1210Replace two consecutive equal values with one greater116
1211Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution116
1212Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution116
1213Path Crossing Leetcode Solution116
1214Arithmetic Slices II – Subsequence LeetCode Solution115
1215Flatten 2D Vector LeetCode Solution115
1216Integer Break LeetCode Solution115
1217Minimum Swaps To Make Sequences Increasing LeetCode Solution115
1218Concatenation of Array LeetCode Solution115
1219Range Sum Query using Sparse Table115
1220Perfect Squares LeetCode Solution115
1221Write a function to get the intersection point of two Linked Lists114
1222Mean of range in array114
1223Maximum Depth Of Binary Tree114
1224Check if each internal node of a BST has exactly one child114
1225Power of Two114
1226Check Completeness of a Binary Tree LeetCode Solution114
1227Design Skiplist LeetCode Solution114
1228Maximum sum of a path in a Right Number Triangle114
1229LRU Cache Leetcode Solution114
1230The kth Factor of n Leetcode Solution114
1231Divide Two Integers Leetcode Solution114
1232BST to a Tree with Sum of all Smaller Keys114
1233Largest Plus Sign Leetcode Solution113
1234Queries on Probability of Even or Odd Number in given Ranges113
1235Bold Words in String LeetCode Solution113
1236Check if all levels of two Binary Tree are anagrams or not113
1237Longest Common Prefix Using Word by Word Matching113
1238New 21 Game113
1239Check for Identical BSTs without building the trees113
1240Print modified array after multiple array range increment operations113
1241Find Minimum in Rotated Sorted Array II LeetCode Solution113
1242Maximize Elements Using Another Array113
1243Valid Perfect Square LeetCode Solution113
1244Contiguous Array113
1245Sliding Window Median Leetcode Solution113
1246Maximum Value at a Given Index in a Bounded Array LeetCode Solution112
1247Print n terms of Newman-Conway Sequence112
1248Parallel Courses II LeetCode Solution112
1249Print Ancestors of a Given Binary Tree Node Without Recursion112
1250Symmetric Tree LeetCode Solution Leetcode Solution111
1251Maximum Product Subarray111
1252Find minimum number of merge operations to make an array palindrome111
1253Count Subsets Having Distinct Even Numbers111
1254Find k-th smallest element in BST (Order Statistics in BST)111
1255Graph Cloning111
1256Merge k Sorted Lists Leetcode Solution111
1257Maximum Array from Two given Arrays Keeping Order Same111
1258Check if two nodes are on the same path in a Tree110
1259Smallest Range II Leetcode Solution110
1260Minimum Remove to Make Valid Parentheses LeetCode Solution110
1261Missing Number110
1262Count and Toggle Queries on a Binary Array110
1263Number of elements less than or equal to a given number in a given subarray109
1264Verify Preorder Serialization of a Binary Tree109
1265Next greater element109
1266Image Overlap LeetCode Solution108
1267Minimum Time to Collect All Apples in a Tree LeetCode Solution108
1268Excel Sheet Column Title LeetCode Solution108
1269Check If a String Can Break Another String Leetcode Solution108
1270Different Ways to Add Parentheses Leetcode Solution107
1271Orderly Queue LeetCode Solution107
1272Koko Eating Bananas LeetCode Solution107
1273Min Cost Climbing Stairs LeetCode Solution107
1274Palindrome Partitioning107
1275Largest Submatrix With Rearrangements LeetCode Solution105
1276Newman–Shanks–Williams prime105
1277Check if X can give change to every person in the Queue105
1278Peeking Iterator LeetCode Solution105
1279Check in binary array the number represented by a subarray is odd or even104
1280Longest Substring Without Repeating Characters Leetcode Solution104
1281Merge Sorted Array103
1282Range Minimum Query (Square Root Decomposition and Sparse Table)102
1283Array Nesting Leetcode Solution102
1284Maximum Sum Increasing Subsequence101
1285Arranging Coins Leetcode Solution101
1286Maximum product of an increasing subsequence100
1287Find maximum average subarray of k length100
1288Encoded String With Shortest Length LeetCode Solution100
1289Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1290Queries for Decimal Values of Subarrays of a Binary Array99
1291Number of indexes with equal elements in given range99
1292Convert to Base -2 LeetCode Solution98
1293Minimum Number of People to Teach LeetCode Solution98
1294Random Pick Index LeetCode Solution97
1295Reach a Number LeetCode Solution97
1296Convert a BST to a Binary Tree such that sum of all greater keys is added to every key97
1297Continuous Subarray Sum LeetCode Solution96
1298Find the Winner of the Circular Game LeetCode Solution96
1299Vertical Order Traversal of Binary Tree LeetCode Solution96
1300Add Two Numbers II Leetcode Solution96
1301Check given array of size n can represent BST of n levels or not96
1302Binary Tree to Binary Search Tree Conversion using STL set96
1303Queries on XOR of greatest odd divisor of the range95
1304Jump Game IV LeetCode Solution95
1305Palindrome Number LeetCode Solution95
1306Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1307Insert Delete GetRandom O(1) Leetcode Solution94
1308Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution94
1309Design Underground System Leetcode Solution90
1310Print Maximum Length Chain of Pairs89
1311Detect Capital Leetcode Solution87
1312Design A Leaderboard Leetcode Solution86
1313Top K Frequent Elements LeetCode Solution83
1314Substring with Concatenation of All Words Leetcode Solution83
1315Minimum Swaps to Group All 1’s Together Leetcode Solution83
1316Binary Tree Inorder Traversal LeetCode Solution81
1317Minimum Path Sum Leetcode Solution80
1318Count Sub Islands LeetCode Solution80
1319Shifting Letters LeetCode Solution79
1320Longest Common Subsequence LeetCode Solution77
1321Odd Even Linked List Leetcode Solution77
1322Best Meeting Point LeetCode Solution76
1323Find the Town Judge LeetCode Solution76
1324Decode String Leetcode Solution76
1325Maximum Population Year LeetCode Solution75
1326Find the Town Judge LeetCode Solution75
1327Sum Root to Leaf Numbers LeetCode Solution72
1328Shortest Unsorted Continuous Subarray LeetCode Solution72
1329Rectangle Overlap LeetCode Solution71
1330Maximum Population Year LeetCode Solution71
1331Design Add and Search Words Data Structure LeetCode Solution70
1332Score of Parenthesis LeetCode Solution67
1333Stone Game IV LeetCode Solution67
1334Flatten Binary Tree to Linked List LeetCode Solution67
1335Insert into a Sorted Circular Linked List LeetCode Solution66
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution63
1338Is Graph Bipartite? LeetCode Solution62
1339Valid Triangle Number LeetCode Solution62
1340Divide Chocolate LeetCode Solution53
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution48
1342Range Sum of BST LeetCode Solution45
1343Reverse Integer Leetcode Solution45
1344Sort Colors LeetCode Solution42
1345Find K Closest Elements LeetCode Solution40
1346Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution38
1347Rotate String LeetCode Solution37
1348Excel Sheet Column Number LeetCode Solution37
1349Maximum Size Subarray Sum Equals k Leetcode Solution20
1350H-Index Leetcode Solution19
1351High Five LeetCode Solution18
1352Unique Binary Search Trees LeetCode Solution10
1353Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution9
1354Monotonic Array Leetcode Solution8
1355Valid Triangle Number LeetCode Solution7
1356Swim in Rising Water LeetCode Solution4
Translate »