Shortest Unsorted Continuous Subarray LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon Apple Facebook Flipkart Google JPMorgan Microsoft Oracle Salesforce Uber
LiveRamp OlaViews 68

Problem Statement

Shortest Unsorted Continuous Subarray LeetCode Solution says that – Given an integer array nums, you have to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order.

Return the length of the shortest subarray.

Example 1:


 nums = [2,6,4,8,10,9,15]




 You need to sort [6, 4, 8, 10, 9] in ascending order to make the whole array sorted in ascending order.

Example 2:


 nums = [1,2,3,4]





  • In order to find Shortest Unsorted Continuous Subarray. First, we will find the unsorted order from the left side of the array and also from the right side of the array. After finding the index from both sides at last we will return right-left+1.


  • At first, we will make two variables maxi and mini in which mini-stores the mini value of the unsorted array from the left side, and maxi stores the maximum value of unsorted array from the right side.
  • after we will iterate from left to right in an array and find the minimum value from the unsorted order and again iterate from right to left in order to find the maximum value from the unsorted order.
  • Then will check if minimum == MIN_Value and maximum == MAX_Value simply return 0(because the array is already in sorted order).
  • Then again iterate from left to right and if we find a value greater than mini then simply break the loop and the same in case of the right to left if we find the value smaller than maxi then simply break the loop and at last will return the (end-start+1).
  • Hence Shortest Unsorted Continuous Subarray will be calculated.


Shortest Unsorted Continuous Subarray LeetCode SolutionPin

Shortest Unsorted Continuous Subarray LeetCode SolutionPin

