Sort Colors LeetCode Solution

Difficulty Level Medium
Frequently asked in Accolite Adobe Amazon Apple Bloomberg eBay Expedia Facebook Goldman Sachs Google Grab Intel Microsoft Morgan Stanley Nvidia Oracle Pocket Gems Salesforce Samsung ServiceNow Spotify Sprinklr Swiggy Tesla Uber Visa VMware Yahoo
Walmart Global techViews 34

Problem Statement

Sort Colors LeetCode Solution – Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.

We will use the integers 01, and 2 to represent the color red, white, and blue, respectively.

You must solve this problem without using the library’s sort function.


Example 1:


Sort Colors LeetCode SolutionPin

 nums = [2,0,2,1,1,0]



Example 2:


 nums = [2,0,1]





  • n == nums.length
  • 1 <= n <= 300
  • nums[i] is either 01, or 2.


Follow up: Could you come up with a one-pass algorithm using only constant extra space?




Counting Sort

iterate the array and count  frequency of each element

here count is the frequency  of 0 ,count1 is freq of 1 and count 2 is frequency of 2

now iterate the array again and first place all 0 then 1 then 2

void sortColors(vector<int>& nums) {
       int n=nums.size();
       int count=0,count1=0,count2=0;
       for(int i=0;i<n;i++)
           else if(nums[i]==1)count1++;
           else if(nums[i]==2)count2++;
       for(int i=0;i<n;i++)
           else if(count1>0)
       return ;

Time Complexity:

O(2*n) where n is size of the array

as we iterate the array two times.

Space Complexity:

O(1) as we are not using extra space.


  1. this is the dutch national flag algorithm approach
  2. make 3 pointer i,j k
  3. i represent that the ele from 0 to i-1 must be equal to 0.
  4.  j represent that the element from j+1 to last(i.e) must be equal to 2
  5. now we travere the array with the help of pointer k


       1.  if(nums[k]==0)we swap nums[i] ans nums[k] and do i++ and k++; as we know that (0 to i-1 all elements must be 0).

2. else if(nums[k]==2)we swap nums[i] and nums[k] and do j– as we know that (j+1 to n-1 all elements must be 2).

3. else if(nums[k]==1)we just do k++ as if all zeors are on the left and all twos are on the right than all ones must be in middle.


void sortColors(vector<int>& nums) {
       int n=nums.size();
       int i=0,j=n-1,k=0;
           else if(nums[k]==0)
           else if(nums[k]==2)
       return ;
class Solution {
   public void sortColors(int[] nums) {
  int i = 0, j = nums.length - 1, k = 0;
  while( k <= j ) {
    if( nums[k] == 0 ) 
            swap(nums, i, k);
    else if( nums[k] == 2)
            swap(nums, j, k); 

public void swap(int[] nums, int i, int j) {
  int temp = nums[i];
  nums[i] = nums[j];
  nums[j] = temp;

Time Complexity:

O(n) where n is the size of the array

as we iterate the array only one time

Space Complexity:

O(1) as we are not using extra space.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2813
2Java program to find the number of Nodes in a Binary Tree2497
3Reverse a string without affecting special characters2451
4Delete a node of a linked list at given position1971
5Palindrome using Recursion1772
6Insert nodes in a linked list in a sorted way (Ascending Order)1655
7Find elements pair from array whose sum equal to number1643
8Sort Elements by Frequency of Occurrences1622
9Write a program to print all permutations of a given string1598
10Find Minimum Distance Between Two Numbers in an Array1465
11Create a Doubly Linked List1442
12Quick Sort1414
13Reverse an Array1405
14Smallest window in a string containing all characters of another string1387
15Find a Triplet That Sum to a Given Value1353
16Recursively remove all adjacent duplicates1347
17First Repeating Element1330
18Arrange Even and Odd number such that Odd comes after Even1315
19Sum of numbers in String1308
20Smallest Positive Number Missing in an Unsorted Array1276
21Check if the Elements of an Array are Consecutive1246
22Detect a loop in the Linked List1233
23Largest Sum Contiguous Subarray1223
24Quick Sort on SIngly Linked List1211
25Subarray with Given Sum1205
26Print all Possible Combinations of R Elements in a given Array of size N1196
27Recursive function to do substring search1193
28Find the Maximum Repeating Number in Array1147
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1115
31Check if two linked lists are identical1099
32Maximum Subarray Sum using Divide and Conquer1096
33Remove characters from first string which are in second1063
34Find Leaders in an Array1056
35Swap nodes in the linked list1030
36Find the Number Occurring Odd Number of Times in an Array998
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 Sum955
41Given a sorted array and a number x, find the pair in array whose sum is closest to x949
42Total number of occurrences of a given item in the linked list949
43A Program to check if strings are rotations of each other or not940
44Print all possible words from phone digits927
45Find the Missing Number920
46Rearrange Positive and Negative Numbers Alternatively in Array912
47Longest Palindromic Substring896
48Segregate even and odd nodes in a linked list880
49Print Longest common subsequence876
50Union and Intersection of Two Linked Lists869
51Transform one string to another using minimum number of given operations860
52Rearrange given Array in Maximum Minimum Form840
53Check rearranged string can form a palindrome840
54Count Possible Triangles816
55Iterative Implementation of Quick Sort811
56Multiplication of Two Matrices795
57Check if the linked list is palindrome792
58Rotate a Linked List787
59Count of Triplets With Sum Less than Given Value787
60Stock Buy Sell to Maximize Profit782
61Concatenation of two strings755
62Tug of War754
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string747
65Find Nearest Greater and Smaller Element739
66The Celebrity Problem734
67Find Pythagorean Triplets from Array733
68Reverse String Without Temporary Variable726
69Remove ‘b’ and ‘ac’ from a given string725
70Find all Common Elements in Given Three Sorted Arrays723
71Remove all duplicates in an unsorted linked list705
72Find the Row with Maximum Number of 1’s701
73Find the Peak Element from an Array693
74Find the subarray whose sum is equal to a given number X692
75Insertion Sort684
76Remove Minimum Characters so that Two Strings Become Anagrams683
77A Product Array Puzzle679
78Find Smallest Missing Number in a Sorted Array679
79Addition of Two Matrices677
80Implement Two Stacks in an Array671
81Generate all Binary Strings Without Consecutive 1’s669
82Maximum Sum of Non Consecutive Elements666
83Maximum Product Subarray II657
84Lexicographic rank of string648
85Multiplication of Previous and Next640
86Check if Two given Matrices are Identical640
87Merge K Sorted Arrays and Print Sorted Output630
88Subtraction of Two Matrices630
89Move All the Zeros to the End of the Given Array624
90Divide a string in N equal parts619
91Form Minimum Number from Given Sequence of D’s and I’s617
92Online Algorithm for Checking Palindrome in a Stream617
93Check whether two strings are anagram of each other610
94Remove recurring digits in a given number607
95Sort a linked list that is sorted alternating ascending and descending606
96Maximum Circular Subarray Sum605
97Sort a stack using a temporary stack603
98Move last element of the Linked List at first place600
99Find the Minimum Element in a Sorted and Rotated Array597
100First Circular Tour to Visit all the Petrol Bunks595
101Subarray and Subsequence591
102Largest Subarray with Equal Number of 0’s and 1’s591
103Flattening a linked list589
104Compare two strings(linked lists)588
105Maximum Element in an Array which is Increasing and then Decreasing587
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array576
108Majority Element572
109Run length encoding571
110Minimum insertions to form a shortest palindrome570
111Print all permutations with repetition569
112Palindromes in a given range569
113Pangram Checking564
114Rearrange a given linked list in-place561
115Remove all duplicates in a sorted linked list560
116Merge a linked list into another at alternate positions560
117Minimum Characters to be Added at Front to Make String Palindrome558
118Minimum number of Merge Operations to make an Array Palindrome556
119Rotate string to get lexicographically minimum string555
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 Problem539
125Clone a Linked List with next and random pointer535
126Merge Overlapping Intervals II533
127Two Sum Leetcode Solution525
128Size of The Subarray With Maximum Sum524
129Transpose of a Matrix521
130Removing Spaces from a String using stringstream517
131Remove Extra Spaces from a String517
132Check if a given string is a rotation of a palindrome514
133Partition Problem513
134Smallest Palindrome after Replacement512
135Remove duplicates from a string512
136Longest Palindrome can be Formed by Removing or Rearranging Characters510
137Maximum Sum Increasing Subsequence509
138Generate all Binary Strings from Given Pattern498
139Check whether Strings are K Distance Apart or Not497
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized495
141Insert Node in the Sorted Linked List495
142Delete Last Occurrence494
143Length of Longest valid Substring493
1443Sum Leetcode Solution490
145Check if Two given Strings are Isomorphic to each other488
146Maximum difference between two elements such as larger element comes after smaller484
147Program to Toggle all Characters in a String480
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 lists473
151Number of Smaller Elements on Right Side470
152Find Pair with Given Difference468
153Check length of a String is Equal to the Number Appended at its Last467
154Check if all Rows of a Matrix are Circular Rotations of Each Other467
155Longest Common Prefix using Divide and Conquer466
156Find nth node of the Linked list from the end465
157Sort 0s 1s and 2s in an Array456
158Find a Fixed Point in a Given Array455
159Print all interleavings of given two strings454
160Merge two sorted linked lists such that merged list is in reverse order452
161Find the Subarray of given length with Least Average451
162Compare Two Version Numbers450
163Reorder Array Using Given Indexes449
164Split linked list using alternate nodes448
165Reverse words in a given string448
166Print Reverse of a string (Recursion)444
167Median of Two Sorted Arrays LeetCode Solution443
168Print string of odd length in ‘X’ format433
169Swap Kth Node from beginning with Kth Node from End430
170Find Element Using Binary Search in Sorted Array429
171Find K Length Subarray of Maximum Average429
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way420
174print all palindromic partitions418
175Flatten a multilevel linked list414
176Shortest Superstring Problem413
177Maximum Length of Chain Pairs409
178Sorting a K Sorted Array407
179Check if String Follows Order of Characters by a Pattern or not407
180Sort a String According to Another String400
181Longest Span with same Sum in two Binary Arrays II396
182Reverse a Linked List in groups394
183Find a Sorted Subsequence of size 3390
184Program to add two binary digits386
185Recursively print all the sentences that can be formed from list of word lists385
186Find the two Numbers with Odd Occurrences in an Unsorted Array385
187Longest Common Prefix Using Binary Search II382
188Reverse a Singly Linked List (Iterative/Non-Recursive)379
189Rearrange a linked list in Zig-Zag376
190Kth Non-repeating Character375
191Caesar Cipher374
192Check if String can Become Empty by Recursively Deleting given Substring373
193Pancake Sorting371
194Rotate Image by 90 degrees369
195Longest Common Prefix Word by Word Matching367
196Perfect Reversible String363
197Permutations of a Given String Using STL362
198Merging Two Sorted Arrays360
199Increasing Subsequence of Length three with Maximum Product360
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes357
201Find the point where a monotonically increasing function becomes positive first time357
202Sort a linked list with 0s, 1s and 2s356
2031`s and 2`s complement of binary number354
204Find First non-repeating character in a string354
205Four Elements that Sum to Given351
206List items containing all characters of a given word350
207Delete N nodes after M350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array343
210Split a string338
211Palindrome string (number)337
212Minimum Characters to be Removed to Make a Binary String Alternate336
213Check if a Linked list of Strings form a Palindrome331
214Print All Distinct Elements of the Array328
215Sorting the array of strings328
216Recursive Implementation of atoi()328
217Convert a String that is Repetition of a Substring of Length K326
218Find the first Repeating Number in a Given Array323
219Even Substring Count323
220Reverse a singly linked list recursively321
221Binary Tree to Doubly linked list320
222Print Shortest Path to Print a String on Screen319
223Can we reverse a linked list in less than O(n) time ?318
224Maximum occurring character in a string317
225Valid Parentheses LeetCode Solution316
226Nth Character in Concatenated Decimal String315
227Sort Elements by Frequency II315
228Convert string1 to string2 in one edit315
229wildcard character matching313
230Lower Case To Upper Case311
231Reverse a String using Stack311
232Merge Two Sorted Arrays309
233Maximum Subarray Leetcode Solution308
234Find the Lost Element From a Duplicated Array308
235Count the number of words308
236Split Four Distinct Strings306
237Find middle of the Linked List303
238Longest Common Subsequence with Permutations298
239Count the Pairs at Same Distance as in English Alphabets297
240Next Greater Element in an Array293
241Matrix Chain Multiplication using Dynamic Programming291
242Palindrome Permutation286
243Find Nth Node282
244Searching a node in a Binary Search Tree281
245Find All Pairs With a Given Difference281
246Delete a Tree278
247Roman to Integer Leetcode Solution278
248Triplet from three linked lists with given sum278
249String(represents an integer) to value275
250Print all Possible Ways to Break a String in Bracket Form274
251Reverse a String274
252Binary Tree271
253Delete a node under given conditions270
254Change Gender of a given String270
255Reverse Bits269
256Sort an array of strings268
257Word Search Leetcode Solution266
258Number of sub-strings which recursively add up to 9265
259How to Efficiently Implement k Stacks in a Single Array?264
260Remove middle points in a linked list of line segments264
261Longest Common Extension263
262Toeplitz Matrix261
263First non Repeating Element259
264Remove spaces from a string259
265Count Pairs With Given Sum257
266Repeated Substring Pattern257
267Meeting Rooms II LeetCode Solution257
268Shuffle a given Array257
269Longest Palindromic Substring LeetCode Solution255
270Move all negative elements to one side of array254
271N queen problem252
272Min Stack251
273Find, second, frequent, character249
274Dijkstra Algorithm247
275Number of Islands LeetCode Solution245
276Cuckoo sequence program245
277Most Frequent Element in an Array244
278Clone a linked list with next and random pointer (Hashing)244
279Max stack243
280Minimize the maximum difference between the heights242
281Sort linked which is sorted on absolute values242
282House Robber Leetcode Solution241
283Fibonacci numbers238
284Search Insert Position Leetcode Solution237
285Expression Evaluation237
286How to Delete a Linked List237
287Valid Palindrome Leetcode Solution235
288KMP Algorithm234
289Sudoku Solver234
290Min Stack Leetcode Solution233
291Plus One Leetcode Solution233
292Word Search233
293Evaluation of Postfix Expression232
294Reverse words in a string231
295Number Of 1 bits231
296Subset Leetcode231
297Combination Sum Leetcode Solution230
298Backspace String Compare225
299Merge Sorted Arrays Leetcode Solution224
300Rabin Karp Algorithm223
301Set Matrix Zeroes222
302Pair of Positive Negative Values in an Array222
303Reversing a Queue222
304Tower Of Hanoi221
305Sqrt(x) Leetcode Solution221
306Subarray with 0 sum220
307Contains Duplicate II Leetcode Solution219
308Combination Sum219
309Common elements in all rows of a given matrix218
310Product of array except self217
311Integer to Roman Leetcode Solution216
312Intersection of Two Arrays II Leetcode Solution216
313Pascal Triangle Leetcode214
314Reverse individual words214
315String Compression213
316Delete middle element of a stack213
317Construct Binary Tree from Given Inorder and Preorder Traversals212
318Minimum swaps required to bring all elements less than or equal to k together212
319Count subarrays with equal number of 1’s and 0’s211
320Find Top K (or Most Frequent) Numbers in a Stream211
321Sliding Window Technique211
322Bellman Ford Algorithm210
323Add Binary Leetcode Solution209
324Arithmetic Expression Evaluation209
325Page Replacement Algorithms in Operating Systems209
326Pow(x, n) Leetcode Solution208
327Count of index pairs with equal elements in an array208
328Segregate even and odd numbers208
329Single Number Leetcode Solution208
330Palindrome Linked List Leetcode Solution207
331Second Most Repeated Word in a Sequence207
332Kruskal Algorithm207
333Contains Duplicate206
334Design a stack that supports getMin() in O(1) time and O(1) extra space206
335Implementation of Deque using Doubly Linked List206
336Minimum Value to Get Positive Step by Step Sum Leetcode Solution206
337Find sum of non-repeating elements (distinct) elements in an array206
338Next Permutation206
339Postfix to Infix Conversion206
340Sort elements by frequency205
341Count Odd Numbers in an Interval Range Leetcode Solution205
342Maximum Number of Balloons Leetcode Solution205
343Maximum Subarray203
344Third Maximum Number Leetcode Solution203
345Group Words With Same Set of Characters203
346Longest Common Prefix Leetcode Solution202
347K-th Smallest Element in a Sorted Matrix202
348Longest Substring Without Repeating Characters LeetCode Solution201
349Find Lucky Integer in an Array Leetcode Solution201
350Find Numbers with Even Number of Digits Leetcode Solution201
351Permutations Leetcode Solution201
352Convex Hull Algorithm201
353Sorting array using Stacks201
354Top K Frequent Words200
355Sum of minimum and maximum elements of all subarrays of size k200
356Minimum operation to make all elements equal in array199
357Smallest Subarray with k Distinct Numbers199
358Scramble String199
359Count subarrays having total distinct elements same as original array199
360Find the Town Judge Leetcode Solution199
361Evaluate Division198
362Swap Nodes in Pairs Leetcode Solutions198
363Majority Element Leetcode Solution197
364Spiral Matrix LeetCode Solution197
365Special Number197
366First element occurring k times in an array196
367Merge Two Sorted Lists Leetcode Solutions195
368Given two unsorted arrays find all pairs whose sum is x195
369Check if two arrays are equal or not195
370Minimum Path Sum194
371Count Primes Leetcode Solutions194
372Group Anagrams194
373Prefix to Infix Conversion194
374Reverse a Number Using Stack193
375Search in Rotated Sorted Array Leetcode Solution193
376Huffman Coding193
377Reversing the First K elements of a Queue193
378Best Time to Buy and Sell Stock  II Leetcode Solution192
379Find duplicates in a given array when elements are not limited to a range192
380Power of Two Leetcode Solution192
381Number of Good Pairs Leetcode Solution192
382Minimum Steps to reach target by a Knight192
383Missing Number Leetcode Solution192
384Maximum Distance Between two Occurrences of Same Element in Array191
385Pascal’s Triangle II Leetcode Solution191
386Single Number191
387Minimum Absolute Difference Leetcode Solution191
388Maximal Square191
389House Robber II Leetcode Solution190
390Sort Array by Increasing Frequency Leetcode Solution190
391Range Sum Query 2D – Immutable Leetcode Solution190
392Sorting using trivial hash function189
393Top K Frequent Elements189
394Unique Paths Leetcode Solution189
395Fizz Buzz Leetcode189
396Running Sum of 1d Array Leetcode Solution188
397Find All Numbers Disappeared in an Array Leetcode Solution188
398Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution188
399Matrix Diagonal Sum Leetcode Solution188
400Check if Array Contains Contiguous Integers With Duplicates Allowed187
401Leetcode Permutations187
402Unique Paths187
403Expression Contains Redundant Bracket or Not187
404How to Implement Stack Using Priority Queue or Heap?187
405Happy Number Leetcode Solution187
406Zigzag Conversion187
407Coin Change 2 Leetcode Solution187
408Maximum possible difference of two subsets of an array187
409Fibonacci Number LeetCode Solution187
410Find The Duplicate Number186
411Palindrome Substring Queries186
412Subset sum problem186
413Find Winner on a Tic Tac Toe Game Leetcode Solution186
414Subarray Sum Equals K LeetCode Solution186
415Decode String185
416Difference between highest and least frequencies in an array185
417Cumulative Frequency of Count of Each Element in an Unsorted Array185
418Convert String To Int185
419How Many Numbers Are Smaller Than the Current Number Leetcode Solution185
420Find the Closest Palindrome number185
421Letter Case Permutation185
422Smallest Element Repeated Exactly K Times185
423Nth Catalan Number185
424Reverse Integer184
425Max Consecutive Ones Leetcode Solution184
426Sort a stack using recursion184
427Subarray Sum Equals k184
428Sort Integers by The Number of 1 Bit Leetcode Solution184
429Remove Duplicates from Sorted Array Leetcode Solution184
430Find Number of Employees Under every Employee184
431Reverse Vowels of a String Leetcode Solution184
432Bipartite Graph183
433Subtract the Product and Sum of Digits of an Integer Leetcode Solution183
434Find top three repeated in array183
435Monotonic Array LeetCode Solution183
436Print All Distinct Elements of a Given Integer Array183
437Find Median from data Stream183
438Best Time to Buy and Sell Stock III Leetcode Solution183
439Check If N and Its Double Exist Leetcode Solution183
440Shuffle the Array Leetcode Solution183
441Trapping Rain Water Leetcode Solution183
442Length of the largest subarray with contiguous elements183
443Implement Stack and Queue using Deque182
444LRU Cache Implementation182
445Generate a String With Characters That Have Odd Counts Leetcode Solution181
446Maximum Depth of Binary Tree Leetcode Solution181
447Find the first repeating element in an array of integers181
448Find the Duplicate Element181
449Prim’s Algorithm181
450Sum of Subarray Ranges Leetcode Solution181
451Capacity To Ship Packages Within D Days Leetcode Solution181
452Find Minimum In Rotated Sorted Array181
453Reverse a Stack Using Recursion181
454Subarrays with distinct elements181
455Count Substrings with equal number of 0s, 1s and 2s180
456Merge Two Sorted Linked Lists180
457Kth largest element in an Array Leetcode Solutions180
458Integer to English words180
459Find all pairs (a, b) in an array such that a % b = k180
460Reverse Words in a String III LeetCode Solution180
461Priority Queue Using Singly Linked List180
462Find Common Characters Leetcode Solution179
463Delete a Node from linked list without head pointer179
464Count pairs from two linked lists whose sum is equal to a given value179
465Longest Common Subsequence179
466The K Weakest Rows in a Matrix Leetcode Solution179
467Sorting a Queue without Extra Space179
468Fizz Buzz178
469Edit Distance178
470Count and Say178
471Reverse a linked list178
472Find the Difference Leetcode Solution178
473MiniMax Algorithm178
474Reverse a String178
475Remove Minimum Number of Elements Such That no Common Element Exist in both Array178
476Find elements which are present in first array and not in second178
477Floyd Warshall Algorithm177
478Print all subarrays with 0 sum177
479Target Sum177
480Text Justification LeetCode Solution177
481Excel Sheet Column Number Leetcode Solution177
482Concatenation of Array LeetCode Solution176
483Find First and Last Position of Element in Sorted Array Leetcode Solution176
484Kth Largest Element in a Stream Leetcode Solution176
485Next Greater Element I Leetcode Solution176
486Balanced Binary Tree Leetcode Solution176
487Degree of an array176
488Longest Common Prefix using Trie176
489Kids With the Greatest Number of Candies Leetcode Solution175
490Flood Fill LeetCode175
491Merge Overlapping Intervals175
492Number of Steps to Reduce a Number to Zero Leetcode Solution175
493Iterative Tower of Hanoi175
494Design Parking System Leetcode Solution175
495Word Ladder LeetCode Solution174
496Priority Queue in C++174
497Multiply Strings Leetcode Solution174
498Longest subarray not having more than K distinct elements174
499Shortest Palindrome174
500Top View of Binary Tree174
501Pair with given product174
502Valid Parenthesis String173
503Find four elements that sum to a given value (Hashmap)173
504Count and Say Leetcode Solution173
505Prefix to Postfix Conversion173
506Find N Unique Integers Sum up to Zero Leetcode Solution173
507Postfix to Prefix Conversion173
508Find subarray with given sum (Handles Negative Numbers)173
509Minimum Moves to Equal Array Elements Leetcode Solution173
511Intersection of Two Arrays172
512Max Area of Island172
513Contiguous Array Leetcode172
514Find missing elements of a range172
515Peak Index in a Mountain Array172
516Slowest Key Leetcode Solution172
517Length of Last Word Leetcode Solution172
518The Stock Span Problem172
519Koko Eating Bananas Leetcode Solution172
520Move Zeroes LeetCode Solution172
521Count number of triplets with product equal to given number171
522Find distinct elements common to all rows of a matrix171
523Implement a stack using single queue171
524Implement Stack using Queues171
525Convert array into Zig-Zag fashion171
526Iterative Inorder Traversal of a Binary Tree171
527Zigzag Conversion LeetCode Solution171
528Substring With Concatenation Of All Words171
529Check if a given array contains duplicate elements within k distance from each other171
530Longest Common Prefix using Sorting170
531Jump Game Leetcode Solution170
532Smallest Subarray With all Occurrences of a Most Frequent Element170
533Mobile Numeric Keypad Problem170
534Container with Most Water170
535Last Stone Weight170
536Find Index of Closing Bracket for a Given Opening Bracket in an Expression170
537K-th Distinct Element in an Array170
538Find any one of the multiple repeating elements in read only array170
539Delete Node in a Linked List Leetcode Solution169
540Shuffle String Leetcode Solution169
541Next Greater Frequency Element169
542Relative Sort Array Leetcode Solution169
543Best Time to Buy and Sell Stock169
544Valid Sudoku169
545Convert a normal BST to Balanced BST169
546Build Array From Permutation Leetcode Solution168
547Largest Perimeter Triangle Leetcode Solution168
548Excel Sheet Column Title Leetcode Solution168
549Minimum Bracket Reversals168
550Shuffle an Array167
551Arrange given numbers to form the biggest number167
552Minimum Operations to convert X to Y167
553First negative integer in every window of size k167
554Rearrange a binary string as alternate x and y occurrences167
555Isomorphic Strings Leetcode Solution167
556Sum of Left Leaves Leetcode Solutions167
557Distribute Candies to People Leetcode Solution167
558Find Words That Can Be Formed by Characters Leetcode Solution167
559Assign Cookies Leetcode Solution167
560Is Subsequence Leetcode Solution167
561Check for Balanced Parentheses in an Expression167
562Change the Array into Permutation of Numbers From 1 to N166
56301 Matrix LeetCode Solution166
564N-th Tribonacci Number Leetcode Solution166
565The Knapsack Problem166
566Integer to Roman166
567Maximum sum rectangle in a 2D matrix166
568Implementation of Deque using circular array166
569Group Multiple Occurrence of Array Elements Ordered by first Occurrence166
570Valid Anagrams166
571Jewels and Stones Leetcode Solution166
572Convert Sorted Array to Binary Search Tree Leetcode Solution165
573Linked List Cycle II LeetCode Solution165
574Minimum Delete Operations to make all Elements of Array Same165
575Hamming Distance165
576Unique Binary Search Trees165
577Island Perimeter Leetcode Solution165
578How to check if two given sets are disjoint?164
579Rotate List Leetcode Solution164
580Decode Ways164
581Remove Linked List Elements Leetcode Solution164
582Count the number of nodes at given level in a tree using BFS164
583Gold Mine Problem164
584Trapping Rain Water LeetCode Solution164
585Maximum path sum in a triangle164
586Find the smallest positive integer value that cannot be represented as sum of any subset of a given array164
587Combinations Leetcode Solution163
588LRU Cache LeetCode Solution163
589Same Tree LeetCode Solution163
590Shortest Path in a Grid with Obstacles Elimination LeetCode Solution163
591Sieve of Eratosthenes163
592Maximum Distance in Array163
593Summary Ranges Leetcode Solution163
594Minimum number of subsets with distinct elements162
595Find minimum difference between any two elements162
596Distance Between Bus Stops Leetcode Solution162
597Find Sum of all unique sub-array sum for a given array162
598Applications of Breadth First Search and Depth First Search162
599Insert Interval Leetcode Solution162
600Maximum difference between first and last indexes of an element in array162
601Count all subsequences having product less than K162
6023Sum Closest LeetCode Solution162
603Minimum Knight Moves LeetCode Solution162
604Word Pattern161
605Minimum insertions to form a palindrome with permutations allowed161
606Maximum Number of Chocolates to be Distributed Equally Among k Students161
607Minimum number of distinct elements after removing m items161
608Rotate Image LeetCode Solution161
609Frog Jump Leetcode Solution161
610Find if an Expression has Duplicate Parenthesis or Not161
611Stone Game LeetCode160
612Best Time to Buy and Sell Stock LeetCode Solution160
613Distance of nearest cell having 1 in a binary matrix160
614License Key Formatting Leetcode Solution160
615Printing brackets in Matrix Chain Multiplication Problem160
616Permutation in String Leetcode Solution159
617Longest Increasing Subsequence159
618K Empty Slots LeetCode159
619Defanging an IP Address Leetcode Solution159
620Minimum Cost to Hire K Workers159
621Sort Characters By Frequency LeetCode Solution159
622Minimum Depth of Binary Tree Leetcode Solution159
623Replace Elements with Greatest Element on Right Side Leetcode Solution159
624House Robber159
625Sort Array By Parity LeetCode Solution159
626XOR Operation in an Array Leetcode Solution159
627Word Wrap Problem159
628Find the Duplicate Number LeetCode Solution158
629Coin Change Problem158
630Reverse a stack without using extra space in O(n)158
631Painting Fence Algorithm158
632Check If It Is a Straight Line Leetcode Solution158
633Maximum Consecutive Numbers Present in an Array158
634Smallest Good Base158
635Remove All Occurrences of a Substring LeetCode Solution158
636Kth Missing Positive Number Leetcode Solution157
637Non-overlapping sum of two sets157
638Find Maximum Level sum in Binary Tree157
639Segregate 0s and 1s in an Array157
640Queries for counts of array elements with values in given range156
641Longest Substring with At Most K Distinct Characters LeetCode Solution156
642Tracking current Maximum Element in a Stack156
643Strobogrammatic Number LeetCode Solution156
644Isomorphic Strings156
645Optimal Account Balancing LeetCode Solution156
646Valid Palindrome II Leetcode Solution156
647GCD Of Two Numbers156
648Merge Two Balanced Binary Search Trees156
649Best Time to Buy and Sell Stock with Cooldown Leetcode Solution156
650Iterative Method to find Height of Binary Tree156
651Wiggle Sort155
652Convert an array to reduced form155
653Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest155
654Binary Tree Zigzag Level Order Traversal LeetCode Solution155
655How to Create Mergable Stack?155
656Find Largest d in Array such that a + b + c = d155
657Employee Free Time LeetCode Solution155
658Reorganize String155
659Flipping an Image LeetCode Solution155
660Partition Labels LeetCode Solution155
661Moving Average from Data Stream Leetcode Solution155
662Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
663Maximum Number of Occurrences of a Substring Leetcode Solution154
664Inorder Successor of a node in Binary Tree154
665Check if a queue can be sorted into another queue using a stack154
666Count Good Nodes in Binary Tree Leetcode Solution154
667Path With Maximum Minimum Value LeetCode Solution154
668Letter Combinations of a Phone Number154
669Largest Sum Contiguous Subarray154
670Form minimum number from given sequence154
671Find the Distance Value Between Two Arrays Leetcode Solution154
672K Empty Slots154
673Longest Substring with At Least K Repeating Characters LeetCode Solution154
674Check If Two String Arrays are Equivalent Leetcode Solution153
675Sum of f(a[i], a[j]) over all pairs in an array of n integers153
676Sum of All Odd Length Subarrays Leetcode Solution153
677Find the Smallest Divisor given a Threshold Leetcode Solution153
678BFS vs DFS for Binary Tree153
679Number of Provinces Leetcode Solution153
680Sort Array by Increasing Frequency Leetcode Solution153
681Power of Four Leetcode Solution153
682Reservoir Sampling153
683Lucky Numbers in a Matrix Leetcode Solution153
684Populating Next Right Pointers in Each Node153
685Valid Palindrome153
686Reversing a Queue using Recursion152
687Construct BST from given Preorder Traversal152
688Find pairs with given sum such that elements of pair are in different rows152
689Find the node with minimum value in a Binary Search Tree152
690Delete consecutive same words in a sequence152
691Subset Sum Leetcode152
692Remove Invalid Parentheses Leetcode Solution152
693To Lower Case Leetcode Solution152
694Maximum Number of Coins You Can Get Leetcode Solution152
695Reducing Dishes LeetCode Solution152
696Print the Fibonacci numbers in reverse order152
697Majority Element II Leetcode Solution152
698Unique Paths II Leetcode Solution152
699Delete Nth node from the end of the given linked list152
700Partition Array Into Three Parts With Equal Sum Leetcode Solution152
701Number of Dice Rolls With Target Sum LeetCode Solution151
702Convert a Number to Hexadecimal Leetcode Solution151
703Longest Increasing Path in a Matrix LeetCode Solution151
704Add and Search Word – Data structure design LeetCode151
705Increasing Decreasing String Leetcode Solution151
706Find Leaves of Binary Tree LeetCode Solution151
707Permutation Sequence LeetCode Solution151
708Ugly Number Leetcode Solution151
709Factorial Trailing Zeroes Leetcode Solution151
710String to Integer (atoi) LeetCode Solution151
711Valid Perfect Square Leetcode Solution151
712Recover Binary Search Tree151
713Binary Tree zigzag level order Traversal150
714Edit Distance LeetCode Solution150
715Reverse Only Letters LeetCode Solution150
716Find whether an array is subset of another array150
717Dynamic Programming Basics150
718Restore IP Addresses Leetcode Solution150
719Maximum Product of Two Elements in an Array Leetcode Solution150
720Longest Span with same Sum in two Binary arrays149
721Hamming Distance Leetcode Solution149
722Keyboard Row Leetcode Solution149
723Largest subarray with equal number of 0s and 1s149
724Rank Transform of an Array Leetcode Solution149
725Minimum Distance Between BST Nodes Leetcode Solution149
726Merge Two Binary Trees LeetCode Solution149
727Binomial Coefficient149
728Numbers with prime frequencies greater than or equal to k149
729Bubble sort using two Stacks149
730Find Maximum Depth of Nested Parenthesis in a String149
731Merge K Sorted Linked Lists148
732Decompress Run-Length Encoded List Leetcode Solution148
733Find unique character in a string148
734Find Pair with Greatest Product in Array148
735Perform String Shifts Leetcode148
736Bulb Switcher LeetCode Solution148
737Minimum Cost For Tickets Leetcode Solution148
738Finding K closest element148
739Deletion in a Binary Tree148
740Stack Permutations (Check if an array is stack permutation of other)148
741Maximum 69 Number Leetcode Solution148
742Minimum Height Trees148
743Find the largest multiple of 3148
744Morris Traversal147
745Find All Duplicates in an Array LeetCode Solution147
746Count quadruples from four sorted arrays whose sum is equal to a given value x147
747Race Car LeetCode Solution147
748Growable array based stack147
749Symmetric Tree Leetcode Solution147
750Binary Tree Maximum Path Sum LeetCode Solution147
751Kth ancestor of a node in binary tree147
752Sorted Linked List to Balanced BST147
753Robot Room Cleaner Leetcode Solution147
754Best Meeting Point LeetCode Solution147
755Non-decreasing Array LeetCode Solution147
756Maximum Product of Three Numbers LeetCode Solution147
757Student Attendance Record I Leetcode Solution147
758Elements to be added so that all elements of a range are present in array147
759Jump Game147
760Word Pattern LeetCode Solution146
761Maximum Depth of N-ary Tree Leetcode Solution146
762Evaluate Reverse Polish Notation LeetCode Solution146
763Remove brackets from an algebraic string containing + and – operators146
764Diagonal Traversal of Binary Tree146
765Valid Number146
766Snakes and Ladders LeetCode Solution146
767Largest rectangular sub-matrix whose sum is 0146
768Generate all possible sorted arrays from alternate elements of two given sorted arrays146
769Minimum time required to rot all oranges146
770k-th missing element in increasing sequence which is not present in a given sequence146
771Special Array With X Elements Greater Than or Equal X Leetcode Solution145
772Largest Rectangle in Histogram LeetCode Solution145
773String Compression LeetCode Solution145
774Minimize Maximum Pair Sum in Array LeetCode Solution145
775Queue based approach for first non-repeating character in a stream145
776Find Median from Data Stream LeetCode Solution145
777First Unique Character in a String LeetCode Solution145
778Number of Islands II LeetCode Solution145
779Tiling Problem145
780N-Queens LeetCode Solution145
781Linked List Cycle145
782Program for Bridge and Torch problem145
783Search in a Binary Search Tree Leetcode Solution145
784Find if Path Exists in Graph Leetcode Solution144
785Final Prices With a Special Discount in a Shop Leetcode Solution144
786Partition to K Equal Sum Subsets Leetcode Solution144
787Maximum Difference Between Increasing Elements LeetCode Solution144
788Count items common to both the lists but with different prices144
789Check if Two Expressions With Brackets are Same144
790Sort an array according to the order defined by another array144
791Maximum Length of a Concatenated String with Unique Characters Leetcode Solution144
792Interval Tree144
793Transpose Graph144
794Nested List Weight Sum II LeetCode Solution144
795Number of NGEs to the Right144
796Check If Array Pairs Are Divisible by k LeetCode Solution144
797Split a String in Balanced Strings Leetcode Solution144
798Search a 2D Matrix II Leetcode Solution144
799Base 7 Leetcode Solution144
800Iterative Preorder Traversal143
801A Space Optimized DP solution for 0-1 Knapsack Problem143
802Crawler Log Folder Leetcode Solution143
803Permutation Coefficient143
804Print a Binary Tree in Vertical Order143
805Circular Queue143
806Remove Duplicates from Sorted List LeetCode Solution143
807Remove Duplicates from Sorted List II143
808Remove Nth Node From End of List Leetcode Solution143
809Minimum swaps to make sequences increasing143
810Check for Palindrome after every character replacement Query143
811Relative Ranks Leetcode Solution143
812Total Numbers With no Repeated Digits in a Range143
813Get Maximum in Generated Array Leetcode Solution143
814String comparison containing wildcards143
815Number Complement Leetcode Solution143
816Longest Subarray Having Count of 1s One More than Count of 0s142
817Course Schedule II – LeetCode142
818Nearest Exit from Entrance in Maze LeetCode Solution142
819Convert BST to Min Heap142
820Merge Sorted Array LeetCode Solution142
821Reorder Data in Log Files LeetCode Solution142
822Priority Queue using doubly linked list142
823Last Stone Weight II LeetCode Solution142
824Invert Binary Tree LeetCode Solution142
825Minimum Jumps to Reach Home LeetCode Solution141
826Maximum Nesting Depth of the Parentheses Leetcode Solution141
827Regular Expression Matching141
828Path with maximum average value141
829Maximum size subarray sum equals k141
830Minimum number of jumps to reach end141
831Minimum Time Visiting All Points Leetcode Solution141
832Design a Stack With Increment Operation Leetcode Solution141
833One Edit Distance LeetCode Solution141
834Clone Graph LeetCode Solution141
835Sort Colors141
836Alien Dictionary LeetCode Solution141
837Partition List Leetcode Solution141
838Sort Array By Parity II Leetcode Solution141
839Check if a given array can represent Preorder Traversal of Binary Search Tree140
840Count ways to reach the nth stair using step 1, 2 or 3140
841Sum of nearest smaller and greater number140
842Find the Only Repetitive Element Between 1 to N-1140
843Minimum Swaps to Make Strings Equal Leetcode Solution140
844Check if an Array is Stack Sortable140
845Find All Possible Recipes from Given Supplies LeetCode Solution140
846Find all triplets with zero sum140
847Valid Parentheses Leetcode Solution140
848Top K Frequent Words LeetCode Solution140
849Check whether a given Binary Tree is Complete or not140
850Matrix Chain Multiplication140
851Sorted Array to Balanced BST140
852Brightest Position on Street LeetCode Solution140
853Can Place Flowers LeetCode Solution140
854Form Minimum Number From Given Sequence140
855Friends Pairing Problem140
856Minimum Number of Taps to Open to Water a Garden LeetCode Solution140
857Subset with sum divisible by m140
858Brick Wall LeetCode Solution140
859Spiral Matrix II Leetcode Solution140
860Find the subarray with least average140
861Level order Traversal in Spiral Form139
862Insert into a Binary Search Tree Leetcode Solution139
863Subsequence of Size K With the Largest Even Sum LeetCode Solution139
864LCS (Longest Common Subsequence) of three strings139
865Range sum queries without updates139
866Binary Search Tree Search and Insertion139
867Given an Array of Pairs Find all Symmetric Pairs in it139
868Subarray Product Less Than K LeetCode Solution139
869Tree Traversal (Preorder, Inorder & Postorder)139
870Count Distinct Elements in Every Window of Size K139
871Maximum Profit in Job Scheduling Leetcode Solution139
872Count Negative Numbers in a Sorted Matrix LeetCode Solution138
873Identify and Mark Unmatched Parenthesis in an Expression138
874Sequences of given length where every element is more than or equal to twice of previous138
875Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
876Guess Number Higher or Lower LeetCode Solution138
877Union and Intersection of two Linked Lists138
878Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution138
879Insert Delete GetRandom138
880Maximum Score After Splitting a String Leetcode Solution138
881Find Maximum Sum Possible Equal Sum of Three Stacks138
882Minimum Sum Path in a Triangle138
883Check if stack elements are pairwise consecutive137
884Missing Element in Sorted Array LeetCode Solution137
885Guess Number Higher or Lower II137
886Destination City Leetcode Solution137
887A program to check if a binary tree is BST or not137
888GCDs of given index ranges in an array137
889Water Bottles Leetcode Solution137
890An Interesting Method to generate Binary Numbers from 1 to n137
891Distinct adjacent elements in an array137
892Delete And Earn137
893Find distance between two nodes of a Binary Tree137
894Balanced Expression with Replacement137
895Repeated Substring Pattern LeetCode Solution137
896BFS for Disconnected Graph137
897Alien Dictionary137
898Rearrange an Array Such that arr[i] is equal to i137
899Check if the given array can represent Level Order Traversal of Binary Search Tree136
900Design Browser History LeetCode Solution136
901Convert Sorted List to Binary Search Tree136
902Diagonal Traversal LeetCode Solution136
903Lemonade Change Leetcode Solution136
904Find Common Characters Leetcode Solution136
905Three way partitioning of an array around a given range136
906Set Matrix Zeroes Leetcode Solution136
907Rearrange Spaces Between Words Leetcode Solution136
908Merge Two Sorted Lists Leetcode136
909Diagonal Traverse LeetCode Solution136
910Least Number of Unique Integers after K Removals Leetcode Solution136
911Minimum sum of multiplications of n numbers136
912Find all permuted rows of a given row in a matrix136
913Number of Days Between Two Dates LeetCode Solution136
914Shortest Word Distance Leetcode Solution136
915Range LCM Queries136
916Spiral Matrix III LeetCode Solution136
917Number of Equivalent Domino Pairs Leetcode Solution135
918Maximum Subarray Sum Excluding Certain Elements135
919Count Subarrays with Same Even and Odd Elements135
920Construct Complete Binary Tree from its Linked List Representation135
921Queue using Stacks135
923Robot Bounded In Circle LeetCode Solution135
924K’th Largest Element in BST when modification to BST is not allowed135
925Averages of Levels in Binary Tree135
926Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i135
927Vertical sum in a given binary tree135
928Special Positions in a Binary Matrix Leetcode Solution135
929Construct the Rectangle Leetcode Solution135
930Lexicographical Numbers Leetcode Solution134
931Trim a Binary Search Tree134
932Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
933Print Fibonacci sequence using 2 variables134
934Infix to Postfix134
935Queries for GCD of all numbers of an array except elements in a given range134
936Palindrome Partitioning Leetcode Solution134
937Daily Temperatures Leetcode Solution134
938Dividing Array into Pairs With Sum Divisible by K134
939Remove Duplicates from Sorted List II LeetCode Solution133
940Pattern Occurrences using Stack133
941Analyze User Website Visit Pattern LeetCode Solution133
942Median of Two Sorted Arrays133
943Time Based Key-Value Store LeetCode Solution133
944Construct BST from its given Level Order Traversal133
945Maximum Frequency Stack Leetcode Solution133
946Merging Intervals133
947Longest Palindromic Subsequence133
948Can Make Arithmetic Progression From Sequence Leetcode Solution133
949Check if any two intervals overlap among a given set of intervals133
950Stone Game II Leetcode133
951Binary array after M range toggle operations133
952Three Consecutive Odds Leetcode Solution133
953Strongly Connected Component133
954Number of Distinct Islands Leetcode Solution133
955Maximize Sum of Array after K Negations Leetcode Solution133
956Iterative Postorder Traversal Using Two Stacks132
957Shuffle 2n integers as without using extra space132
958Binary Tree Longest Consecutive Sequence LeetCode Solution132
959Split Array Into Consecutive Subsequences132
960Create Maximum Number132
961Newman-Conway Sequence132
9623 Sum132
963All Unique Triplets that Sum up to a Given Value132
964Palindrome Partitioning132
965Depth First Search (DFS) for a Graph132
966Symmetric Tree132
967Binary Search Tree Delete Operation131
968Breadth First Search (BFS) for a Graph131
969Word Break131
970Intersection of Two Linked Lists LeetCode Solution131
971Length of Longest Fibonacci Subsequence131
972Difference Array | Range update query in O(1)131
973Count Submatrices With All Ones LeetCode Solution131
974Segment Tree131
975Minimum Height Trees LeetCode Solution131
976Climbing stairs131
977Largest Substring Between Two Equal Characters Leetcode Solution131
978My Calendar I LeetCode Solution131
979Sign of the Product of an Array LeetCode Solution130
980Reverse Nodes in K-Group130
981Maximum Product Subarray130
982Count pair with Given Sum130
983Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
984Find the Difference Leetcode Solution130
985Sliding Window Maximum130
986Find postorder traversal of BST from preorder traversal130
987Maximum subsequence sum such that no three are consecutive130
988Find Maximum of Minimum for Every Window Size in a Given Array130
989Minesweeper LeetCode Solution129
990Boundary Traversal of binary tree129
991Valid Boomerang Leetcode Solution129
992Count Primes in Ranges129
993Largest divisible pairs subset129
994Asteroid Collision LeetCode Solution129
995Count subarrays where second highest lie before highest129
996Height of a generic tree from parent array129
997Insertion in a Binary Tree129
998Serialize and Deserialize Binary Tree129
999The Painter’s Partition Problem129
1000Level Order Traversal of Binary Tree129
1001Product of Array Except Self LeetCode Solution128
1002Find Duplicate Subtrees128
1003Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1004Longest Nice Substring LeetCode Solution128
1005Kth Smallest Element in a BST Leetcode Solution128
1006Friends Of Appropriate Ages LeetCode Solution128
1007Find the First Circular Tour that visits all the Petrol Pumps128
1008Collect maximum points in a grid using two traversals128
1009Number Of Longest Increasing Subsequence128
1010Unique Paths II128
1011Maximum Length of Repeated Subarray128
1012Rearrange array such that even positioned are greater than odd128
1013Compute nCr % p128
1014Find number of pairs in an array such that their XOR is 0128
1015First missing positive127
1016Construction of Longest Increasing Subsequence (N log N)127
1017Make The String Great Leetcode Solution127
1018Partition Equal Subset Sum127
1019Scramble String LeetCode Solution127
1020Advantages of BST over Hash Table127
1021Level order traversal using two Queues127
1022Ugly Numbers127
1023Build an Array With Stack Operations Leetcode Solution127
1024Construct Binary Tree from given Parent Array representation127
1025Graph Valid Tree LeetCode Solution127
1026The Maze III LeetCode Solution127
1027Binary Search Tree127
1028Next Greater Element III LeetCode Solution127
1029String Matching in an Array Leetcode Solution127
1030Shortest Completing Word Leetcode Solution127
1031Maximum length subsequence with difference between adjacent elements as either 0 or 1126
1032Largest Number Leetcode Solution126
1033Kill Process LeetCode Solution126
1034Balanced Binary Tree126
1035Design Hit Counter LeetCode Solution126
1036Longest subsequence such that difference between adjacents is one126
1037Boolean Parenthesization Problem126
1038Maximum Number of Ways to Partition an Array LeetCode Solution126
1039Double the first element and move zero to end126
1040Number of palindromic paths in a matrix126
1041Implement Trie (Prefix Tree) Leetcode Solution126
1042Morris Inorder Traversal126
1043Maximum weight transformation of a given string126
1044Iterative Depth First Traversal of Graph125
1045Invalid Transactions LeetCode Solution125
1046K Closest Points to Origin Leetcode Solution125
1047Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’125
1048Validate Binary Search Tree125
1049Find whether a subarray is in form of a mountain or not125
1050Path Sum II LeetCode Solution125
1051Minimum Index Sum of Two Lists125
1052Maximum Sum of 3 Non-Overlapping Subarrays125
1053Minimum Size Subarray Sum125
1054Lowest Common Ancestor125
1055Maximum Product of Indexes of Next Greater on Left and Right125
1056Employee Importance LeetCode Solution124
1057Defanging an IP Address LeetCode Solution124
1058Kth Smallest Element in a Sorted Matrix LeetCode Solution124
1059Find Peak Element124
1060Ugly Number II LeetCode Solution124
1061Find a Peak Element II LeetCode Solution124
1062Move all negative elements to end in order with extra space allowed124
1063Available Captures for Rook Leetcode Solution124
1064Custom Sort String Leetcode Solution124
1065Regular Expression Matching Regular Expression Matching LeetCode Solution124
1066Bitwise AND of Numbers Range LeetCode Solution124
1067Add two numbers124
1068Largest BST Subtree LeetCode Solution123
1069Types of Binary Tree123
1070Count minimum steps to get the given desired array123
1071Binary Tree Right Side View LeetCode Solution123
1072Rearrange array such that even index elements are smaller and odd index elements are greater123
1073Super Ugly Number123
1074Recover Binary Search Tree Leetcode Solution123
1075Day of the Year Leetcode Solution123
1076Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution123
1077Remove Duplicates from Sorted Array II Leetcode Solution123
1078Smallest Common Region Leetcode Solution122
1079Number of Closed Islands Leetcode Solution122
1080Print all triplets in sorted array that form AP122
1081Print Next Greater Number of Q queries122
1082Path Sum122
1083Populating Next Right Pointers in Each Node Leetcode Solution122
1084Maximum difference between frequency of two elements such that element having greater frequency is also greater122
1085Search in Sorted Rotated Array122
1086Number of Students Doing Homework at a Given Time Leetcode Solution122
1087Number of siblings of a given Node in n-ary Tree122
1088Count pairs from two sorted arrays whose sum is equal to a given value x122
1089Binary Tree Data Structure122
1090Find the minimum distance between two numbers122
1091Divisible Pairs Counting122
1092Find Smallest Range Containing Elements from k Lists122
1093Generate Parentheses Leetcode Solution121
1094Clone a Binary Tree with Random Pointers121
1095Longest Bitonic Subsequence121
1096Serialize and Deserialize Binary Tree LeetCode Solution121
1097Combination Sum IV LeetCode Solution121
1098Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1099Remove Palindromic Subsequences Leetcode Solution121
1100Constant time range add operation on an array121
1101Root to Leaf path with target sum Leetcode Solutions121
1102Print Right View of a Binary Tree120
1103Bottom View of a Binary Tree120
1104Write Code to Determine if Two Trees are Identical120
1105Subarrays with K Different Integers Leetcode Solution120
1106Remove duplicates from sorted array120
1107Third Maximum Number Leetcode Solution120
1108Maximize Distance to Closest Person LeetCode Solution120
1109Distinct Subsequences120
1110Convert BST into a Min-Heap without using array120
1111Search Insert Position120
1112Valid Tic-Tac-Toe State LeetCode Solution120
1113Find maximum difference between nearest left and right smaller elements120
1114Level of Each node in a Tree from source node120
1115Cutting a Rod119
1116Palindrome Permutation LeetCode Solution119
1117Increasing Triplet Subsequence LeetCode Solution119
1118Next Permutation Leetcode Solution119
1119Minimum sum of squares of character counts in a given string after removing k characters119
1120Count Largest Group Leetcode Solution119
1121Find Three Element From Different Three Arrays Such That a + b + c = sum119
1122Mean of Array After Removing Some Elements Leetcode Solution118
1123Products of ranges in an array118
1124Topological Sorting118
1125Consecutive Characters LeetCode Solution118
1126Iterative method to find ancestors of a given binary tree118
1127Maximum Product Subarray118
1128Cells with Odd Values in a Matrix LeetCode Solution118
1129Moser-de Bruijn Sequence118
1130Reformat The String Leetcode Solution118
1131Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1132Maximum Binary Tree118
1133Print modified array after executing the commands of addition and subtraction118
1134Thousand Separator Leetcode Solution118
1135Minimum Score Triangulation of Polygon Leetcode Solution118
1136Prime Palindrome LeetCode Solution118
1137Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1138Golomb sequence117
1139Search an Element in Sorted Rotated Array117
1140Longest Increasing Consecutive Subsequence117
1141Construct K Palindrome Strings LeetCode Solution117
1142Sum of Even Numbers After Queries117
1143Minimum Absolute Difference in BST Leetcode Solution117
1144Maximum Product of Splitted Binary Tree LeetCode Solution116
1145Check Array Formation Through Concatenation Leetcode Solution116
1146K maximum sums of overlapping contiguous sub-arrays116
1147Red-Black Tree Introduction116
1148Swap Nodes In Pairs116
1149Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution116
1150Transform a BST to Greater sum Tree116
1151Find maximum length Snake sequence116
1152Count even length binary sequences with same sum of first and second half bits116
1153Factorial Trailing Zeroes LeetCode Solution116
1154Kth Smallest Number in Multiplication Table Leetcode Solution116
1155Binary Tree to Binary Search Tree Conversion116
1156Queries for Number of Distinct Elements in a Subarray116
1157K’th Largest element in BST using constant extra space115
1158Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1159Delete Nodes and Return Forest Leetcode Solution115
1160Merge two BSTs with limited extra space115
1161Possible Bipartition LeetCode Solution115
1162Subset Sum Problem in O(sum) space115
1163Decision Tree115
1164Maximize sum of consecutive differences in a circular array115
1165Rotate Array115
1166Priority Queue115
1167Palindromic Substrings Leetcode Solution115
1168Closest Binary Search Tree Value Leetcode Solution114
1169Search Suggestions System LeetCode Solution114
1170Minimum Sideway Jumps LeetCode Solution114
1171Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1172Find the smallest binary digit multiple of given number114
1173Number of Orders in the Backlog Leetcode Solution113
1174First Bad Version113
1175Given a binary tree, how do you remove all the half nodes?113
1176Minimum Cost to Move Chips to The Same Position LeetCode Solution113
1177Find a sorted subsequence of size 3 in linear time113
1178Count Pairs Whose Products Exist in Array113
1179Diameter of N-Ary Tree LeetCode Solution113
1180Bus Routes Leetcode Solution113
1181Decrease Elements To Make Array Zigzag LeetCode Solution112
1182Longest Repeated Subsequence112
1183Reverse a Path in BST using Queue112
1184Maximum number of segments of lengths a, b and c112
1185Contiguous Array LeetCode Solution112
1186Web Crawler LeetCode Solution112
1187Champagne Tower LeetCode Solution111
1188Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1189Find Largest Value in Each Tree Row LeetCode Solution111
1190Lowest Common Ancestor in Binary Search Tree111
1191Swapping Nodes in a Linked List Leetcode Solution111
1192Matchsticks to Square Leetcode Solution111
1193Queue Reconstruction by Height111
1194How to print maximum number of A’s using given four keys110
1195Reformat Date LeetCode Solution110
1196New 21 Game110
1197Valid Triangle Number110
1198Moving Stones Until Consecutive Leetcode Solution110
1199Closest Leaf in a Binary Tree LeetCode Solution110
1200Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution110
1201Maximum sum bitonic subarray110
1202Maximum Depth Of Binary Tree109
1203Replace two consecutive equal values with one greater109
1204Sum of Left Leaves LeetCode Solution109
1205Valid Perfect Square LeetCode Solution109
1206Range Sum Query using Sparse Table109
1207Kth Smallest Element in a BST109
1208Print modified array after multiple array range increment operations109
1209Minimum Moves to Equal Array Elements LeetCode Solution109
1210The kth Factor of n Leetcode Solution109
1211Write a function to get the intersection point of two Linked Lists109
1212Graph and its representation109
1213Array Queries for multiply replacements and product109
1214Maximum sum of pairs with specific difference109
1215Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1216Maximum sum of a path in a Right Number Triangle108
1217Concatenation of Array LeetCode Solution108
1218Design Skiplist LeetCode Solution108
1219Maximum Value at a Given Index in a Bounded Array LeetCode Solution108
1220Guess The Word108
1221Path Crossing Leetcode Solution108
1222Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution108
1223Arithmetic Slices II – Subsequence LeetCode Solution108
1224Range Queries for Longest Correct Bracket Subsequence108
1225Merge Sort108
1226BST to a Tree with Sum of all Smaller Keys108
1227Check if all levels of two Binary Tree are anagrams or not107
1228Check if each internal node of a BST has exactly one child107
1229Lowest Common Ancestor of a Binary Tree Leetcode Solution107
1230Queries on Probability of Even or Odd Number in given Ranges107
1231Check for Identical BSTs without building the trees107
1232Flatten 2D Vector LeetCode Solution107
1233Integer Break LeetCode Solution107
1234Longest Common Prefix Using Word by Word Matching106
1235Graph Cloning106
1236Power of Two106
1237Perfect Squares LeetCode Solution106
1238Count Subsets Having Distinct Even Numbers106
1239Divide Two Integers Leetcode Solution106
1240Check Completeness of a Binary Tree LeetCode Solution106
1241Mean of range in array105
1242Largest Plus Sign Leetcode Solution105
1243Maximize Elements Using Another Array105
1244Symmetric Tree LeetCode Solution Leetcode Solution105
1245Find minimum number of merge operations to make an array palindrome105
1246Sliding Window Median Leetcode Solution105
1247Print n terms of Newman-Conway Sequence105
1248Maximum Array from Two given Arrays Keeping Order Same105
1249Bold Words in String LeetCode Solution105
1250Contiguous Array104
1251Verify Preorder Serialization of a Binary Tree104
1252LRU Cache Leetcode Solution104
1253Find k-th smallest element in BST (Order Statistics in BST)104
1254Missing Number104
1255Find Minimum in Rotated Sorted Array II LeetCode Solution104
1256Print Ancestors of a Given Binary Tree Node Without Recursion103
1257Next greater element103
1258Check If a String Can Break Another String Leetcode Solution103
1259Parallel Courses II LeetCode Solution103
1260Smallest Range II Leetcode Solution102
1261Excel Sheet Column Title LeetCode Solution102
1262Minimum Remove to Make Valid Parentheses LeetCode Solution102
1263Merge k Sorted Lists Leetcode Solution102
1264Maximum Product Subarray102
1265Count and Toggle Queries on a Binary Array101
1266Image Overlap LeetCode Solution101
1267Minimum Time to Collect All Apples in a Tree LeetCode Solution101
1268Check if two nodes are on the same path in a Tree100
1269Check in binary array the number represented by a subarray is odd or even100
1270Orderly Queue LeetCode Solution100
1271Palindrome Partitioning100
1272Koko Eating Bananas LeetCode Solution99
1273Merge Sorted Array98
1274Check if X can give change to every person in the Queue98
1275Min Cost Climbing Stairs LeetCode Solution98
1276Newman–Shanks–Williams prime98
1277Number of elements less than or equal to a given number in a given subarray97
1278Peeking Iterator LeetCode Solution97
1279Largest Submatrix With Rearrangements LeetCode Solution97
1280Different Ways to Add Parentheses Leetcode Solution97
1281Maximum Sum Increasing Subsequence96
1282Range Minimum Query (Square Root Decomposition and Sparse Table)95
1283Number of indexes with equal elements in given range95
1284Find maximum average subarray of k length95
1285Queries for Decimal Values of Subarrays of a Binary Array94
1286Longest Substring Without Repeating Characters Leetcode Solution93
1287Maximum product of an increasing subsequence93
1288Array Nesting Leetcode Solution93
1289Arranging Coins Leetcode Solution92
1290Binary Tree to Binary Search Tree Conversion using STL set92
1291Check given array of size n can represent BST of n levels or not92
1292Encoded String With Shortest Length LeetCode Solution91
1293Minimum Number of People to Teach LeetCode Solution91
1294Minimum Total Space Wasted With K Resizing Operations LeetCode Solution90
1295Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1296Random Pick Index LeetCode Solution90
1297Convert a BST to a Binary Tree such that sum of all greater keys is added to every key89
1298Queries on XOR of greatest odd divisor of the range89
1299Reach a Number LeetCode Solution89
1300Convert to Base -2 LeetCode Solution89
1301Find the Winner of the Circular Game LeetCode Solution88
1302Jump Game IV LeetCode Solution87
1303Insert Delete GetRandom O(1) Leetcode Solution86
1304Add Two Numbers II Leetcode Solution86
1305Palindrome Number LeetCode Solution85
1306Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution83
1307Design Underground System Leetcode Solution83
1308Print Maximum Length Chain of Pairs83
1309Vertical Order Traversal of Binary Tree LeetCode Solution82
1310Continuous Subarray Sum LeetCode Solution81
1311Detect Capital Leetcode Solution80
1312Design A Leaderboard Leetcode Solution78
1313Substring with Concatenation of All Words Leetcode Solution74
1314Minimum Swaps to Group All 1’s Together Leetcode Solution74
1315Minimum Path Sum Leetcode Solution72
1316Top K Frequent Elements LeetCode Solution71
1317Odd Even Linked List Leetcode Solution70
1318Binary Tree Inorder Traversal LeetCode Solution70
1319Maximum Population Year LeetCode Solution69
1320Count Sub Islands LeetCode Solution69
1321Shortest Unsorted Continuous Subarray LeetCode Solution68
1322Shifting Letters LeetCode Solution68
1323Best Meeting Point LeetCode Solution68
1324Find the Town Judge LeetCode Solution68
1325Decode String Leetcode Solution67
1326Longest Common Subsequence LeetCode Solution67
1327Sum Root to Leaf Numbers LeetCode Solution66
1328Find the Town Judge LeetCode Solution64
1329Design Add and Search Words Data Structure LeetCode Solution64
1330Maximum Population Year LeetCode Solution62
1331Rectangle Overlap LeetCode Solution61
1332Score of Parenthesis LeetCode Solution59
1333Stone Game IV LeetCode Solution59
1334Insert into a Sorted Circular Linked List LeetCode Solution59
1335Range Sum Query 2D – Immutable LeetCode Solution58
1336Flatten Binary Tree to Linked List LeetCode Solution58
1337Valid Triangle Number LeetCode Solution57
1338Is Graph Bipartite? LeetCode Solution56
1339Reveal Cards In Increasing Order Leetcode Solution51
1340Divide Chocolate LeetCode Solution47
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution38
1342Reverse Integer Leetcode Solution35
1343Sort Colors LeetCode Solution34
1344Range Sum of BST LeetCode Solution34
1345Find K Closest Elements LeetCode Solution32
1346Excel Sheet Column Number LeetCode Solution29
1347Rotate String LeetCode Solution28
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution27
Translate »