class Solution {
    public int findUnsortedSubarray(int[] nums) {
        int maxi = Integer.MIN_VALUE;
        int mini = Integer.MAX_VALUE;
        for(int i=1;i<nums.length;i++){
            if(nums[i] < nums[i-1]){
                if(mini > nums[i])
                    mini = nums[i];
        for(int i = nums.length-2;i >= 0;i--){
            if(nums[i] > nums[i+1]){
                if(maxi < nums[i])
                    maxi = nums[i];
        if(mini == Integer.MAX_VALUE && maxi == Integer.MIN_VALUE)
            return 0;
        int start = 0;
        int end = nums.length;
        for(start = 0;start < nums.length;start++){
            if(mini < nums[start])
        for(end = nums.length-1;end >= 0;end--){
            if(maxi > nums[end])
        return (end-start+1);
class Solution:
    def findUnsortedSubarray(self, nums: List[int]) -> int:
        maxi = -9999999
        mini = 9999999
        for i in range(1,len(nums)):
            if nums[i] < nums[i-1]:
                mini = min(nums[i],mini)
        for i in range(len(nums)-2,-1,-1):
            if nums[i] > nums[i+1]:
                maxi = max(nums[i],maxi)
        if mini == 9999999 and maxi == -9999999:
            return 0
        for start in range(len(nums)):
            if nums[start] > mini:
        for end in range(len(nums)-1,-1,-1):
            if nums[end] < maxi:
        return end-start+1        

Complexity Analysis of Shortest Unsorted Continuous Subarray Leetcode Solution:

Time Complexity:

The Time Complexity of the above Solution is O(N) since accessing each index at most one time.

Space Complexity:

The Space Complexity of the above Solution is O(1) since we are using constant extra space in the above solution.

Similar Problem Link:


Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2815
2Java program to find the number of Nodes in a Binary Tree2497
3Reverse a string without affecting special characters2453
4Delete a node of a linked list at given position1972
5Palindrome using Recursion1774
6Insert nodes in a linked list in a sorted way (Ascending Order)1656
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1626
9Write a program to print all permutations of a given string1599
10Find Minimum Distance Between Two Numbers in an Array1469
11Create a Doubly Linked List1443
12Quick Sort1415
13Reverse an Array1408
14Smallest window in a string containing all characters of another string1393
15Find a Triplet That Sum to a Given Value1354
16Recursively remove all adjacent duplicates1351
17First Repeating Element1334
18Arrange Even and Odd number such that Odd comes after Even1316
19Sum of numbers in String1309
20Smallest Positive Number Missing in an Unsorted Array1277
21Check if the Elements of an Array are Consecutive1250
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1212
25Subarray with Given Sum1209
26Print all Possible Combinations of R Elements in a given Array of size N1198
27Recursive function to do substring search1194
28Find the Maximum Repeating Number in Array1149
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1100
32Maximum Subarray Sum using Divide and Conquer1097
33Remove characters from first string which are in second1064
34Find Leaders in an Array1057
35Swap nodes in the linked list1030
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II987
38Find the second most frequent character983
39Given a string find its first non-repeating character962
40Find Triplet in Array With a Given Sum957
41Total number of occurrences of a given item in the linked list950
42Given a sorted array and a number x, find the pair in array whose sum is closest to x949
43A Program to check if strings are rotations of each other or not941
44Print all possible words from phone digits927
45Find the Missing Number922
46Rearrange Positive and Negative Numbers Alternatively in Array916
47Longest Palindromic Substring900
48Segregate even and odd nodes in a linked list880
49Print Longest common subsequence877
50Union and Intersection of Two Linked Lists869
51Transform one string to another using minimum number of given operations860
52Check rearranged string can form a palindrome841
53Rearrange given Array in Maximum Minimum Form841
54Count Possible Triangles817
55Iterative Implementation of Quick Sort811
56Multiplication of Two Matrices796
57Check if the linked list is palindrome792
58Rotate a Linked List788
59Count of Triplets With Sum Less than Given Value787
60Stock Buy Sell to Maximize Profit784
61Concatenation of two strings756
62Tug of War755
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string748
65Find Nearest Greater and Smaller Element742
66Find Pythagorean Triplets from Array734
67The Celebrity Problem734
68Reverse String Without Temporary Variable729
69Remove ‘b’ and ‘ac’ from a given string726
70Find all Common Elements in Given Three Sorted Arrays724
71Remove all duplicates in an unsorted linked list707
72Find the Row with Maximum Number of 1’s701
73Find the Peak Element from an Array694
74Find the subarray whose sum is equal to a given number X692
75Insertion Sort685
76Remove Minimum Characters so that Two Strings Become Anagrams683
77Find Smallest Missing Number in a Sorted Array682
78Addition of Two Matrices680
79A Product Array Puzzle680
80Implement Two Stacks in an Array674
81Generate all Binary Strings Without Consecutive 1’s670
82Maximum Sum of Non Consecutive Elements666
83Maximum Product Subarray II658
84Lexicographic rank of string649
85Check if Two given Matrices are Identical641
86Multiplication of Previous and Next641
87Merge K Sorted Arrays and Print Sorted Output631
88Subtraction of Two Matrices630
89Move All the Zeros to the End of the Given Array625
90Online Algorithm for Checking Palindrome in a Stream620
91Divide a string in N equal parts620
92Form Minimum Number from Given Sequence of D’s and I’s620
93Check whether two strings are anagram of each other611
94Maximum Circular Subarray Sum607
95Remove recurring digits in a given number607
96Sort a linked list that is sorted alternating ascending and descending606
97Sort a stack using a temporary stack603
98Find the Minimum Element in a Sorted and Rotated Array602
99Move last element of the Linked List at first place600
100First Circular Tour to Visit all the Petrol Bunks596
101Subarray and Subsequence593
102Largest Subarray with Equal Number of 0’s and 1’s592
103Compare two strings(linked lists)589
104Flattening a linked list589
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array580
108Majority Element572
109Run length encoding571
110Minimum insertions to form a shortest palindrome571
111Print all permutations with repetition570
112Palindromes in a given range569
113Pangram Checking565
114Merge a linked list into another at alternate positions563
115Rearrange a given linked list in-place561
116Remove all duplicates in a sorted linked list561
117Minimum Characters to be Added at Front to Make String Palindrome561
118Minimum number of Merge Operations to make an Array Palindrome557
119Rotate string to get lexicographically minimum string556
120Repeated Subsequence of Length Two or More553
121Most repeating character in a string550
122Print all anagrams together in a sequence of words548
123Reorder an Array According to the Given Indexes546
124Pancake Sorting Problem540
125Clone a Linked List with next and random pointer535
126Merge Overlapping Intervals II534
127Two Sum Leetcode Solution532
128Size of The Subarray With Maximum Sum524
129Transpose of a Matrix522
130Remove Extra Spaces from a String518
131Removing Spaces from a String using stringstream517
132Check if a given string is a rotation of a palindrome515
133Smallest Palindrome after Replacement514
134Partition Problem513
135Remove duplicates from a string512
136Longest Palindrome can be Formed by Removing or Rearranging Characters511
137Maximum Sum Increasing Subsequence510
138Check whether Strings are K Distance Apart or Not500
139Generate all Binary Strings from Given Pattern499
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized497
141Insert Node in the Sorted Linked List497
1423Sum Leetcode Solution494
143Delete Last Occurrence494
144Length of Longest valid Substring494
145Check if Two given Strings are Isomorphic to each other489
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String481
148Given string is interleaving of two other strings or not478
149Count Minimum Steps to Get the given Array477
150Merge sort better than quick sort for linked lists474
151Number of Smaller Elements on Right Side471
152Find Pair with Given Difference470
153Check length of a String is Equal to the Number Appended at its Last468
154Check if all Rows of a Matrix are Circular Rotations of Each Other468
155Longest Common Prefix using Divide and Conquer466
156Find nth node of the Linked list from the end466
157Sort 0s 1s and 2s in an Array457
158Find a Fixed Point in a Given Array455
159Print all interleavings of given two strings454
160Compare Two Version Numbers452
161Merge two sorted linked lists such that merged list is in reverse order452
162Find the Subarray of given length with Least Average452
163Split linked list using alternate nodes449
164Reorder Array Using Given Indexes449
165Reverse words in a given string448
166Print Reverse of a string (Recursion)445
167Median of Two Sorted Arrays LeetCode Solution444
168Print string of odd length in ‘X’ format434
169Find Element Using Binary Search in Sorted Array430
170Find K Length Subarray of Maximum Average430
171Swap Kth Node from beginning with Kth Node from End430
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way424
174print all palindromic partitions420
175Flatten a multilevel linked list414
176Maximum Length of Chain Pairs414
177Shortest Superstring Problem413
178Check if String Follows Order of Characters by a Pattern or not410
179Sorting a K Sorted Array408
180Sort a String According to Another String401
181Longest Span with same Sum in two Binary Arrays II396
182Reverse a Linked List in groups394
183Find a Sorted Subsequence of size 3391
184Program to add two binary digits389
185Find the two Numbers with Odd Occurrences in an Unsorted Array386
186Recursively print all the sentences that can be formed from list of word lists385
187Longest Common Prefix Using Binary Search II382
188Reverse a Singly Linked List (Iterative/Non-Recursive)380
189Rearrange a linked list in Zig-Zag376
190Kth Non-repeating Character376
191Caesar Cipher375
192Check if String can Become Empty by Recursively Deleting given Substring374
193Pancake Sorting372
194Rotate Image by 90 degrees369
195Longest Common Prefix Word by Word Matching367
196Permutations of a Given String Using STL363
197Perfect Reversible String363
198Increasing Subsequence of Length three with Maximum Product361
199Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes360
200Merging Two Sorted Arrays360
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
2031`s and 2`s complement of binary number355
204Find First non-repeating character in a string355
205Four Elements that Sum to Given352
206Delete N nodes after M350
207List items containing all characters of a given word350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array343
210Split a string338
211Palindrome string (number)338
212Minimum Characters to be Removed to Make a Binary String Alternate337
213Check if a Linked list of Strings form a Palindrome332
214Recursive Implementation of atoi()330
215Sorting the array of strings329
216Print All Distinct Elements of the Array329
217Convert a String that is Repetition of a Substring of Length K327
218Find the first Repeating Number in a Given Array325
219Even Substring Count324
220Reverse a singly linked list recursively323
221Valid Parentheses LeetCode Solution322
222Binary Tree to Doubly linked list321
223Maximum occurring character in a string320
224Print Shortest Path to Print a String on Screen320
225Can we reverse a linked list in less than O(n) time ?319
226Nth Character in Concatenated Decimal String316
227Sort Elements by Frequency II316
228Reverse a String using Stack315
229Convert string1 to string2 in one edit315
230Lower Case To Upper Case313
231wildcard character matching313
232Merge Two Sorted Arrays310
233Find the Lost Element From a Duplicated Array309
234Maximum Subarray Leetcode Solution309
235Count the number of words308
236Split Four Distinct Strings307
237Find middle of the Linked List304
238Longest Common Subsequence with Permutations298
239Count the Pairs at Same Distance as in English Alphabets298
240Next Greater Element in an Array293
241Matrix Chain Multiplication using Dynamic Programming291
242Palindrome Permutation286
243Find Nth Node283
244Searching a node in a Binary Search Tree283
245Find All Pairs With a Given Difference281
246Triplet from three linked lists with given sum280
247Roman to Integer Leetcode Solution279
248Delete a Tree279
249Reverse a String275
250Print all Possible Ways to Break a String in Bracket Form275
251String(represents an integer) to value275
252Binary Tree271
253Reverse Bits270
254Delete a node under given conditions270
255Change Gender of a given String270
256Word Search Leetcode Solution268
257Sort an array of strings268
258Number of sub-strings which recursively add up to 9265
259How to Efficiently Implement k Stacks in a Single Array?265
260Longest Common Extension264
261Remove middle points in a linked list of line segments264
262Count Pairs With Given Sum261
263Meeting Rooms II LeetCode Solution261
264Remove spaces from a string261
265Toeplitz Matrix261
266First non Repeating Element259
267Longest Palindromic Substring LeetCode Solution258
268Shuffle a given Array258
269Repeated Substring Pattern257
270Move all negative elements to one side of array256
271N queen problem253
272Min Stack252
273Find, second, frequent, character249
274Number of Islands LeetCode Solution248
275Dijkstra Algorithm248
276Cuckoo sequence program247
277Clone a linked list with next and random pointer (Hashing)245
278Most Frequent Element in an Array244
279Minimize the maximum difference between the heights244
280Max stack243
281Sort linked which is sorted on absolute values243
282Expression Evaluation242
283House Robber Leetcode Solution242
284Search Insert Position Leetcode Solution241
285Fibonacci numbers239
286KMP Algorithm237
287Valid Palindrome Leetcode Solution237
288How to Delete a Linked List237
289Sudoku Solver236
290Plus One Leetcode Solution235
291Min Stack Leetcode Solution235
292Word Search235
293Subset Leetcode233
294Evaluation of Postfix Expression233
295Number Of 1 bits232
296Combination Sum Leetcode Solution232
297Reverse words in a string232
298Backspace String Compare227
299Merge Sorted Arrays Leetcode Solution226
300Rabin Karp Algorithm225
301Pair of Positive Negative Values in an Array224
302Set Matrix Zeroes223
303Contains Duplicate II Leetcode Solution223
304Sqrt(x) Leetcode Solution222
305Reversing a Queue222
306Tower Of Hanoi222
307Subarray with 0 sum220
308Combination Sum220
309Common elements in all rows of a given matrix219
310Product of array except self219
311Integer to Roman Leetcode Solution217
312Intersection of Two Arrays II Leetcode Solution216
313Count subarrays with equal number of 1’s and 0’s215
314Pascal Triangle Leetcode215
315String Compression214
316Delete middle element of a stack214
317Reverse individual words214
318Construct Binary Tree from Given Inorder and Preorder Traversals213
319Minimum swaps required to bring all elements less than or equal to k together212
320Sliding Window Technique212
321Find Top K (or Most Frequent) Numbers in a Stream212
322Add Binary Leetcode Solution211
323Bellman Ford Algorithm211
324Pow(x, n) Leetcode Solution211
325Arithmetic Expression Evaluation210
326Second Most Repeated Word in a Sequence209
327Page Replacement Algorithms in Operating Systems209
328Next Permutation209
329Segregate even and odd numbers208
330Kruskal Algorithm208
331Palindrome Linked List Leetcode Solution208
332Single Number Leetcode Solution208
333Count of index pairs with equal elements in an array208
334Find sum of non-repeating elements (distinct) elements in an array208
335Postfix to Infix Conversion207
336Minimum Value to Get Positive Step by Step Sum Leetcode Solution207
337Contains Duplicate207
338Design a stack that supports getMin() in O(1) time and O(1) extra space207
339Implementation of Deque using Doubly Linked List207
340Sort elements by frequency206
341Maximum Number of Balloons Leetcode Solution206
342Count Odd Numbers in an Interval Range Leetcode Solution206
343K-th Smallest Element in a Sorted Matrix205
344Maximum Subarray205
345Group Words With Same Set of Characters204
346Longest Common Prefix Leetcode Solution204
347Permutations Leetcode Solution203
348Third Maximum Number Leetcode Solution203
349Convex Hull Algorithm203
350Top K Frequent Words202
351Longest Substring Without Repeating Characters LeetCode Solution202
352Find Lucky Integer in an Array Leetcode Solution202
353Find Numbers with Even Number of Digits Leetcode Solution202
354Majority Element Leetcode Solution202
355Sorting array using Stacks201
356Spiral Matrix LeetCode Solution201
357Minimum operation to make all elements equal in array201
358Sum of minimum and maximum elements of all subarrays of size k201
359Find the Town Judge Leetcode Solution200
360Scramble String200
361Count subarrays having total distinct elements same as original array200
362Swap Nodes in Pairs Leetcode Solutions200
363Smallest Subarray with k Distinct Numbers199
364Evaluate Division198
365Special Number197
366Reverse a Number Using Stack197
367First element occurring k times in an array197
368Check if two arrays are equal or not196
369Merge Two Sorted Lists Leetcode Solutions196
370Prefix to Infix Conversion196
371Given two unsorted arrays find all pairs whose sum is x196
372Number of Good Pairs Leetcode Solution195
373Group Anagrams195
374Best Time to Buy and Sell Stock  II Leetcode Solution195
375Pascal’s Triangle II Leetcode Solution195
376Minimum Path Sum195
377Search in Rotated Sorted Array Leetcode Solution195
378Reversing the First K elements of a Queue194
379Find duplicates in a given array when elements are not limited to a range194
380Count Primes Leetcode Solutions194
381Maximum Distance Between two Occurrences of Same Element in Array194
382Huffman Coding194
383Minimum Steps to reach target by a Knight193
384Power of Two Leetcode Solution193
385Fizz Buzz Leetcode193
386Minimum Absolute Difference Leetcode Solution193
387Missing Number Leetcode Solution192
388House Robber II Leetcode Solution192
389Sort Array by Increasing Frequency Leetcode Solution192
390Maximum possible difference of two subsets of an array191
391Range Sum Query 2D – Immutable Leetcode Solution191
392Maximal Square191
393Single Number191
394Find All Numbers Disappeared in an Array Leetcode Solution190
395Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution190
396Top K Frequent Elements190
397Unique Paths Leetcode Solution189
398Running Sum of 1d Array Leetcode Solution189
399How Many Numbers Are Smaller Than the Current Number Leetcode Solution189
400Sorting using trivial hash function189
401Matrix Diagonal Sum Leetcode Solution189
402Max Consecutive Ones Leetcode Solution189
403Subarray Sum Equals K LeetCode Solution188
404Zigzag Conversion188
405Palindrome Substring Queries188
406Leetcode Permutations188
407How to Implement Stack Using Priority Queue or Heap?187
408Expression Contains Redundant Bracket or Not187
409Check if Array Contains Contiguous Integers With Duplicates Allowed187
410Coin Change 2 Leetcode Solution187
411Subset sum problem187
412Sort Integers by The Number of 1 Bit Leetcode Solution187
413Happy Number Leetcode Solution187
414Unique Paths187
415Find Winner on a Tic Tac Toe Game Leetcode Solution187
416Difference between highest and least frequencies in an array187
417Fibonacci Number LeetCode Solution187
418Find The Duplicate Number187
419Letter Case Permutation186
420Decode String186
421Find the Closest Palindrome number186
422Reverse Vowels of a String Leetcode Solution186
423Subarray Sum Equals k186
424Smallest Element Repeated Exactly K Times186
425Reverse Integer186
426Remove Duplicates from Sorted Array Leetcode Solution185
427Print All Distinct Elements of a Given Integer Array185
428Nth Catalan Number185
429Convert String To Int185
430Check If N and Its Double Exist Leetcode Solution185
431Cumulative Frequency of Count of Each Element in an Unsorted Array185
432Length of the largest subarray with contiguous elements185
433Subtract the Product and Sum of Digits of an Integer Leetcode Solution185
434Find Number of Employees Under every Employee185
435Monotonic Array LeetCode Solution185
436Find top three repeated in array185
437Trapping Rain Water Leetcode Solution184
438Best Time to Buy and Sell Stock III Leetcode Solution184
439Sort a stack using recursion184
440Reverse Words in a String III LeetCode Solution184
441Shuffle the Array Leetcode Solution184
442Bipartite Graph184
443Find the first repeating element in an array of integers183
444Capacity To Ship Packages Within D Days Leetcode Solution183
445Find Median from data Stream183
446Maximum Depth of Binary Tree Leetcode Solution182
447Prim’s Algorithm182
448Find all pairs (a, b) in an array such that a % b = k182
449Find the Duplicate Element182
450LRU Cache Implementation182
451Generate a String With Characters That Have Odd Counts Leetcode Solution182
452Priority Queue Using Singly Linked List182
453Find Minimum In Rotated Sorted Array182
454Implement Stack and Queue using Deque182
455Count Substrings with equal number of 0s, 1s and 2s181
456Kth largest element in an Array Leetcode Solutions181
457Sum of Subarray Ranges Leetcode Solution181
458Merge Two Sorted Linked Lists181
459Reverse a Stack Using Recursion181
460Integer to English words181
461Minimum Moves to Equal Array Elements Leetcode Solution181
462Subarrays with distinct elements181
463Fizz Buzz180
464Sorting a Queue without Extra Space180
465Longest Common Subsequence180
466The K Weakest Rows in a Matrix Leetcode Solution180
467Count pairs from two linked lists whose sum is equal to a given value180
468Delete a Node from linked list without head pointer180
469Remove Minimum Number of Elements Such That no Common Element Exist in both Array179
470Find Common Characters Leetcode Solution179
471Edit Distance179
472Find the Difference Leetcode Solution179
473Find elements which are present in first array and not in second179
474Target Sum178
475Degree of an array178
476Next Greater Element I Leetcode Solution178
477Reverse a String178
478Concatenation of Array LeetCode Solution178
479Find First and Last Position of Element in Sorted Array Leetcode Solution178
480Count and Say178
481MiniMax Algorithm178
482Reverse a linked list178
483Text Justification LeetCode Solution177
484Number of Steps to Reduce a Number to Zero Leetcode Solution177
485Print all subarrays with 0 sum177
486Floyd Warshall Algorithm177
487Kth Largest Element in a Stream Leetcode Solution177
488Excel Sheet Column Number Leetcode Solution177
489Top View of Binary Tree176
490Kids With the Greatest Number of Candies Leetcode Solution176
491Multiply Strings Leetcode Solution176
492Word Ladder LeetCode Solution176
493Longest Common Prefix using Trie176
494Merge Overlapping Intervals176
495Priority Queue in C++176
496Balanced Binary Tree Leetcode Solution176
497Design Parking System Leetcode Solution175
498Longest subarray not having more than K distinct elements175
499Iterative Tower of Hanoi175
500Pair with given product175
501Shortest Palindrome175
502Koko Eating Bananas Leetcode Solution175
503Flood Fill LeetCode175
504Max Area of Island174
505Check if a given array contains duplicate elements within k distance from each other174
506Postfix to Prefix Conversion174
507Prefix to Postfix Conversion174
508Move Zeroes LeetCode Solution174
509Count and Say Leetcode Solution174
510Intersection of Two Arrays173
511Shuffle String Leetcode Solution173
512Implement a stack using single queue173
513Implement Stack using Queues173
514Valid Parenthesis String173
515Length of Last Word Leetcode Solution173
516Find four elements that sum to a given value (Hashmap)173
517Mobile Numeric Keypad Problem173
518Peak Index in a Mountain Array173
519The Stock Span Problem173
520Zigzag Conversion LeetCode Solution173
521Find N Unique Integers Sum up to Zero Leetcode Solution173
522Find subarray with given sum (Handles Negative Numbers)173
524Substring With Concatenation Of All Words172
525Count number of triplets with product equal to given number172
526Convert array into Zig-Zag fashion172
527Find Index of Closing Bracket for a Given Opening Bracket in an Expression172
528Iterative Inorder Traversal of a Binary Tree172
529Find distinct elements common to all rows of a matrix172
530Contiguous Array Leetcode172
531Container with Most Water172
532Slowest Key Leetcode Solution172
533Find missing elements of a range172
534Last Stone Weight171
535Best Time to Buy and Sell Stock171
536Longest Common Prefix using Sorting171
537Excel Sheet Column Title Leetcode Solution171
538Find any one of the multiple repeating elements in read only array170
539Largest Perimeter Triangle Leetcode Solution170
540K-th Distinct Element in an Array170
541Maximum sum rectangle in a 2D matrix170
542Convert a normal BST to Balanced BST170
543Smallest Subarray With all Occurrences of a Most Frequent Element170
544Minimum Bracket Reversals170
545Relative Sort Array Leetcode Solution170
546Jump Game Leetcode Solution170
547Delete Node in a Linked List Leetcode Solution170
548Shuffle an Array169
549Next Greater Frequency Element169
550Valid Sudoku169
551Build Array From Permutation Leetcode Solution168
552Assign Cookies Leetcode Solution168
553First negative integer in every window of size k168
554Sum of Left Leaves Leetcode Solutions168
555Arrange given numbers to form the biggest number168
556Distribute Candies to People Leetcode Solution168
557Check for Balanced Parentheses in an Expression168
558Change the Array into Permutation of Numbers From 1 to N168
559Find Words That Can Be Formed by Characters Leetcode Solution167
560Is Subsequence Leetcode Solution167
561The Knapsack Problem167
562Implementation of Deque using circular array167
563Isomorphic Strings Leetcode Solution167
564Group Multiple Occurrence of Array Elements Ordered by first Occurrence167
565Shortest Path in a Grid with Obstacles Elimination LeetCode Solution167
566Rearrange a binary string as alternate x and y occurrences167
567Minimum Operations to convert X to Y167
568Integer to Roman167
569N-th Tribonacci Number Leetcode Solution166
570Linked List Cycle II LeetCode Solution166
571Valid Anagrams166
572Decode Ways166
573Maximum path sum in a triangle166
574Convert Sorted Array to Binary Search Tree Leetcode Solution166
57501 Matrix LeetCode Solution166
576Jewels and Stones Leetcode Solution166
577Hamming Distance165
578Sieve of Eratosthenes165
579Island Perimeter Leetcode Solution165
580Unique Binary Search Trees165
581Rotate List Leetcode Solution165
582How to check if two given sets are disjoint?165
583Gold Mine Problem165
5843Sum Closest LeetCode Solution165
585Minimum Delete Operations to make all Elements of Array Same165
586Count the number of nodes at given level in a tree using BFS165
587Find the smallest positive integer value that cannot be represented as sum of any subset of a given array164
588Maximum Distance in Array164
589Combinations Leetcode Solution164
590Trapping Rain Water LeetCode Solution164
591Minimum Knight Moves LeetCode Solution164
592Remove Linked List Elements Leetcode Solution164
593Count all subsequences having product less than K164
594LRU Cache LeetCode Solution164
595Maximum difference between first and last indexes of an element in array164
596Same Tree LeetCode Solution164
597Rotate Image LeetCode Solution163
598K Empty Slots LeetCode163
599Summary Ranges Leetcode Solution163
600Distance Between Bus Stops Leetcode Solution163
601Find minimum difference between any two elements163
602Minimum number of subsets with distinct elements163
603Insert Interval Leetcode Solution163
604Applications of Breadth First Search and Depth First Search162
605Find Sum of all unique sub-array sum for a given array162
606Maximum Number of Chocolates to be Distributed Equally Among k Students162
607Minimum insertions to form a palindrome with permutations allowed162
608Best Time to Buy and Sell Stock LeetCode Solution161
609Minimum number of distinct elements after removing m items161
610Frog Jump Leetcode Solution161
611Word Wrap Problem161
612Word Pattern161
613Minimum Cost to Hire K Workers161
614Find if an Expression has Duplicate Parenthesis or Not161
615Printing brackets in Matrix Chain Multiplication Problem161
616Replace Elements with Greatest Element on Right Side Leetcode Solution161
617Minimum Depth of Binary Tree Leetcode Solution160
618Sort Array By Parity LeetCode Solution160
619Permutation in String Leetcode Solution160
620Find the Duplicate Number LeetCode Solution160
621Distance of nearest cell having 1 in a binary matrix160
622License Key Formatting Leetcode Solution160
623Stone Game LeetCode160
624Remove All Occurrences of a Substring LeetCode Solution160
625Find Maximum Level sum in Binary Tree160
626House Robber160
627Sort Characters By Frequency LeetCode Solution159
628Segregate 0s and 1s in an Array159
629XOR Operation in an Array Leetcode Solution159
630Kth Missing Positive Number Leetcode Solution159
631Painting Fence Algorithm159
632Maximum Consecutive Numbers Present in an Array159
633Defanging an IP Address Leetcode Solution159
634Smallest Good Base159
635Longest Increasing Subsequence159
636Coin Change Problem158
637Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest158
638Queries for counts of array elements with values in given range158
639Non-overlapping sum of two sets158
640Check If It Is a Straight Line Leetcode Solution158
641Reverse a stack without using extra space in O(n)158
642Longest Substring with At Most K Distinct Characters LeetCode Solution157
643Find Largest d in Array such that a + b + c = d157
644Valid Palindrome II Leetcode Solution157
645Optimal Account Balancing LeetCode Solution157
646Isomorphic Strings157
647Power of Four Leetcode Solution157
648Reorganize String157
649Count Good Nodes in Binary Tree Leetcode Solution157
650Best Time to Buy and Sell Stock with Cooldown Leetcode Solution157
651Iterative Method to find Height of Binary Tree157
652Tracking current Maximum Element in a Stack157
653Merge Two Balanced Binary Search Trees156
654Employee Free Time LeetCode Solution156
655Number of Provinces Leetcode Solution156
656Strobogrammatic Number LeetCode Solution156
657How to Create Mergable Stack?156
658Binary Tree Zigzag Level Order Traversal LeetCode Solution156
659Wiggle Sort156
660Sum of All Odd Length Subarrays Leetcode Solution156
661Partition Labels LeetCode Solution156
662GCD Of Two Numbers156
663Check If Two String Arrays are Equivalent Leetcode Solution156
664Flipping an Image LeetCode Solution155
665BFS vs DFS for Binary Tree155
666Sum of f(a[i], a[j]) over all pairs in an array of n integers155
667Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
668Check if a queue can be sorted into another queue using a stack155
669K Empty Slots155
670Inorder Successor of a node in Binary Tree155
671Moving Average from Data Stream Leetcode Solution155
672Convert an array to reduced form155
673Letter Combinations of a Phone Number155
674Longest Substring with At Least K Repeating Characters LeetCode Solution155
675Reservoir Sampling154
676Largest Sum Contiguous Subarray154
677Populating Next Right Pointers in Each Node154
678Delete consecutive same words in a sequence154
679Form minimum number from given sequence154
680Increasing Decreasing String Leetcode Solution154
681Find the Distance Value Between Two Arrays Leetcode Solution154
682Maximum Number of Coins You Can Get Leetcode Solution154
683Ugly Number Leetcode Solution154
684Subset Sum Leetcode154
685Path With Maximum Minimum Value LeetCode Solution154
686Permutation Sequence LeetCode Solution154
687Lucky Numbers in a Matrix Leetcode Solution154
688Maximum Number of Occurrences of a Substring Leetcode Solution154
689Maximum Product of Three Numbers LeetCode Solution153
690Majority Element II Leetcode Solution153
691Print the Fibonacci numbers in reverse order153
692Sort Array by Increasing Frequency Leetcode Solution153
693To Lower Case Leetcode Solution153
694Find Leaves of Binary Tree LeetCode Solution153
695Find the node with minimum value in a Binary Search Tree153
696Find the Smallest Divisor given a Threshold Leetcode Solution153
697Hamming Distance Leetcode Solution153
698Longest Increasing Path in a Matrix LeetCode Solution153
699String to Integer (atoi) LeetCode Solution153
700Valid Palindrome153
701Reducing Dishes LeetCode Solution153
702Remove Invalid Parentheses Leetcode Solution152
703Reversing a Queue using Recursion152
704Add and Search Word – Data structure design LeetCode152
705Numbers with prime frequencies greater than or equal to k152
706Find pairs with given sum such that elements of pair are in different rows152
707Factorial Trailing Zeroes Leetcode Solution152
708Unique Paths II Leetcode Solution152
709Reverse Only Letters LeetCode Solution152
710Number of Dice Rolls With Target Sum LeetCode Solution152
711Partition Array Into Three Parts With Equal Sum Leetcode Solution152
712Delete Nth node from the end of the given linked list152
713Construct BST from given Preorder Traversal152
714Convert a Number to Hexadecimal Leetcode Solution151
715Longest Span with same Sum in two Binary arrays151
716Recover Binary Search Tree151
717Edit Distance LeetCode Solution151
718Decompress Run-Length Encoded List Leetcode Solution151
719Binary Tree zigzag level order Traversal151
720Valid Perfect Square Leetcode Solution151
721Largest subarray with equal number of 0s and 1s151
722Dynamic Programming Basics151
723Find whether an array is subset of another array151
724Deletion in a Binary Tree150
725Maximum Product of Two Elements in an Array Leetcode Solution150
726Binomial Coefficient150
727Restore IP Addresses Leetcode Solution150
728Minimum Cost For Tickets Leetcode Solution150
729Finding K closest element149
730Keyboard Row Leetcode Solution149
731Rank Transform of an Array Leetcode Solution149
732Maximum 69 Number Leetcode Solution149
733Minimum Height Trees149
734Minimum Distance Between BST Nodes Leetcode Solution149
735Merge K Sorted Linked Lists149
736Find the largest multiple of 3149
737Merge Two Binary Trees LeetCode Solution149
738Bubble sort using two Stacks149
739Stack Permutations (Check if an array is stack permutation of other)149
740Find unique character in a string149
741Find Maximum Depth of Nested Parenthesis in a String149
742Find Pair with Greatest Product in Array149
743Sorted Linked List to Balanced BST148
744Elements to be added so that all elements of a range are present in array148
745Word Pattern LeetCode Solution148
746Best Meeting Point LeetCode Solution148
747Race Car LeetCode Solution148
748Symmetric Tree Leetcode Solution148
749Bulb Switcher LeetCode Solution148
750Remove brackets from an algebraic string containing + and – operators148
751Invert Binary Tree LeetCode Solution148
752Jump Game148
753Perform String Shifts Leetcode148
754Binary Tree Maximum Path Sum LeetCode Solution148
755Growable array based stack148
756Morris Traversal148
757Kth ancestor of a node in binary tree147
758Minimum time required to rot all oranges147
759Robot Room Cleaner Leetcode Solution147
760Diagonal Traversal of Binary Tree147
761k-th missing element in increasing sequence which is not present in a given sequence147
762Student Attendance Record I Leetcode Solution147
763Non-decreasing Array LeetCode Solution147
764Evaluate Reverse Polish Notation LeetCode Solution147
765Number of NGEs to the Right147
766Find All Duplicates in an Array LeetCode Solution147
767Generate all possible sorted arrays from alternate elements of two given sorted arrays147
768Count quadruples from four sorted arrays whose sum is equal to a given value x147
769Maximum Length of a Concatenated String with Unique Characters Leetcode Solution146
770Check for Palindrome after every character replacement Query146
771Largest rectangular sub-matrix whose sum is 0146
772Minimum number of jumps to reach end146
773Search in a Binary Search Tree Leetcode Solution146
774Maximum Depth of N-ary Tree Leetcode Solution146
775Snakes and Ladders LeetCode Solution146
776Remove Nth Node From End of List Leetcode Solution146
777String Compression LeetCode Solution146
778First Unique Character in a String LeetCode Solution146
779Program for Bridge and Torch problem146
780Largest Rectangle in Histogram LeetCode Solution146
781N-Queens LeetCode Solution146
782Nested List Weight Sum II LeetCode Solution146
783Valid Number146
784Tiling Problem146
785Number of Islands II LeetCode Solution145
786Count items common to both the lists but with different prices145
787Interval Tree145
788Base 7 Leetcode Solution145
789Minimize Maximum Pair Sum in Array LeetCode Solution145
790Find if Path Exists in Graph Leetcode Solution145
791Relative Ranks Leetcode Solution145
792Sort an array according to the order defined by another array145
793Partition to K Equal Sum Subsets Leetcode Solution145
794Special Array With X Elements Greater Than or Equal X Leetcode Solution145
795Remove Duplicates from Sorted List LeetCode Solution145
796Linked List Cycle145
797Search a 2D Matrix II Leetcode Solution145
798Queue based approach for first non-repeating character in a stream145
799Find Median from Data Stream LeetCode Solution145
800Maximum Difference Between Increasing Elements LeetCode Solution145
801A Space Optimized DP solution for 0-1 Knapsack Problem144
802Reorder Data in Log Files LeetCode Solution144
803Alien Dictionary LeetCode Solution144
804Split a String in Balanced Strings Leetcode Solution144
805Print a Binary Tree in Vertical Order144
806String comparison containing wildcards144
807Circular Queue144
808Final Prices With a Special Discount in a Shop Leetcode Solution144
809Check if Two Expressions With Brackets are Same144
810Minimum swaps to make sequences increasing144
811Crawler Log Folder Leetcode Solution144
812Transpose Graph144
813Check If Array Pairs Are Divisible by k LeetCode Solution144
814Permutation Coefficient143
815Course Schedule II – LeetCode143
816Iterative Preorder Traversal143
817Merge Sorted Array LeetCode Solution143
818Total Numbers With no Repeated Digits in a Range143
819Longest Subarray Having Count of 1s One More than Count of 0s143
820One Edit Distance LeetCode Solution143
821Nearest Exit from Entrance in Maze LeetCode Solution143
822Clone Graph LeetCode Solution143
823Find all triplets with zero sum143
824Get Maximum in Generated Array Leetcode Solution143
825Number Complement Leetcode Solution143
826Minimum Time Visiting All Points Leetcode Solution143
827Convert BST to Min Heap143
828Remove Duplicates from Sorted List II143
829Priority Queue using doubly linked list143
830Path with maximum average value142
831Subset with sum divisible by m142
832Sort Array By Parity II Leetcode Solution142
833Find the subarray with least average142
834Partition List Leetcode Solution142
835Sort Colors142
836Top K Frequent Words LeetCode Solution142
837Design a Stack With Increment Operation Leetcode Solution142
838Minimum Swaps to Make Strings Equal Leetcode Solution142
839Last Stone Weight II LeetCode Solution142
840Maximum Nesting Depth of the Parentheses Leetcode Solution142
841Find the Only Repetitive Element Between 1 to N-1142
842Spiral Matrix II Leetcode Solution141
843Check if a given array can represent Preorder Traversal of Binary Search Tree141
844Brick Wall LeetCode Solution141
845Regular Expression Matching141
846Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution141
847Sum of nearest smaller and greater number141
848Find All Possible Recipes from Given Supplies LeetCode Solution141
849Sorted Array to Balanced BST141
850Check if an Array is Stack Sortable141
851Friends Pairing Problem141
852Maximum size subarray sum equals k141
853Matrix Chain Multiplication141
854Minimum Jumps to Reach Home LeetCode Solution141
855Binary Search Tree Search and Insertion140
856LCS (Longest Common Subsequence) of three strings140
857Form Minimum Number From Given Sequence140
858Brightest Position on Street LeetCode Solution140
859Count Distinct Elements in Every Window of Size K140
860Level order Traversal in Spiral Form140
861Can Place Flowers LeetCode Solution140
862Valid Parentheses Leetcode Solution140
863Subarray Product Less Than K LeetCode Solution140
864Count ways to reach the nth stair using step 1, 2 or 3140
865Tree Traversal (Preorder, Inorder & Postorder)140
866Minimum Number of Taps to Open to Water a Garden LeetCode Solution140
867Maximum Profit in Job Scheduling Leetcode Solution140
868Given an Array of Pairs Find all Symmetric Pairs in it140
869Check whether a given Binary Tree is Complete or not140
870Subsequence of Size K With the Largest Even Sum LeetCode Solution140
871Insert into a Binary Search Tree Leetcode Solution139
872Guess Number Higher or Lower LeetCode Solution139
873Union and Intersection of two Linked Lists139
874Insert Delete GetRandom139
875Rearrange an Array Such that arr[i] is equal to i139
876Sequences of given length where every element is more than or equal to twice of previous139
877Guess Number Higher or Lower II139
878Minimum Sum Path in a Triangle139
879Range sum queries without updates139
880Maximum Score After Splitting a String Leetcode Solution138
881Find Maximum Sum Possible Equal Sum of Three Stacks138
882Delete And Earn138
883Count Subarrays with Same Even and Odd Elements138
884Alien Dictionary138
885Rearrange Spaces Between Words Leetcode Solution138
886Convert Sorted List to Binary Search Tree138
887Shortest Word Distance Leetcode Solution138
888Destination City Leetcode Solution138
889Identify and Mark Unmatched Parenthesis in an Expression138
890A program to check if a binary tree is BST or not138
891Find distance between two nodes of a Binary Tree138
892Daily Temperatures Leetcode Solution138
893Find all permuted rows of a given row in a matrix138
894Count Negative Numbers in a Sorted Matrix LeetCode Solution138
895Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
896Distinct adjacent elements in an array138
897Check if stack elements are pairwise consecutive138
898Missing Element in Sorted Array LeetCode Solution138
899BFS for Disconnected Graph138
900Minimum sum of multiplications of n numbers138
901An Interesting Method to generate Binary Numbers from 1 to n138
902Repeated Substring Pattern LeetCode Solution137
903Balanced Expression with Replacement137
904Lemonade Change Leetcode Solution137
905Special Positions in a Binary Matrix Leetcode Solution137
906GCDs of given index ranges in an array137
907Water Bottles Leetcode Solution137
908Range LCM Queries137
909Set Matrix Zeroes Leetcode Solution137
910Number of Days Between Two Dates LeetCode Solution137
911Find Common Characters Leetcode Solution137
912Check if the given array can represent Level Order Traversal of Binary Search Tree137
913Construct Complete Binary Tree from its Linked List Representation137
915Vertical sum in a given binary tree136
916Number of Equivalent Domino Pairs Leetcode Solution136
917Least Number of Unique Integers after K Removals Leetcode Solution136
918Robot Bounded In Circle LeetCode Solution136
919Three way partitioning of an array around a given range136
920Diagonal Traversal LeetCode Solution136
921Design Browser History LeetCode Solution136
922Diagonal Traverse LeetCode Solution136
923Spiral Matrix III LeetCode Solution136
924Merge Two Sorted Lists Leetcode136
925Palindrome Partitioning Leetcode Solution135
926Construct the Rectangle Leetcode Solution135
927Queue using Stacks135
928Print Fibonacci sequence using 2 variables135
929Averages of Levels in Binary Tree135
930K’th Largest Element in BST when modification to BST is not allowed135
931Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i135
932Maximum Subarray Sum Excluding Certain Elements135
933Longest Palindromic Subsequence135
934Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
935Dividing Array into Pairs With Sum Divisible by K134
936Lexicographical Numbers Leetcode Solution134
937Binary array after M range toggle operations134
938Time Based Key-Value Store LeetCode Solution134
939Analyze User Website Visit Pattern LeetCode Solution134
940Remove Duplicates from Sorted List II LeetCode Solution134
941Trim a Binary Search Tree134
942Infix to Postfix134
943Stone Game II Leetcode134
944Median of Two Sorted Arrays134
9453 Sum134
946Check if any two intervals overlap among a given set of intervals134
947Queries for GCD of all numbers of an array except elements in a given range134
948Newman-Conway Sequence133
949Iterative Postorder Traversal Using Two Stacks133
950Strongly Connected Component133
951Can Make Arithmetic Progression From Sequence Leetcode Solution133
952Maximum Frequency Stack Leetcode Solution133
953Pattern Occurrences using Stack133
954Largest Substring Between Two Equal Characters Leetcode Solution133
955Three Consecutive Odds Leetcode Solution133
956Construct BST from its given Level Order Traversal133
957Maximize Sum of Array after K Negations Leetcode Solution133
958All Unique Triplets that Sum up to a Given Value133
959Binary Tree Longest Consecutive Sequence LeetCode Solution133
960Word Break133
961Merging Intervals133
962Number of Distinct Islands Leetcode Solution133
963Symmetric Tree133
964Length of Longest Fibonacci Subsequence132
965Palindrome Partitioning132
966Difference Array | Range update query in O(1)132
967Count Submatrices With All Ones LeetCode Solution132
968My Calendar I LeetCode Solution132
969Shuffle 2n integers as without using extra space132
970Depth First Search (DFS) for a Graph132
971Sliding Window Maximum132
972Create Maximum Number132
973Maximum Product Subarray132
974Segment Tree132
975Find Maximum of Minimum for Every Window Size in a Given Array132
976Intersection of Two Linked Lists LeetCode Solution132
977Sign of the Product of an Array LeetCode Solution132
978Split Array Into Consecutive Subsequences132
979Count Primes in Ranges131
980Height of a generic tree from parent array131
981Find the Difference Leetcode Solution131
982Binary Search Tree Delete Operation131
983Maximum subsequence sum such that no three are consecutive131
984Level Order Traversal of Binary Tree131
985Minimum Height Trees LeetCode Solution131
986Find Duplicate Subtrees131
987First missing positive131
988Climbing stairs131
989Breadth First Search (BFS) for a Graph131
990Count pair with Given Sum131
991Boundary Traversal of binary tree130
992Reverse Nodes in K-Group130
993Find postorder traversal of BST from preorder traversal130
994Serialize and Deserialize Binary Tree130
995Find the First Circular Tour that visits all the Petrol Pumps130
996Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
997Insertion in a Binary Tree130
998Largest divisible pairs subset129
999Unique Paths II129
1000Largest Number Leetcode Solution129
1001Level order traversal using two Queues129
1002The Painter’s Partition Problem129
1003Compute nCr % p129
1004Product of Array Except Self LeetCode Solution129
1005Count subarrays where second highest lie before highest129
1006Find number of pairs in an array such that their XOR is 0129
1007Asteroid Collision LeetCode Solution129
1008Number Of Longest Increasing Subsequence129
1009Kth Smallest Element in a BST Leetcode Solution129
1010Minesweeper LeetCode Solution129
1011Valid Boomerang Leetcode Solution129
1012Double the first element and move zero to end129
1013Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1014Rearrange array such that even positioned are greater than odd128
1015Partition Equal Subset Sum128
1016Binary Search Tree128
1017Graph Valid Tree LeetCode Solution128
1018Collect maximum points in a grid using two traversals128
1019The Maze III LeetCode Solution128
1020Shortest Completing Word Leetcode Solution128
1021Number of palindromic paths in a matrix128
1022Make The String Great Leetcode Solution128
1023Longest Nice Substring LeetCode Solution128
1024Scramble String LeetCode Solution128
1025Maximum Length of Repeated Subarray128
1026Friends Of Appropriate Ages LeetCode Solution128
1027Next Greater Element III LeetCode Solution127
1028Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1029Ugly Numbers127
1030Find whether a subarray is in form of a mountain or not127
1031Invalid Transactions LeetCode Solution127
1032Advantages of BST over Hash Table127
1033Maximum Number of Ways to Partition an Array LeetCode Solution127
1034Design Hit Counter LeetCode Solution127
1035Build an Array With Stack Operations Leetcode Solution127
1036Longest subsequence such that difference between adjacents is one127
1037Construction of Longest Increasing Subsequence (N log N)127
1038String Matching in an Array Leetcode Solution127
1039Construct Binary Tree from given Parent Array representation127
1040Boolean Parenthesization Problem127
1041Balanced Binary Tree127
1042K Closest Points to Origin Leetcode Solution126
1043Kill Process LeetCode Solution126
1044Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1045Minimum Size Subarray Sum126
1046Maximum Product of Indexes of Next Greater on Left and Right126
1047Implement Trie (Prefix Tree) Leetcode Solution126
1048Lowest Common Ancestor126
1049Maximum weight transformation of a given string126
1050Morris Inorder Traversal126
1051Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1052Minimum Index Sum of Two Lists126
1053Regular Expression Matching Regular Expression Matching LeetCode Solution125
1054Path Sum II LeetCode Solution125
1055Bitwise AND of Numbers Range LeetCode Solution125
1056Iterative Depth First Traversal of Graph125
1057Custom Sort String Leetcode Solution125
1058Find a Peak Element II LeetCode Solution125
1059Validate Binary Search Tree125
1060Maximum Sum of 3 Non-Overlapping Subarrays125
1061Ugly Number II LeetCode Solution125
1062Add two numbers125
1063Available Captures for Rook Leetcode Solution125
1064Super Ugly Number124
1065Number of Closed Islands Leetcode Solution124
1066Find Peak Element124
1067Divisible Pairs Counting124
1068Defanging an IP Address LeetCode Solution124
1069Largest BST Subtree LeetCode Solution124
1070Move all negative elements to end in order with extra space allowed124
1071Binary Tree Right Side View LeetCode Solution124
1072Recover Binary Search Tree Leetcode Solution124
1073Employee Importance LeetCode Solution124
1074Remove Duplicates from Sorted Array II Leetcode Solution123
1075Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution123
1076Serialize and Deserialize Binary Tree LeetCode Solution123
1077Populating Next Right Pointers in Each Node Leetcode Solution123
1078Types of Binary Tree123
1079Subarrays with K Different Integers Leetcode Solution123
1080Clone a Binary Tree with Random Pointers123
1081Print all triplets in sorted array that form AP123
1082Count pairs from two sorted arrays whose sum is equal to a given value x123
1083Find Smallest Range Containing Elements from k Lists123
1084Binary Tree Data Structure123
1085Count minimum steps to get the given desired array123
1086Rearrange array such that even index elements are smaller and odd index elements are greater123
1087Day of the Year Leetcode Solution123
1088Maximum difference between frequency of two elements such that element having greater frequency is also greater123
1089Print Next Greater Number of Q queries123
1090Find the minimum distance between two numbers122
1091Remove Palindromic Subsequences Leetcode Solution122
1092Generate Parentheses Leetcode Solution122
1093Search in Sorted Rotated Array122
1094Path Sum122
1095Number of Students Doing Homework at a Given Time Leetcode Solution122
1096Number of siblings of a given Node in n-ary Tree122
1097Smallest Common Region Leetcode Solution122
1098Longest Bitonic Subsequence122
1099Constant time range add operation on an array121
1100Remove duplicates from sorted array121
1101Convert BST into a Min-Heap without using array121
1102Print Right View of a Binary Tree121
1103Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1104Level of Each node in a Tree from source node121
1105Combination Sum IV LeetCode Solution121
1106Valid Tic-Tac-Toe State LeetCode Solution121
1107Bottom View of a Binary Tree121
1108Write Code to Determine if Two Trees are Identical121
1109Third Maximum Number Leetcode Solution121
1110Root to Leaf path with target sum Leetcode Solutions121
1111Maximize Distance to Closest Person LeetCode Solution120
1112Search Insert Position120
1113Palindrome Permutation LeetCode Solution120
1114Minimum sum of squares of character counts in a given string after removing k characters120
1115Distinct Subsequences120
1116Products of ranges in an array120
1117Next Permutation Leetcode Solution120
1118Find maximum difference between nearest left and right smaller elements120
1119Topological Sorting119
1120Maximum Product Subarray119
1121Cutting a Rod119
1122Iterative method to find ancestors of a given binary tree119
1123Find Three Element From Different Three Arrays Such That a + b + c = sum119
1124Increasing Triplet Subsequence LeetCode Solution119
1125Prime Palindrome LeetCode Solution119
1126Minimum Score Triangulation of Polygon Leetcode Solution119
1127Print modified array after executing the commands of addition and subtraction119
1128Count Largest Group Leetcode Solution119
1129Longest Increasing Consecutive Subsequence119
1130Maximum Binary Tree119
1131Thousand Separator Leetcode Solution119
1132Search an Element in Sorted Rotated Array118
1133Golomb sequence118
1134Consecutive Characters LeetCode Solution118
1135Construct K Palindrome Strings LeetCode Solution118
1136Mean of Array After Removing Some Elements Leetcode Solution118
1137Cells with Odd Values in a Matrix LeetCode Solution118
1138Moser-de Bruijn Sequence118
1139Reformat The String Leetcode Solution118
1140Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1141Red-Black Tree Introduction117
1142Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1143Transform a BST to Greater sum Tree117
1144Minimum Absolute Difference in BST Leetcode Solution117
1145K maximum sums of overlapping contiguous sub-arrays117
1146Swap Nodes In Pairs117
1147Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1148Sum of Even Numbers After Queries117
1149Find maximum length Snake sequence116
1150Possible Bipartition LeetCode Solution116
1151Longest Repeated Subsequence116
1152Kth Smallest Number in Multiplication Table Leetcode Solution116
1153Delete Nodes and Return Forest Leetcode Solution116
1154K’th Largest element in BST using constant extra space116
1155Count even length binary sequences with same sum of first and second half bits116
1156Maximum Product of Splitted Binary Tree LeetCode Solution116
1157Merge two BSTs with limited extra space116
1158Priority Queue116
1159Check Array Formation Through Concatenation Leetcode Solution116
1160Rotate Array116
1161Palindromic Substrings Leetcode Solution116
1162Factorial Trailing Zeroes LeetCode Solution116
1163Subset Sum Problem in O(sum) space116
1164Binary Tree to Binary Search Tree Conversion116
1165Queries for Number of Distinct Elements in a Subarray116
1166Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1167Find the smallest binary digit multiple of given number115
1168Maximize sum of consecutive differences in a circular array115
1169Decision Tree115
1170Bus Routes Leetcode Solution114
1171Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1172Search Suggestions System LeetCode Solution114
1173Count Pairs Whose Products Exist in Array114
1174Minimum Sideway Jumps LeetCode Solution114
1175First Bad Version114
1176Minimum Moves to Equal Array Elements LeetCode Solution114
1177Closest Binary Search Tree Value Leetcode Solution114
1178Number of Orders in the Backlog Leetcode Solution113
1179Find a sorted subsequence of size 3 in linear time113
1180Minimum Cost to Move Chips to The Same Position LeetCode Solution113
1181Diameter of N-Ary Tree LeetCode Solution113
1182Given a binary tree, how do you remove all the half nodes?113
1183Maximum number of segments of lengths a, b and c113
1184Reverse a Path in BST using Queue113
1185Contiguous Array LeetCode Solution112
1186Queue Reconstruction by Height112
1187Lowest Common Ancestor in Binary Search Tree112
1188Decrease Elements To Make Array Zigzag LeetCode Solution112
1189Web Crawler LeetCode Solution112
1190Swapping Nodes in a Linked List Leetcode Solution112
1191Find Largest Value in Each Tree Row LeetCode Solution112
1192Reformat Date LeetCode Solution111
1193Champagne Tower LeetCode Solution111
1194Matchsticks to Square Leetcode Solution111
1195Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution111
1196Moving Stones Until Consecutive Leetcode Solution111
1197Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1198Closest Leaf in a Binary Tree LeetCode Solution111
1199Valid Perfect Square LeetCode Solution110
1200Sum of Left Leaves LeetCode Solution110
1201New 21 Game110
1202Maximum sum of pairs with specific difference110
1203How to print maximum number of A’s using given four keys110
1204Replace two consecutive equal values with one greater110
1205Array Queries for multiply replacements and product110
1206Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1207Graph and its representation110
1208Maximum sum bitonic subarray110
1209Range Sum Query using Sparse Table110
1210Integer Break LeetCode Solution110
1211Valid Triangle Number110
1212Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution109
1213BST to a Tree with Sum of all Smaller Keys109
1214Path Crossing Leetcode Solution109
1215The kth Factor of n Leetcode Solution109
1216Concatenation of Array LeetCode Solution109
1217Kth Smallest Element in a BST109
1218Maximum Depth Of Binary Tree109
1219Print modified array after multiple array range increment operations109
1220Write a function to get the intersection point of two Linked Lists109
1221Lowest Common Ancestor of a Binary Tree Leetcode Solution108
1222Range Queries for Longest Correct Bracket Subsequence108
1223Check if each internal node of a BST has exactly one child108
1224Design Skiplist LeetCode Solution108
1225Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1226Maximum sum of a path in a Right Number Triangle108
1227Arithmetic Slices II – Subsequence LeetCode Solution108
1228Merge Sort108
1229Guess The Word108
1230Check for Identical BSTs without building the trees107
1231Queries on Probability of Even or Odd Number in given Ranges107
1232Count Subsets Having Distinct Even Numbers107
1233Check Completeness of a Binary Tree LeetCode Solution107
1234Flatten 2D Vector LeetCode Solution107
1235Perfect Squares LeetCode Solution107
1236Divide Two Integers Leetcode Solution107
1237Sliding Window Median Leetcode Solution107
1238Check if all levels of two Binary Tree are anagrams or not107
1239Graph Cloning107
1240Longest Common Prefix Using Word by Word Matching106
1241Largest Plus Sign Leetcode Solution106
1242Maximum Array from Two given Arrays Keeping Order Same106
1243Power of Two106
1244Symmetric Tree LeetCode Solution Leetcode Solution106
1245Print n terms of Newman-Conway Sequence106
1246Maximize Elements Using Another Array106
1247LRU Cache Leetcode Solution106
1248Bold Words in String LeetCode Solution105
1249Count and Toggle Queries on a Binary Array105
1250Contiguous Array105
1251Mean of range in array105
1252Find minimum number of merge operations to make an array palindrome105
1253Find Minimum in Rotated Sorted Array II LeetCode Solution105
1254Find k-th smallest element in BST (Order Statistics in BST)105
1255Next greater element104
1256Missing Number104
1257Verify Preorder Serialization of a Binary Tree104
1258Merge k Sorted Lists Leetcode Solution103
1259Print Ancestors of a Given Binary Tree Node Without Recursion103
1260Excel Sheet Column Title LeetCode Solution103
1261Maximum Product Subarray103
1262Check If a String Can Break Another String Leetcode Solution103
1263Parallel Courses II LeetCode Solution103
1264Smallest Range II Leetcode Solution102
1265Image Overlap LeetCode Solution102
1266Check if two nodes are on the same path in a Tree102
1267Minimum Remove to Make Valid Parentheses LeetCode Solution102
1268Orderly Queue LeetCode Solution101
1269Minimum Time to Collect All Apples in a Tree LeetCode Solution101
1270Palindrome Partitioning101
1271Koko Eating Bananas LeetCode Solution100
1272Check in binary array the number represented by a subarray is odd or even100
1273Min Cost Climbing Stairs LeetCode Solution98
1274Merge Sorted Array98
1275Newman–Shanks–Williams prime98
1276Peeking Iterator LeetCode Solution98
1277Different Ways to Add Parentheses Leetcode Solution98
1278Number of elements less than or equal to a given number in a given subarray98
1279Check if X can give change to every person in the Queue98
1280Maximum Sum Increasing Subsequence97
1281Largest Submatrix With Rearrangements LeetCode Solution97
1282Longest Substring Without Repeating Characters Leetcode Solution95
1283Range Minimum Query (Square Root Decomposition and Sparse Table)95
1284Find maximum average subarray of k length95
1285Number of indexes with equal elements in given range95
1286Queries for Decimal Values of Subarrays of a Binary Array94
1287Check given array of size n can represent BST of n levels or not94
1288Maximum product of an increasing subsequence93
1289Binary Tree to Binary Search Tree Conversion using STL set93
1290Array Nesting Leetcode Solution93
1291Minimum Number of People to Teach LeetCode Solution92
1292Arranging Coins Leetcode Solution92
1293Encoded String With Shortest Length LeetCode Solution91
1294Minimum Total Space Wasted With K Resizing Operations LeetCode Solution91
1295Random Pick Index LeetCode Solution91
1296Find the Winner of the Circular Game LeetCode Solution90
1297Reach a Number LeetCode Solution90
1298Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1299Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1300Queries on XOR of greatest odd divisor of the range90
1301Convert to Base -2 LeetCode Solution89
1302Jump Game IV LeetCode Solution89
1303Insert Delete GetRandom O(1) Leetcode Solution88
1304Vertical Order Traversal of Binary Tree LeetCode Solution86
1305Palindrome Number LeetCode Solution86
1306Add Two Numbers II Leetcode Solution86
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution84
1308Print Maximum Length Chain of Pairs83
1309Design Underground System Leetcode Solution83
1310Continuous Subarray Sum LeetCode Solution82
1311Detect Capital Leetcode Solution80
1312Design A Leaderboard Leetcode Solution78
1313Minimum Swaps to Group All 1’s Together Leetcode Solution75
1314Substring with Concatenation of All Words Leetcode Solution75
1315Top K Frequent Elements LeetCode Solution72
1316Minimum Path Sum Leetcode Solution72
1317Odd Even Linked List Leetcode Solution71
1318Maximum Population Year LeetCode Solution70
1319Decode String Leetcode Solution70
1320Binary Tree Inorder Traversal LeetCode Solution70
1321Count Sub Islands LeetCode Solution69
1322Shifting Letters LeetCode Solution69
1323Find the Town Judge LeetCode Solution68
1324Shortest Unsorted Continuous Subarray LeetCode Solution68
1325Longest Common Subsequence LeetCode Solution68
1326Best Meeting Point LeetCode Solution68
1327Sum Root to Leaf Numbers LeetCode Solution67
1328Find the Town Judge LeetCode Solution66
1329Design Add and Search Words Data Structure LeetCode Solution65
1330Rectangle Overlap LeetCode Solution63
1331Maximum Population Year LeetCode Solution62
1332Score of Parenthesis LeetCode Solution60
1333Stone Game IV LeetCode Solution60
1334Insert into a Sorted Circular Linked List LeetCode Solution60
1335Flatten Binary Tree to Linked List LeetCode Solution59
1336Range Sum Query 2D – Immutable LeetCode Solution59
1337Valid Triangle Number LeetCode Solution58
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution52
1340Divide Chocolate LeetCode Solution47
1341Range Sum of BST LeetCode Solution40
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution38
1343Sort Colors LeetCode Solution36
1344Reverse Integer Leetcode Solution36
1345Find K Closest Elements LeetCode Solution32
1346Rotate String LeetCode Solution30
1347Excel Sheet Column Number LeetCode Solution29
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »