Reveal Cards In Increasing Order Leetcode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon
Array Deque SortingViews 53

Problem Statement

The Reveal Cards In Increasing Order Leetcode Solution – Given an integer Array named “deck”. In this deck of cards, every card has a unique integer. The integer on the i card is deck[i].  Order the deck in any order and all the cards start face down (unrevealed) in one deck.

Now, Follow the steps repeatedly until all cards are revealed:

  1. Take the top card of the deck, reveal it, and take it out of the deck.
  2. If there are still cards in the deck then put the next top card of the deck at the bottom of the deck.
  3. If there are still unrevealed cards, go back to step 1. Otherwise, stop.

Return an ordering of the deck that would reveal the cards in increasing order.

Note that the first entry in the answer is considered to be the top of the deck.

Example

Input:
deck = [17,13,11,2,3,5,7]
Output: 
[2,13,3,11,5,17,7]

 Explanation:

Input: deck = [17,13,11,2,3,5,7]

Output: [2,13,3,11,5,17,7]

Given deck is in the order [17,13,11,2,3,5,7] but the order doesn’t matter at all because we can reorder it. So we need to reorder it such that the cards reveal in increasing order.

After reordering, it will be [2,13,3,11,5,17,7] where 2 is in the top.

bottom

Reveal Cards In Increasing Order Leetcode SolutionPin

top

1. We reveal 2, and move 13 to the bottom. The deck is now [3,11,5,17,7,13].

 

bottom

Reveal Cards In Increasing Order Leetcode SolutionPin

top

2. We reveal 3, and move 11 to the bottom. The deck is now [5,17,7,13,11].

 

bottom

Reveal Cards In Increasing Order Leetcode SolutionPin

top

3. We reveal 5, and move 17 to the bottom. The deck is now [7,13,11,17].

 

Reveal Cards In Increasing Order Leetcode SolutionPin

4. We reveal 7, and move 13 to the bottom. The deck is now [11,17,13].

 

Reveal Cards In Increasing Order Leetcode SolutionPin

5. We reveal 11, and move 17 to the bottom. The deck is now [13,17].

 

Reveal Cards In Increasing Order Leetcode SolutionPin6. We reveal 13, and move 17 to the bottom. The deck is now [17].

 

Reveal Cards In Increasing Order Leetcode Solution7. We reveal 17.

 

Example 2:

Input: deck = [1,1000]
Output: [1,1000]

Approach

Idea:

As we want to reveal the cards in increasing order so we need to put the smallest card at index 0, then the second smallest card at index 2, the third smallest card at index 4 so on.

  1. We need to sort the given array in decreasing order.
  2. Then we take a deque to arrange the cards in such a way so that when we reveal them they are all in increasing order and a result vector to store the final answer.
  3. For that First, push the largest element of the given array in the deque from the back.
  4. Then we need to iterate in the array, pop the last element from the deque, and push it in the front of the deque, after that push the array element in the front of the deque.
  5. Finally, we take the front elements of the deque and push them into our result vector one by one.
  6. Return the result vector.

 

Code

C++ Program of  Reveal Cards In Increasing Order Leetcode Solution:

class Solution {
public:
    vector<int> deckRevealedIncreasing(vector<int>& deck) {
        vector<int> res;
        sort(deck.begin(), deck.end());
        reverse(deck.begin(), deck.end());
        deque<int> dq;
        dq.push_back(deck[0]);
        for (int i = 1; i < deck.size(); i++) {
            dq.push_front(dq.back());
            dq.pop_back();
            dq.push_front(deck[i]);
        }
        while(!dq.empty()){
            int value=dq.front();
            dq.pop_front();
            res.push_back(value);
        }
        return res;
    }
};

Java Program of  Reveal Cards In Increasing Order Leetcode Solution:

class Solution {
    
    public int[] deckRevealedIncreasing(int[] deck) {
        int N=deck.length, j=0;
        int[] res = new int[N];
        Deque<Integer> dq = new LinkedList();
        Arrays.sort(deck);
        dq.add(deck[N-1]);
        for (int i = N-2; i >= 0; i--){
            dq.addFirst(dq.pollLast());
            dq.addFirst(deck[i]);
        }
            
        while(!dq.isEmpty()) {
            int value = dq.pollFirst();
            res[j]=value;
            j++;
        }

        return res;
    }
}

 

Complexity Analysis for Reveal Cards In Increasing Order Leetcode Solution:

Time Complexity:

The time complexity for this code is O(NlogN) + O(N).  As O(NlogN) is asymptotically larger, so we can say that the time complexity is O(NlogN).  O(NlogN) is taken to sort the given array and O(N) is taken to traverse the array and store the result.

Space Complexity:

The space complexity of the above code is O(2N) because of the result array and the deque which we used to solve the problem.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2818
2Java program to find the number of Nodes in a Binary Tree2500
3Reverse a string without affecting special characters2458
4Delete a node of a linked list at given position1973
5Palindrome using Recursion1779
6Insert nodes in a linked list in a sorted way (Ascending Order)1661
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1631
9Write a program to print all permutations of a given string1604
10Find Minimum Distance Between Two Numbers in an Array1471
11Create a Doubly Linked List1444
12Quick Sort1416
13Reverse an Array1412
14Smallest window in a string containing all characters of another string1394
15Find a Triplet That Sum to a Given Value1356
16Recursively remove all adjacent duplicates1353
17First Repeating Element1337
18Arrange Even and Odd number such that Odd comes after Even1320
19Sum of numbers in String1315
20Smallest Positive Number Missing in an Unsorted Array1280
21Check if the Elements of an Array are Consecutive1252
22Detect a loop in the Linked List1236
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1214
25Subarray with Given Sum1212
26Print all Possible Combinations of R Elements in a given Array of size N1203
27Recursive function to do substring search1196
28Find the Maximum Repeating Number in Array1155
29Binary Tree Level order traversal in Java1123
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1102
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1067
34Find Leaders in an Array1060
35Swap nodes in the linked list1034
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II993
38Find the second most frequent character984
39Given a string find its first non-repeating character966
40Find Triplet in Array With a Given Sum964
41Given a sorted array and a number x, find the pair in array whose sum is closest to x952
42Total number of occurrences of a given item in the linked list951
43A Program to check if strings are rotations of each other or not943
44Print all possible words from phone digits932
45Find the Missing Number924
46Rearrange Positive and Negative Numbers Alternatively in Array917
47Longest Palindromic Substring905
48Segregate even and odd nodes in a linked list883
49Print Longest common subsequence881
50Union and Intersection of Two Linked Lists870
51Transform one string to another using minimum number of given operations867
52Rearrange given Array in Maximum Minimum Form844
53Check rearranged string can form a palindrome842
54Count Possible Triangles819
55Iterative Implementation of Quick Sort814
56Multiplication of Two Matrices801
57Check if the linked list is palindrome795
58Count of Triplets With Sum Less than Given Value790
59Rotate a Linked List789
60Stock Buy Sell to Maximize Profit786
61Concatenation of two strings758
62Tug of War758
63Count Number of Substrings with K Distinct Character’s758
64Print all duplicates in the input string753
65Find Nearest Greater and Smaller Element744
66Find Pythagorean Triplets from Array736
67The Celebrity Problem736
68Reverse String Without Temporary Variable733
69Remove ‘b’ and ‘ac’ from a given string728
70Find all Common Elements in Given Three Sorted Arrays727
71Remove all duplicates in an unsorted linked list708
72Find the Row with Maximum Number of 1’s703
73Find the Peak Element from an Array697
74Find the subarray whose sum is equal to a given number X695
75Remove Minimum Characters so that Two Strings Become Anagrams689
76Find Smallest Missing Number in a Sorted Array687
77Insertion Sort686
78A Product Array Puzzle684
79Addition of Two Matrices682
80Implement Two Stacks in an Array675
81Generate all Binary Strings Without Consecutive 1’s671
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II658
84Lexicographic rank of string652
85Multiplication of Previous and Next643
86Check if Two given Matrices are Identical641
87Subtraction of Two Matrices631
88Merge K Sorted Arrays and Print Sorted Output631
89Move All the Zeros to the End of the Given Array627
90Form Minimum Number from Given Sequence of D’s and I’s622
91Divide a string in N equal parts622
92Online Algorithm for Checking Palindrome in a Stream622
93Check whether two strings are anagram of each other614
94Maximum Circular Subarray Sum612
95Remove recurring digits in a given number608
96Sort a linked list that is sorted alternating ascending and descending607
97Sort a stack using a temporary stack605
98Find the Minimum Element in a Sorted and Rotated Array604
99Move last element of the Linked List at first place601
100Subarray and Subsequence599
101First Circular Tour to Visit all the Petrol Bunks597
102Largest Subarray with Equal Number of 0’s and 1’s596
103Compare two strings(linked lists)591
104Flattening a linked list590
105Maximum Element in an Array which is Increasing and then Decreasing589
106Palindrome Permutations of a String583
107Elements Appear more than N/K times in Array581
108Majority Element575
109Run length encoding574
110Minimum insertions to form a shortest palindrome573
111Print all permutations with repetition572
112Palindromes in a given range570
113Pangram Checking568
114Merge a linked list into another at alternate positions567
115Minimum Characters to be Added at Front to Make String Palindrome563
116Remove all duplicates in a sorted linked list562
117Rearrange a given linked list in-place562
118Most repeating character in a string558
119Minimum number of Merge Operations to make an Array Palindrome558
120Rotate string to get lexicographically minimum string557
121Repeated Subsequence of Length Two or More554
122Print all anagrams together in a sequence of words551
123Reorder an Array According to the Given Indexes550
124Pancake Sorting Problem540
125Merge Overlapping Intervals II538
126Two Sum Leetcode Solution537
127Clone a Linked List with next and random pointer536
128Size of The Subarray With Maximum Sum527
129Transpose of a Matrix524
130Remove Extra Spaces from a String520
131Removing Spaces from a String using stringstream520
132Smallest Palindrome after Replacement518
133Check if a given string is a rotation of a palindrome517
134Remove duplicates from a string517
135Partition Problem516
136Longest Palindrome can be Formed by Removing or Rearranging Characters513
137Maximum Sum Increasing Subsequence512
138Check whether Strings are K Distance Apart or Not502
139Generate all Binary Strings from Given Pattern501
140Delete Last Occurrence500
141Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized499
142Length of Longest valid Substring499
143Insert Node in the Sorted Linked List498
1443Sum Leetcode Solution497
145Check if Two given Strings are Isomorphic to each other494
146Maximum difference between two elements such as larger element comes after smaller486
147Given string is interleaving of two other strings or not482
148Program to Toggle all Characters in a String482
149Count Minimum Steps to Get the given Array479
150Number of Smaller Elements on Right Side477
151Merge sort better than quick sort for linked lists477
152Find Pair with Given Difference472
153Check if all Rows of a Matrix are Circular Rotations of Each Other471
154Check length of a String is Equal to the Number Appended at its Last469
155Longest Common Prefix using Divide and Conquer468
156Find nth node of the Linked list from the end466
157Find a Fixed Point in a Given Array463
158Sort 0s 1s and 2s in an Array457
159Print all interleavings of given two strings457
160Compare Two Version Numbers455
161Reverse words in a given string453
162Merge two sorted linked lists such that merged list is in reverse order453
163Find the Subarray of given length with Least Average452
164Reorder Array Using Given Indexes451
165Median of Two Sorted Arrays LeetCode Solution449
166Split linked list using alternate nodes449
167Print Reverse of a string (Recursion)448
168Find K Length Subarray of Maximum Average438
169Print string of odd length in ‘X’ format435
170Find Element Using Binary Search in Sorted Array433
171Swap Kth Node from beginning with Kth Node from End430
172Print all Palindromic Partitions of a String429
173Find Duplicates in an Array in Most Efficient Way427
174print all palindromic partitions420
175Maximum Length of Chain Pairs416
176Flatten a multilevel linked list415
177Shortest Superstring Problem414
178Check if String Follows Order of Characters by a Pattern or not412
179Sorting a K Sorted Array408
180Sort a String According to Another String404
181Longest Span with same Sum in two Binary Arrays II398
182Reverse a Linked List in groups395
183Find a Sorted Subsequence of size 3393
184Program to add two binary digits390
185Recursively print all the sentences that can be formed from list of word lists388
186Find the two Numbers with Odd Occurrences in an Unsorted Array386
187Longest Common Prefix Using Binary Search II385
188Reverse a Singly Linked List (Iterative/Non-Recursive)381
189Rearrange a linked list in Zig-Zag377
190Kth Non-repeating Character377
191Check if String can Become Empty by Recursively Deleting given Substring377
192Caesar Cipher377
193Pancake Sorting373
194Rotate Image by 90 degrees371
195Longest Common Prefix Word by Word Matching369
196Perfect Reversible String365
197Permutations of a Given String Using STL364
198Merging Two Sorted Arrays362
199Increasing Subsequence of Length three with Maximum Product361
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes361
201Find the point where a monotonically increasing function becomes positive first time358
2021`s and 2`s complement of binary number357
203Sort a linked list with 0s, 1s and 2s357
204Find First non-repeating character in a string356
205Four Elements that Sum to Given353
206List items containing all characters of a given word351
207Delete N nodes after M351
208Count Number of Occurrences in a Sorted Array349
209Longest Common Prefix using Character by Character Matching348
210Palindrome string (number)342
211Split a string340
212Minimum Characters to be Removed to Make a Binary String Alternate339
213Check if a Linked list of Strings form a Palindrome333
214Recursive Implementation of atoi()332
215Convert a String that is Repetition of a Substring of Length K330
216Print All Distinct Elements of the Array330
217Sorting the array of strings330
218Maximum occurring character in a string326
219Even Substring Count325
220Find the first Repeating Number in a Given Array325
221Valid Parentheses LeetCode Solution325
222Reverse a singly linked list recursively324
223Can we reverse a linked list in less than O(n) time ?323
224Binary Tree to Doubly linked list323
225Print Shortest Path to Print a String on Screen322
226Nth Character in Concatenated Decimal String318
227Convert string1 to string2 in one edit318
228Maximum Subarray Leetcode Solution317
229Sort Elements by Frequency II317
230Reverse a String using Stack316
231Lower Case To Upper Case314
232wildcard character matching314
233Count the number of words311
234Merge Two Sorted Arrays310
235Find the Lost Element From a Duplicated Array310
236Split Four Distinct Strings308
237Find middle of the Linked List306
238Longest Common Subsequence with Permutations304
239Count the Pairs at Same Distance as in English Alphabets301
240Matrix Chain Multiplication using Dynamic Programming295
241Next Greater Element in an Array294
242Palindrome Permutation287
243Find Nth Node285
244Searching a node in a Binary Search Tree283
245Roman to Integer Leetcode Solution281
246Find All Pairs With a Given Difference281
247Triplet from three linked lists with given sum280
248Delete a Tree279
249Print all Possible Ways to Break a String in Bracket Form277
250Reverse a String276
251String(represents an integer) to value276
252Reverse Bits274
253Delete a node under given conditions272
254Binary Tree272
255Change Gender of a given String271
256Word Search Leetcode Solution271
257Sort an array of strings270
258How to Efficiently Implement k Stacks in a Single Array?268
259Count Pairs With Given Sum267
260Number of sub-strings which recursively add up to 9267
261Longest Common Extension266
262First non Repeating Element265
263Remove middle points in a linked list of line segments265
264Meeting Rooms II LeetCode Solution264
265Repeated Substring Pattern263
266Remove spaces from a string262
267Toeplitz Matrix262
268Longest Palindromic Substring LeetCode Solution262
269Move all negative elements to one side of array260
270Shuffle a given Array258
271Min Stack255
272N queen problem255
273Find, second, frequent, character251
274Number of Islands LeetCode Solution250
275House Robber Leetcode Solution250
276Dijkstra Algorithm250
277Cuckoo sequence program248
278Most Frequent Element in an Array247
279Max stack247
280Clone a linked list with next and random pointer (Hashing)246
281Search Insert Position Leetcode Solution245
282Minimize the maximum difference between the heights245
283Sort linked which is sorted on absolute values244
284Expression Evaluation244
285Valid Palindrome Leetcode Solution241
286Plus One Leetcode Solution241
287Subset Leetcode241
288Fibonacci numbers240
289KMP Algorithm240
290Word Search239
291Evaluation of Postfix Expression238
292Sudoku Solver238
293How to Delete a Linked List238
294Reverse words in a string237
295Min Stack Leetcode Solution237
296Combination Sum Leetcode Solution233
297Number Of 1 bits232
298Subarray with 0 sum230
299Merge Sorted Arrays Leetcode Solution230
300Sqrt(x) Leetcode Solution230
301Rabin Karp Algorithm228
302Set Matrix Zeroes228
303Reversing a Queue227
304Backspace String Compare227
305Pair of Positive Negative Values in an Array227
306Contains Duplicate II Leetcode Solution225
307Combination Sum224
308Integer to Roman Leetcode Solution223
309Tower Of Hanoi223
310Common elements in all rows of a given matrix222
311Product of array except self221
312Delete middle element of a stack220
313String Compression220
314Intersection of Two Arrays II Leetcode Solution220
315Minimum swaps required to bring all elements less than or equal to k together218
316Pascal Triangle Leetcode218
317Reverse individual words218
318Count subarrays with equal number of 1’s and 0’s218
319Add Binary Leetcode Solution217
320Segregate even and odd numbers216
321Find Top K (or Most Frequent) Numbers in a Stream215
322Single Number Leetcode Solution215
323Construct Binary Tree from Given Inorder and Preorder Traversals215
324Second Most Repeated Word in a Sequence215
325Pow(x, n) Leetcode Solution215
326Palindrome Linked List Leetcode Solution214
327Bellman Ford Algorithm214
328Sliding Window Technique214
329Count Odd Numbers in an Interval Range Leetcode Solution213
330Arithmetic Expression Evaluation213
331Next Permutation213
332Count of index pairs with equal elements in an array212
333Design a stack that supports getMin() in O(1) time and O(1) extra space212
334Maximum Number of Balloons Leetcode Solution212
335Implementation of Deque using Doubly Linked List211
336Contains Duplicate210
337Sort elements by frequency210
338Minimum Value to Get Positive Step by Step Sum Leetcode Solution210
339Kruskal Algorithm210
340Page Replacement Algorithms in Operating Systems210
341Postfix to Infix Conversion209
342Find sum of non-repeating elements (distinct) elements in an array209
343K-th Smallest Element in a Sorted Matrix208
344Find Lucky Integer in an Array Leetcode Solution207
345Third Maximum Number Leetcode Solution207
346Longest Common Prefix Leetcode Solution207
347Find Numbers with Even Number of Digits Leetcode Solution206
348Sum of minimum and maximum elements of all subarrays of size k206
349Group Words With Same Set of Characters206
350Find the Town Judge Leetcode Solution206
351Majority Element Leetcode Solution206
352Permutations Leetcode Solution206
353Maximum Subarray206
354Convex Hull Algorithm206
355Longest Substring Without Repeating Characters LeetCode Solution205
356Minimum operation to make all elements equal in array204
357Count Primes Leetcode Solutions203
358Scramble String203
359First element occurring k times in an array203
360Sorting array using Stacks203
361Top K Frequent Words203
362Spiral Matrix LeetCode Solution203
363Smallest Subarray with k Distinct Numbers202
364Count subarrays having total distinct elements same as original array202
365Swap Nodes in Pairs Leetcode Solutions202
366Check if two arrays are equal or not201
367Evaluate Division201
368Merge Two Sorted Lists Leetcode Solutions200
369Given two unsorted arrays find all pairs whose sum is x200
370Power of Two Leetcode Solution200
371Minimum Path Sum199
372Special Number199
373Fizz Buzz Leetcode199
374Search in Rotated Sorted Array Leetcode Solution198
375Best Time to Buy and Sell Stock  II Leetcode Solution198
376Prefix to Infix Conversion198
377Reverse a Number Using Stack198
378Find duplicates in a given array when elements are not limited to a range197
379Group Anagrams197
380Number of Good Pairs Leetcode Solution197
381Pascal’s Triangle II Leetcode Solution197
382Leetcode Permutations196
383Reversing the First K elements of a Queue196
384Minimum Absolute Difference Leetcode Solution196
385Missing Number Leetcode Solution196
386Maximum possible difference of two subsets of an array196
387Running Sum of 1d Array Leetcode Solution195
388Find All Numbers Disappeared in an Array Leetcode Solution195
389Huffman Coding195
390Minimum Steps to reach target by a Knight195
391Maximum Distance Between two Occurrences of Same Element in Array195
392Matrix Diagonal Sum Leetcode Solution195
393House Robber II Leetcode Solution195
394Coin Change 2 Leetcode Solution194
395How to Implement Stack Using Priority Queue or Heap?193
396Single Number193
397Maximal Square193
398Top K Frequent Elements193
399Unique Paths Leetcode Solution193
400Check if Array Contains Contiguous Integers With Duplicates Allowed193
401Sorting using trivial hash function193
402Range Sum Query 2D – Immutable Leetcode Solution192
403Find The Duplicate Number192
404Sort Array by Increasing Frequency Leetcode Solution192
405Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution192
406Happy Number Leetcode Solution191
407How Many Numbers Are Smaller Than the Current Number Leetcode Solution191
408Subarray Sum Equals k190
409Reverse Vowels of a String Leetcode Solution190
410Find Number of Employees Under every Employee190
411Max Consecutive Ones Leetcode Solution190
412Smallest Element Repeated Exactly K Times190
413Subarray Sum Equals K LeetCode Solution190
414Expression Contains Redundant Bracket or Not190
415Find the Closest Palindrome number190
416Remove Duplicates from Sorted Array Leetcode Solution190
417Unique Paths190
418Find Winner on a Tic Tac Toe Game Leetcode Solution189
419Zigzag Conversion189
420Fibonacci Number LeetCode Solution189
421Decode String189
422Subset sum problem189
423Sort Integers by The Number of 1 Bit Leetcode Solution189
424Subtract the Product and Sum of Digits of an Integer Leetcode Solution189
425Cumulative Frequency of Count of Each Element in an Unsorted Array188
426Nth Catalan Number188
427Find Median from data Stream188
428Palindrome Substring Queries188
429Reverse Integer188
430Difference between highest and least frequencies in an array188
431Length of the largest subarray with contiguous elements188
432Check If N and Its Double Exist Leetcode Solution187
433LRU Cache Implementation187
434Delete a Node from linked list without head pointer187
435Implement Stack and Queue using Deque187
436Monotonic Array LeetCode Solution187
437Trapping Rain Water Leetcode Solution187
438Convert String To Int187
439Letter Case Permutation187
440Count Substrings with equal number of 0s, 1s and 2s187
441Subarrays with distinct elements186
442Print All Distinct Elements of a Given Integer Array186
443Shuffle the Array Leetcode Solution186
444Find top three repeated in array186
445The K Weakest Rows in a Matrix Leetcode Solution185
446Best Time to Buy and Sell Stock III Leetcode Solution185
447Capacity To Ship Packages Within D Days Leetcode Solution185
448Integer to English words185
449Find all pairs (a, b) in an array such that a % b = k185
450Sort a stack using recursion185
451Minimum Moves to Equal Array Elements Leetcode Solution185
452Bipartite Graph185
453Reverse Words in a String III LeetCode Solution185
454Maximum Depth of Binary Tree Leetcode Solution185
455Find the Duplicate Element184
456Find the first repeating element in an array of integers184
457Kth largest element in an Array Leetcode Solutions184
458Find Minimum In Rotated Sorted Array184
459Reverse a Stack Using Recursion184
460Merge Two Sorted Linked Lists183
461Excel Sheet Column Number Leetcode Solution183
462Count pairs from two linked lists whose sum is equal to a given value183
463Generate a String With Characters That Have Odd Counts Leetcode Solution183
464Prim’s Algorithm183
465Priority Queue Using Singly Linked List182
466Longest Common Subsequence182
467Iterative Tower of Hanoi182
468Sum of Subarray Ranges Leetcode Solution182
469Flood Fill LeetCode182
470Find the Difference Leetcode Solution182
471Floyd Warshall Algorithm182
472Sorting a Queue without Extra Space182
473Reverse a String182
474Find First and Last Position of Element in Sorted Array Leetcode Solution181
475Remove Minimum Number of Elements Such That no Common Element Exist in both Array181
476Find elements which are present in first array and not in second181
477Edit Distance181
478Concatenation of Array LeetCode Solution181
479Find Common Characters Leetcode Solution181
480Next Greater Element I Leetcode Solution181
481Count and Say180
482Merge Overlapping Intervals180
483Text Justification LeetCode Solution180
484Kth Largest Element in a Stream Leetcode Solution180
485Multiply Strings Leetcode Solution180
486Print all subarrays with 0 sum180
487Longest Common Prefix using Trie180
488Word Ladder LeetCode Solution180
489Fizz Buzz180
490MiniMax Algorithm180
491Degree of an array180
492Slowest Key Leetcode Solution179
493Target Sum179
494Number of Steps to Reduce a Number to Zero Leetcode Solution179
495Kids With the Greatest Number of Candies Leetcode Solution179
496Move Zeroes LeetCode Solution179
497Top View of Binary Tree179
498Balanced Binary Tree Leetcode Solution178
499Reverse a linked list178
500Valid Parenthesis String177
501Priority Queue in C++177
502Zigzag Conversion LeetCode Solution177
503Design Parking System Leetcode Solution177
504Longest subarray not having more than K distinct elements177
505Jump Game Leetcode Solution177
506Length of Last Word Leetcode Solution177
507Peak Index in a Mountain Array176
508Pair with given product176
509The Stock Span Problem176
510Find four elements that sum to a given value (Hashmap)176
511Shortest Palindrome176
512Max Area of Island176
513Count and Say Leetcode Solution176
514Intersection of Two Arrays176
515Koko Eating Bananas Leetcode Solution176
516Check if a given array contains duplicate elements within k distance from each other175
517Find missing elements of a range175
518Last Stone Weight175
519Postfix to Prefix Conversion175
520Mobile Numeric Keypad Problem175
521Prefix to Postfix Conversion175
522Find subarray with given sum (Handles Negative Numbers)175
523Shuffle String Leetcode Solution175
524Convert array into Zig-Zag fashion175
525Find N Unique Integers Sum up to Zero Leetcode Solution174
526Find any one of the multiple repeating elements in read only array174
527K-th Distinct Element in an Array174
528Smallest Subarray With all Occurrences of a Most Frequent Element174
529Relative Sort Array Leetcode Solution174
530Substring With Concatenation Of All Words174
531Find distinct elements common to all rows of a matrix174
532Count number of triplets with product equal to given number173
533Implementation of Deque using circular array173
534Implement a stack using single queue173
535Find Index of Closing Bracket for a Given Opening Bracket in an Expression173
536Longest Common Prefix using Sorting173
537Container with Most Water173
538Iterative Inorder Traversal of a Binary Tree173
539Recursion173
540Valid Sudoku173
541Excel Sheet Column Title Leetcode Solution173
542Implement Stack using Queues173
543N-th Tribonacci Number Leetcode Solution173
544Contiguous Array Leetcode172
545Largest Perimeter Triangle Leetcode Solution172
546First negative integer in every window of size k172
547Best Time to Buy and Sell Stock172
548Maximum sum rectangle in a 2D matrix172
549Delete Node in a Linked List Leetcode Solution172
550Build Array From Permutation Leetcode Solution172
551Next Greater Frequency Element172
552Convert a normal BST to Balanced BST171
553Sum of Left Leaves Leetcode Solutions171
554Find Words That Can Be Formed by Characters Leetcode Solution171
555Trapping Rain Water LeetCode Solution171
55601 Matrix LeetCode Solution171
557Isomorphic Strings Leetcode Solution171
558Valid Anagrams171
559Minimum Delete Operations to make all Elements of Array Same171
560Arrange given numbers to form the biggest number170
561Is Subsequence Leetcode Solution170
562Remove Linked List Elements Leetcode Solution170
563Count the number of nodes at given level in a tree using BFS170
564Shuffle an Array170
565Jewels and Stones Leetcode Solution170
566Minimum Bracket Reversals170
567Minimum Operations to convert X to Y170
568Linked List Cycle II LeetCode Solution170
569Distribute Candies to People Leetcode Solution170
570Count all subsequences having product less than K169
571Assign Cookies Leetcode Solution169
572Convert Sorted Array to Binary Search Tree Leetcode Solution169
573Integer to Roman169
574Rearrange a binary string as alternate x and y occurrences169
575Gold Mine Problem169
576Insert Interval Leetcode Solution168
577Hamming Distance168
578Island Perimeter Leetcode Solution168
579Change the Array into Permutation of Numbers From 1 to N168
580Group Multiple Occurrence of Array Elements Ordered by first Occurrence168
581Shortest Path in a Grid with Obstacles Elimination LeetCode Solution168
582The Knapsack Problem168
583Check for Balanced Parentheses in an Expression168
584K Empty Slots LeetCode167
585Unique Binary Search Trees167
586Maximum path sum in a triangle167
587Minimum number of distinct elements after removing m items167
5883Sum Closest LeetCode Solution167
589Decode Ways167
590Rotate List Leetcode Solution167
591How to check if two given sets are disjoint?166
592Same Tree LeetCode Solution166
593Find the smallest positive integer value that cannot be represented as sum of any subset of a given array166
594Combinations Leetcode Solution166
595Sieve of Eratosthenes166
596Maximum difference between first and last indexes of an element in array165
597LRU Cache LeetCode Solution165
598Rotate Image LeetCode Solution165
599Find minimum difference between any two elements165
600Minimum Knight Moves LeetCode Solution165
601Summary Ranges Leetcode Solution165
602Distance Between Bus Stops Leetcode Solution165
603Permutation in String Leetcode Solution164
604Minimum number of subsets with distinct elements164
605Maximum Distance in Array164
606Frog Jump Leetcode Solution164
607Segregate 0s and 1s in an Array164
608Remove All Occurrences of a Substring LeetCode Solution164
609Word Pattern164
610Sort Characters By Frequency LeetCode Solution163
611Sort Array By Parity LeetCode Solution163
612Minimum insertions to form a palindrome with permutations allowed163
613Painting Fence Algorithm163
614Word Wrap Problem163
615Smallest Good Base163
616XOR Operation in an Array Leetcode Solution163
617Find Sum of all unique sub-array sum for a given array163
618Printing brackets in Matrix Chain Multiplication Problem163
619Find if an Expression has Duplicate Parenthesis or Not162
620Replace Elements with Greatest Element on Right Side Leetcode Solution162
621Stone Game LeetCode162
622Coin Change Problem162
623Distance of nearest cell having 1 in a binary matrix162
624Minimum Depth of Binary Tree Leetcode Solution162
625Defanging an IP Address Leetcode Solution162
626Find the Duplicate Number LeetCode Solution162
627Maximum Number of Chocolates to be Distributed Equally Among k Students162
628Applications of Breadth First Search and Depth First Search162
629Best Time to Buy and Sell Stock LeetCode Solution162
630License Key Formatting Leetcode Solution161
631House Robber161
632Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
633Kth Missing Positive Number Leetcode Solution161
634Minimum Cost to Hire K Workers161
635Optimal Account Balancing LeetCode Solution160
636Maximum Consecutive Numbers Present in an Array160
637Find Maximum Level sum in Binary Tree160
638Sum of All Odd Length Subarrays Leetcode Solution160
639Longest Substring with At Most K Distinct Characters LeetCode Solution160
640Power of Four Leetcode Solution160
641Longest Increasing Subsequence160
642Tracking current Maximum Element in a Stack160
643Iterative Method to find Height of Binary Tree160
644Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions160
645Count Good Nodes in Binary Tree Leetcode Solution160
646Isomorphic Strings159
647Reverse a stack without using extra space in O(n)159
648Delete consecutive same words in a sequence159
649Check If It Is a Straight Line Leetcode Solution159
650Valid Palindrome II Leetcode Solution159
651Non-overlapping sum of two sets159
652Binary Tree Zigzag Level Order Traversal LeetCode Solution159
653Best Time to Buy and Sell Stock with Cooldown Leetcode Solution159
654Convert an array to reduced form158
655Strobogrammatic Number LeetCode Solution158
656Check If Two String Arrays are Equivalent Leetcode Solution158
657Letter Combinations of a Phone Number158
658Number of Provinces Leetcode Solution158
659Merge Two Balanced Binary Search Trees158
660GCD Of Two Numbers158
661Maximum Number of Coins You Can Get Leetcode Solution158
662Queries for counts of array elements with values in given range158
663K Empty Slots158
664Wiggle Sort157
665Reorganize String157
666Number of Dice Rolls With Target Sum LeetCode Solution157
667Reducing Dishes LeetCode Solution157
668Employee Free Time LeetCode Solution157
669Reverse Only Letters LeetCode Solution157
670Lucky Numbers in a Matrix Leetcode Solution157
671Largest Sum Contiguous Subarray157
672Subset Sum Leetcode157
673Flipping an Image LeetCode Solution157
674Partition Labels LeetCode Solution157
675Find Largest d in Array such that a + b + c = d157
676Ugly Number Leetcode Solution157
677Longest Increasing Path in a Matrix LeetCode Solution157
678String to Integer (atoi) LeetCode Solution157
679How to Create Mergable Stack?156
680Maximum Number of Occurrences of a Substring Leetcode Solution156
681Form minimum number from given sequence156
682Find whether an array is subset of another array156
683Check if a queue can be sorted into another queue using a stack156
684Path With Maximum Minimum Value LeetCode Solution156
685Print the Fibonacci numbers in reverse order156
686Increasing Decreasing String Leetcode Solution156
687Longest Substring with At Least K Repeating Characters LeetCode Solution156
688Find the Distance Value Between Two Arrays Leetcode Solution156
689Sum of f(a[i], a[j]) over all pairs in an array of n integers156
690Moving Average from Data Stream Leetcode Solution156
691Valid Palindrome155
692To Lower Case Leetcode Solution155
693Permutation Sequence LeetCode Solution155
694BFS vs DFS for Binary Tree155
695Inorder Successor of a node in Binary Tree155
696Recover Binary Search Tree155
697Find Leaves of Binary Tree LeetCode Solution155
698Populating Next Right Pointers in Each Node155
699Reversing a Queue using Recursion155
700Reservoir Sampling155
701Sort Array by Increasing Frequency Leetcode Solution154
702Find the Smallest Divisor given a Threshold Leetcode Solution154
703Unique Paths II Leetcode Solution154
704Find pairs with given sum such that elements of pair are in different rows154
705Merge Two Binary Trees LeetCode Solution154
706Hamming Distance Leetcode Solution154
707Binary Tree zigzag level order Traversal154
708Edit Distance LeetCode Solution154
709Add and Search Word – Data structure design LeetCode154
710Dynamic Programming Basics154
711Delete Nth node from the end of the given linked list154
712Majority Element II Leetcode Solution153
713Remove Invalid Parentheses Leetcode Solution153
714Find the node with minimum value in a Binary Search Tree153
715Numbers with prime frequencies greater than or equal to k153
716Partition Array Into Three Parts With Equal Sum Leetcode Solution153
717Decompress Run-Length Encoded List Leetcode Solution153
718Valid Perfect Square Leetcode Solution153
719Maximum Product of Three Numbers LeetCode Solution153
720Keyboard Row Leetcode Solution153
721Convert a Number to Hexadecimal Leetcode Solution153
722Robot Room Cleaner Leetcode Solution153
723Construct BST from given Preorder Traversal153
724Rank Transform of an Array Leetcode Solution152
725Factorial Trailing Zeroes Leetcode Solution152
726Stack Permutations (Check if an array is stack permutation of other)152
727Longest Span with same Sum in two Binary arrays152
728Bulb Switcher LeetCode Solution152
729String Compression LeetCode Solution152
730Largest subarray with equal number of 0s and 1s151
731Find the largest multiple of 3151
732Queue based approach for first non-repeating character in a stream151
733Race Car LeetCode Solution151
734Find Maximum Depth of Nested Parenthesis in a String151
735Deletion in a Binary Tree151
736Symmetric Tree Leetcode Solution151
737Non-decreasing Array LeetCode Solution151
738Linked List Cycle150
739Maximum 69 Number Leetcode Solution150
740k-th missing element in increasing sequence which is not present in a given sequence150
741Minimum Height Trees150
742Maximum Product of Two Elements in an Array Leetcode Solution150
743Minimize Maximum Pair Sum in Array LeetCode Solution150
744Binary Tree Maximum Path Sum LeetCode Solution150
745Find Pair with Greatest Product in Array150
746Perform String Shifts Leetcode150
747Find if Path Exists in Graph Leetcode Solution150
748Minimum Cost For Tickets Leetcode Solution150
749First Unique Character in a String LeetCode Solution150
750Bubble sort using two Stacks150
751Sorted Linked List to Balanced BST150
752Invert Binary Tree LeetCode Solution150
753Word Pattern LeetCode Solution150
754Remove Nth Node From End of List Leetcode Solution150
755Binomial Coefficient150
756Restore IP Addresses Leetcode Solution150
757Find unique character in a string150
758Morris Traversal149
759Finding K closest element149
760Best Meeting Point LeetCode Solution149
761Jump Game149
762Diagonal Traversal of Binary Tree149
763Count quadruples from four sorted arrays whose sum is equal to a given value x149
764Minimum Distance Between BST Nodes Leetcode Solution149
765Maximum Length of a Concatenated String with Unique Characters Leetcode Solution149
766Evaluate Reverse Polish Notation LeetCode Solution149
767Find All Duplicates in an Array LeetCode Solution149
768Remove Duplicates from Sorted List LeetCode Solution149
769Search in a Binary Search Tree Leetcode Solution149
770Student Attendance Record I Leetcode Solution149
771Number of Islands II LeetCode Solution149
772Generate all possible sorted arrays from alternate elements of two given sorted arrays149
773Elements to be added so that all elements of a range are present in array149
774Merge K Sorted Linked Lists149
775Find Median from Data Stream LeetCode Solution149
776Growable array based stack149
777Split a String in Balanced Strings Leetcode Solution148
778Remove brackets from an algebraic string containing + and – operators148
779N-Queens LeetCode Solution148
780Kth ancestor of a node in binary tree148
781Largest rectangular sub-matrix whose sum is 0148
782Valid Number148
783Snakes and Ladders LeetCode Solution148
784Program for Bridge and Torch problem148
785Minimum time required to rot all oranges148
786Maximum Difference Between Increasing Elements LeetCode Solution148
787Minimum number of jumps to reach end147
788Sort an array according to the order defined by another array147
789Merge Sorted Array LeetCode Solution147
790Transpose Graph147
791Nearest Exit from Entrance in Maze LeetCode Solution147
792Minimum Time Visiting All Points Leetcode Solution147
793Remove Duplicates from Sorted List II147
794Check for Palindrome after every character replacement Query147
795Largest Rectangle in Histogram LeetCode Solution147
796Number of NGEs to the Right147
797Relative Ranks Leetcode Solution147
798Nested List Weight Sum II LeetCode Solution147
799Special Array With X Elements Greater Than or Equal X Leetcode Solution147
800Maximum Depth of N-ary Tree Leetcode Solution147
801A Space Optimized DP solution for 0-1 Knapsack Problem146
802String comparison containing wildcards146
803Tiling Problem146
804Crawler Log Folder Leetcode Solution146
805Friends Pairing Problem146
806Get Maximum in Generated Array Leetcode Solution146
807Sort Array By Parity II Leetcode Solution146
808Partition to K Equal Sum Subsets Leetcode Solution146
809Base 7 Leetcode Solution146
810Circular Queue146
811Check If Array Pairs Are Divisible by k LeetCode Solution146
812Sort Colors146
813Search a 2D Matrix II Leetcode Solution146
814Convert BST to Min Heap146
815Print a Binary Tree in Vertical Order146
816Count items common to both the lists but with different prices146
817Clone Graph LeetCode Solution145
818Number Complement Leetcode Solution145
819Final Prices With a Special Discount in a Shop Leetcode Solution145
820Minimum swaps to make sequences increasing145
821Check if Two Expressions With Brackets are Same145
822Path with maximum average value145
823Interval Tree145
824Minimum Number of Taps to Open to Water a Garden LeetCode Solution145
825Alien Dictionary LeetCode Solution145
826Reorder Data in Log Files LeetCode Solution145
827Longest Subarray Having Count of 1s One More than Count of 0s144
828Maximum size subarray sum equals k144
829Level order Traversal in Spiral Form144
830Total Numbers With no Repeated Digits in a Range144
831Regular Expression Matching144
832Subarray Product Less Than K LeetCode Solution144
833Design a Stack With Increment Operation Leetcode Solution144
834Sorted Array to Balanced BST144
835Partition List Leetcode Solution144
836Subsequence of Size K With the Largest Even Sum LeetCode Solution144
837Minimum Swaps to Make Strings Equal Leetcode Solution144
838Iterative Preorder Traversal144
839One Edit Distance LeetCode Solution144
840Course Schedule II – LeetCode144
841Count Distinct Elements in Every Window of Size K143
842Last Stone Weight II LeetCode Solution143
843Find all triplets with zero sum143
844Check if a given array can represent Preorder Traversal of Binary Search Tree143
845Brightest Position on Street LeetCode Solution143
846Subset with sum divisible by m143
847Priority Queue using doubly linked list143
848Guess Number Higher or Lower LeetCode Solution143
849Top K Frequent Words LeetCode Solution143
850Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution143
851Minimum Jumps to Reach Home LeetCode Solution143
852Find the subarray with least average143
853Permutation Coefficient143
854Can Place Flowers LeetCode Solution143
855Maximum Profit in Job Scheduling Leetcode Solution142
856Find All Possible Recipes from Given Supplies LeetCode Solution142
857Water Bottles Leetcode Solution142
858Valid Parentheses Leetcode Solution142
859Given an Array of Pairs Find all Symmetric Pairs in it142
860Brick Wall LeetCode Solution142
861Maximum Nesting Depth of the Parentheses Leetcode Solution142
862Find the Only Repetitive Element Between 1 to N-1142
863Check whether a given Binary Tree is Complete or not142
864Insert into a Binary Search Tree Leetcode Solution142
865Design Browser History LeetCode Solution141
866Form Minimum Number From Given Sequence141
867Check if an Array is Stack Sortable141
868Spiral Matrix II Leetcode Solution141
869Repeated Substring Pattern LeetCode Solution141
870Union and Intersection of two Linked Lists141
871Least Number of Unique Integers after K Removals Leetcode Solution141
872Sum of nearest smaller and greater number141
873Binary Search Tree Search and Insertion141
874LCS (Longest Common Subsequence) of three strings141
875Range sum queries without updates141
876Count ways to reach the nth stair using step 1, 2 or 3141
877Matrix Chain Multiplication141
878Rearrange Spaces Between Words Leetcode Solution141
879GCDs of given index ranges in an array140
880Daily Temperatures Leetcode Solution140
881Distinct adjacent elements in an array140
882Construct Complete Binary Tree from its Linked List Representation140
883Three way partitioning of an array around a given range140
884Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution140
885Delete And Earn140
886An Interesting Method to generate Binary Numbers from 1 to n140
887Destination City Leetcode Solution140
8884Sum140
889Minimum Sum Path in a Triangle140
890Tree Traversal (Preorder, Inorder & Postorder)140
891Find all permuted rows of a given row in a matrix140
892Insert Delete GetRandom140
893Count Negative Numbers in a Sorted Matrix LeetCode Solution140
894Shortest Word Distance Leetcode Solution140
895Guess Number Higher or Lower II140
896Maximum Score After Splitting a String Leetcode Solution140
897Count Subarrays with Same Even and Odd Elements140
898Number of Days Between Two Dates LeetCode Solution139
899Diagonal Traversal LeetCode Solution139
900Set Matrix Zeroes Leetcode Solution139
901Convert Sorted List to Binary Search Tree139
902Find Maximum Sum Possible Equal Sum of Three Stacks139
903Missing Element in Sorted Array LeetCode Solution139
904Queries for GCD of all numbers of an array except elements in a given range139
905Lemonade Change Leetcode Solution139
906Sequences of given length where every element is more than or equal to twice of previous139
907Rearrange an Array Such that arr[i] is equal to i139
908Identify and Mark Unmatched Parenthesis in an Expression139
909Check if stack elements are pairwise consecutive139
910A program to check if a binary tree is BST or not139
911Special Positions in a Binary Matrix Leetcode Solution138
912Find Common Characters Leetcode Solution138
913Find distance between two nodes of a Binary Tree138
914Range LCM Queries138
915Check if the given array can represent Level Order Traversal of Binary Search Tree138
916Balanced Expression with Replacement138
917Robot Bounded In Circle LeetCode Solution138
918BFS for Disconnected Graph138
919Time Based Key-Value Store LeetCode Solution138
920Alien Dictionary138
921Minimum sum of multiplications of n numbers138
922Merge Two Sorted Lists Leetcode137
923Vertical sum in a given binary tree137
924Number of Distinct Islands Leetcode Solution137
925Stone Game II Leetcode137
926Longest Palindromic Subsequence137
927Diagonal Traverse LeetCode Solution137
928Spiral Matrix III LeetCode Solution137
929K’th Largest Element in BST when modification to BST is not allowed136
930Palindrome Partitioning Leetcode Solution136
931Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i136
932Queue using Stacks136
933Number of Equivalent Domino Pairs Leetcode Solution136
934Averages of Levels in Binary Tree136
935Infix to Postfix136
936Remove Duplicates from Sorted List II LeetCode Solution136
937Can Make Arithmetic Progression From Sequence Leetcode Solution136
938Maximum Frequency Stack Leetcode Solution136
939Print Fibonacci sequence using 2 variables136
940Lexicographical Numbers Leetcode Solution136
941Maximum Subarray Sum Excluding Certain Elements136
942Three Consecutive Odds Leetcode Solution135
943Dividing Array into Pairs With Sum Divisible by K135
9443 Sum135
945Binary array after M range toggle operations135
946Largest area rectangular sub-matrix with equal number of 1’s and 0’s135
947Construct the Rectangle Leetcode Solution135
948Median of Two Sorted Arrays135
949Pattern Occurrences using Stack135
950Trim a Binary Search Tree135
951Merging Intervals135
952Difference Array | Range update query in O(1)135
953Construct BST from its given Level Order Traversal135
954Sliding Window Maximum134
955Analyze User Website Visit Pattern LeetCode Solution134
956Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution134
957Height of a generic tree from parent array134
958Newman-Conway Sequence134
959Strongly Connected Component134
960Check if any two intervals overlap among a given set of intervals134
961Word Break134
962Intersection of Two Linked Lists LeetCode Solution134
963Largest Substring Between Two Equal Characters Leetcode Solution134
964Maximize Sum of Array after K Negations Leetcode Solution134
965Largest divisible pairs subset134
966All Unique Triplets that Sum up to a Given Value134
967Binary Tree Longest Consecutive Sequence LeetCode Solution134
968Minimum Height Trees LeetCode Solution134
969Find postorder traversal of BST from preorder traversal134
970Iterative Postorder Traversal Using Two Stacks133
971Symmetric Tree133
972Create Maximum Number133
973Breadth First Search (BFS) for a Graph133
974Count Submatrices With All Ones LeetCode Solution133
975Depth First Search (DFS) for a Graph133
976Segment Tree133
977First missing positive133
978Find Maximum of Minimum for Every Window Size in a Given Array133
979Palindrome Partitioning133
980Split Array Into Consecutive Subsequences133
981Maximum Product Subarray133
982Product of Array Except Self LeetCode Solution133
983Binary Search Tree Delete Operation132
984Length of Longest Fibonacci Subsequence132
985Asteroid Collision LeetCode Solution132
986Maximum subsequence sum such that no three are consecutive132
987Sign of the Product of an Array LeetCode Solution132
988My Calendar I LeetCode Solution132
989Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space132
990Minesweeper LeetCode Solution132
991Level Order Traversal of Binary Tree132
992Rearrange array such that even positioned are greater than odd132
993Climbing stairs132
994Count Primes in Ranges132
995Reverse Nodes in K-Group132
996Find the First Circular Tour that visits all the Petrol Pumps131
997Find Duplicate Subtrees131
998Kill Process LeetCode Solution131
999Count pair with Given Sum131
1000Maximum Number of Ways to Partition an Array LeetCode Solution131
1001Find the Difference Leetcode Solution131
1002Boundary Traversal of binary tree131
1003Partition Equal Subset Sum131
1004Kth Smallest Element in a BST Leetcode Solution131
1005Serialize and Deserialize Binary Tree130
1006Maximum Length of Repeated Subarray130
1007Largest Number Leetcode Solution130
1008Level order traversal using two Queues130
1009Insertion in a Binary Tree130
1010Super Ugly Number130
1011Shortest Completing Word Leetcode Solution130
1012Decrypt String from Alphabet to Integer Mapping Leetcode Solution130
1013Longest Nice Substring LeetCode Solution130
1014Make The String Great Leetcode Solution130
1015Double the first element and move zero to end130
1016Unique Paths II130
1017Graph Valid Tree LeetCode Solution130
1018The Painter’s Partition Problem130
1019Find number of pairs in an array such that their XOR is 0130
1020Binary Search Tree129
1021K Closest Points to Origin Leetcode Solution129
1022Valid Boomerang Leetcode Solution129
1023Longest subsequence such that difference between adjacents is one129
1024Number Of Longest Increasing Subsequence129
1025Count subarrays where second highest lie before highest129
1026Collect maximum points in a grid using two traversals129
1027Compute nCr % p129
1028Ugly Number II LeetCode Solution129
1029Advantages of BST over Hash Table129
1030Friends Of Appropriate Ages LeetCode Solution129
1031Boolean Parenthesization Problem128
1032Construct Binary Tree from given Parent Array representation128
1033Next Greater Element III LeetCode Solution128
1034Build an Array With Stack Operations Leetcode Solution128
1035Defanging an IP Address LeetCode Solution128
1036Maximum Product of Indexes of Next Greater on Left and Right128
1037The Maze III LeetCode Solution128
1038Scramble String LeetCode Solution128
1039Invalid Transactions LeetCode Solution128
1040Construction of Longest Increasing Subsequence (N log N)128
1041Minimum Size Subarray Sum128
1042Employee Importance LeetCode Solution128
1043Balanced Binary Tree128
1044Design Hit Counter LeetCode Solution128
1045Available Captures for Rook Leetcode Solution128
1046Number of palindromic paths in a matrix128
1047String Matching in an Array Leetcode Solution128
1048Maximum difference between frequency of two elements such that element having greater frequency is also greater127
1049Morris Inorder Traversal127
1050Longest Bitonic Subsequence127
1051Ugly Numbers127
1052Maximum Sum of 3 Non-Overlapping Subarrays127
1053Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’127
1054Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1055Populating Next Right Pointers in Each Node Leetcode Solution127
1056Regular Expression Matching Regular Expression Matching LeetCode Solution127
1057Maximum weight transformation of a given string127
1058Find whether a subarray is in form of a mountain or not127
1059Kth Smallest Element in a Sorted Matrix LeetCode Solution127
1060Find Peak Element127
1061Count minimum steps to get the given desired array127
1062Add two numbers127
1063Lowest Common Ancestor126
1064Minimum Index Sum of Two Lists126
1065Find the minimum distance between two numbers126
1066Implement Trie (Prefix Tree) Leetcode Solution126
1067Validate Binary Search Tree126
1068Bitwise AND of Numbers Range LeetCode Solution126
1069Recover Binary Search Tree Leetcode Solution126
1070Iterative Depth First Traversal of Graph126
1071Custom Sort String Leetcode Solution125
1072Path Sum II LeetCode Solution125
1073Move all negative elements to end in order with extra space allowed125
1074Search in Sorted Rotated Array125
1075Binary Tree Right Side View LeetCode Solution125
1076Find a Peak Element II LeetCode Solution125
1077Binary Tree Data Structure125
1078Maximize Distance to Closest Person LeetCode Solution125
1079Combination Sum IV LeetCode Solution125
1080Smallest Common Region Leetcode Solution125
1081Remove Duplicates from Sorted Array II Leetcode Solution125
1082Number of Closed Islands Leetcode Solution125
1083Divisible Pairs Counting125
1084Largest BST Subtree LeetCode Solution125
1085Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution125
1086Clone a Binary Tree with Random Pointers124
1087Rearrange array such that even index elements are smaller and odd index elements are greater124
1088Types of Binary Tree124
1089Number of Students Doing Homework at a Given Time Leetcode Solution124
1090Day of the Year Leetcode Solution124
1091Path Sum124
1092Subarrays with K Different Integers Leetcode Solution124
1093Serialize and Deserialize Binary Tree LeetCode Solution123
1094Print all triplets in sorted array that form AP123
1095Print Next Greater Number of Q queries123
1096Consecutive Characters LeetCode Solution123
1097Number of siblings of a given Node in n-ary Tree123
1098Generate Parentheses Leetcode Solution123
1099Level of Each node in a Tree from source node123
1100Count pairs from two sorted arrays whose sum is equal to a given value x123
1101Kth Smallest Product of Two Sorted Arrays LeetCode Solution123
1102Find Smallest Range Containing Elements from k Lists123
1103Next Permutation Leetcode Solution123
1104Distinct Subsequences122
1105Find maximum difference between nearest left and right smaller elements122
1106Topological Sorting122
1107Bottom View of a Binary Tree122
1108Remove Palindromic Subsequences Leetcode Solution122
1109Maximum Product Subarray122
1110Root to Leaf path with target sum Leetcode Solutions122
1111Find Three Element From Different Three Arrays Such That a + b + c = sum121
1112Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution121
1113Convert BST into a Min-Heap without using array121
1114Cutting a Rod121
1115Write Code to Determine if Two Trees are Identical121
1116Maximum Binary Tree121
1117Remove duplicates from sorted array121
1118Count Largest Group Leetcode Solution121
1119Print Right View of a Binary Tree121
1120Valid Tic-Tac-Toe State LeetCode Solution121
1121Third Maximum Number Leetcode Solution121
1122Constant time range add operation on an array121
1123Search Insert Position120
1124Cells with Odd Values in a Matrix LeetCode Solution120
1125Increasing Triplet Subsequence LeetCode Solution120
1126Golomb sequence120
1127Queries for Number of Distinct Elements in a Subarray120
1128Mean of Array After Removing Some Elements Leetcode Solution120
1129Search an Element in Sorted Rotated Array120
1130Reformat The String Leetcode Solution120
1131Iterative method to find ancestors of a given binary tree120
1132Longest Subarray of 1’s After Deleting One Element LeetCode Solution120
1133Products of ranges in an array120
1134Minimum sum of squares of character counts in a given string after removing k characters120
1135Palindrome Permutation LeetCode Solution120
1136Minimum Score Triangulation of Polygon Leetcode Solution119
1137Minimum Absolute Difference in BST Leetcode Solution119
1138Thousand Separator Leetcode Solution119
1139Construct K Palindrome Strings LeetCode Solution119
1140Longest Increasing Consecutive Subsequence119
1141Print modified array after executing the commands of addition and subtraction119
1142Prime Palindrome LeetCode Solution119
1143Moser-de Bruijn Sequence119
1144Binary Tree to Binary Search Tree Conversion118
1145Red-Black Tree Introduction118
1146Sum of Even Numbers After Queries118
1147Find maximum length Snake sequence118
1148Delete Nodes and Return Forest Leetcode Solution118
1149Longest Repeated Subsequence117
1150Swap Nodes In Pairs117
1151Possible Bipartition LeetCode Solution117
1152Count even length binary sequences with same sum of first and second half bits117
1153K maximum sums of overlapping contiguous sub-arrays117
1154Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1155Kth Smallest Number in Multiplication Table Leetcode Solution117
1156Check Array Formation Through Concatenation Leetcode Solution117
1157Maximum Product of Splitted Binary Tree LeetCode Solution117
1158Factorial Trailing Zeroes LeetCode Solution117
1159Palindromic Substrings Leetcode Solution117
1160Transform a BST to Greater sum Tree117
1161Decision Tree117
1162Swapping Nodes in a Linked List Leetcode Solution116
1163Find a sorted subsequence of size 3 in linear time116
1164Priority Queue116
1165Minimum Sideway Jumps LeetCode Solution116
1166Subset Sum Problem in O(sum) space116
1167Merge two BSTs with limited extra space116
1168K’th Largest element in BST using constant extra space116
1169Compare Strings by Frequency of the Smallest Character Leetcode Solution116
1170Find the smallest binary digit multiple of given number116
1171Web Crawler LeetCode Solution116
1172Rotate Array116
1173Maximize sum of consecutive differences in a circular array116
1174Minimum Cost to Move Chips to The Same Position LeetCode Solution116
1175Find Largest Value in Each Tree Row LeetCode Solution115
1176Search Suggestions System LeetCode Solution115
1177Closest Binary Search Tree Value Leetcode Solution115
1178Bus Routes Leetcode Solution115
1179First Bad Version115
1180Decrease Elements To Make Array Zigzag LeetCode Solution114
1181Diameter of N-Ary Tree LeetCode Solution114
1182Count Pairs Whose Products Exist in Array114
1183Number of Orders in the Backlog Leetcode Solution114
1184Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1185Minimum Moves to Equal Array Elements LeetCode Solution114
1186Queue Reconstruction by Height113
1187Convert Sorted Array to Binary Search Tree LeetCode Solutions113
1188Reverse a Path in BST using Queue113
1189Maximum number of segments of lengths a, b and c113
1190Matchsticks to Square Leetcode Solution113
1191Given a binary tree, how do you remove all the half nodes?113
1192Contiguous Array LeetCode Solution113
1193Moving Stones Until Consecutive Leetcode Solution113
1194Write a function to get the intersection point of two Linked Lists112
1195Champagne Tower LeetCode Solution112
1196Valid Triangle Number112
1197Reformat Date LeetCode Solution112
1198Closest Leaf in a Binary Tree LeetCode Solution112
1199Array Queries for multiply replacements and product112
1200Kth Smallest Element in a BST112
1201Lowest Common Ancestor in Binary Search Tree112
1202Maximum sum bitonic subarray112
1203Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution112
1204Sum of Left Leaves LeetCode Solution111
1205Maximum Depth Of Binary Tree111
1206New 21 Game111
1207Replace two consecutive equal values with one greater111
1208Range Sum Query using Sparse Table111
1209How to print maximum number of A’s using given four keys111
1210Maximum sum of pairs with specific difference111
1211Range Queries for Longest Correct Bracket Subsequence110
1212Valid Perfect Square LeetCode Solution110
1213Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1214Concatenation of Array LeetCode Solution110
1215Divide Two Integers Leetcode Solution110
1216Integer Break LeetCode Solution110
1217Graph and its representation110
1218Design Skiplist LeetCode Solution110
1219Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution110
1220Lowest Common Ancestor of a Binary Tree Leetcode Solution109
1221Path Crossing Leetcode Solution109
1222Maximum sum of a path in a Right Number Triangle109
1223Check if each internal node of a BST has exactly one child109
1224Guess The Word109
1225BST to a Tree with Sum of all Smaller Keys109
1226The kth Factor of n Leetcode Solution109
1227Symmetric Tree LeetCode Solution Leetcode Solution109
1228Print modified array after multiple array range increment operations109
1229Arithmetic Slices II – Subsequence LeetCode Solution109
1230Flatten 2D Vector LeetCode Solution109
1231Merge Sort109
1232Perfect Squares LeetCode Solution108
1233Count Subsets Having Distinct Even Numbers108
1234Check if all levels of two Binary Tree are anagrams or not108
1235Check for Identical BSTs without building the trees108
1236Queries on Probability of Even or Odd Number in given Ranges108
1237Check Completeness of a Binary Tree LeetCode Solution108
1238Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1239Sliding Window Median Leetcode Solution108
1240Mean of range in array107
1241Largest Plus Sign Leetcode Solution107
1242Contiguous Array107
1243Count and Toggle Queries on a Binary Array107
1244Maximum Array from Two given Arrays Keeping Order Same107
1245Power of Two107
1246Find Minimum in Rotated Sorted Array II LeetCode Solution107
1247Parallel Courses II LeetCode Solution107
1248Graph Cloning107
1249Longest Common Prefix Using Word by Word Matching107
1250Find minimum number of merge operations to make an array palindrome106
1251LRU Cache Leetcode Solution106
1252Print n terms of Newman-Conway Sequence106
1253Bold Words in String LeetCode Solution106
1254Maximize Elements Using Another Array106
1255Missing Number106
1256Verify Preorder Serialization of a Binary Tree105
1257Excel Sheet Column Title LeetCode Solution105
1258Find k-th smallest element in BST (Order Statistics in BST)105
1259Check If a String Can Break Another String Leetcode Solution105
1260Minimum Remove to Make Valid Parentheses LeetCode Solution105
1261Print Ancestors of a Given Binary Tree Node Without Recursion104
1262Maximum Product Subarray104
1263Next greater element104
1264Image Overlap LeetCode Solution104
1265Palindrome Partitioning103
1266Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1267Smallest Range II Leetcode Solution103
1268Merge k Sorted Lists Leetcode Solution103
1269Check if two nodes are on the same path in a Tree102
1270Orderly Queue LeetCode Solution101
1271Min Cost Climbing Stairs LeetCode Solution101
1272Check in binary array the number represented by a subarray is odd or even101
1273Koko Eating Bananas LeetCode Solution100
1274Merge Sorted Array100
1275Newman–Shanks–Williams prime99
1276Peeking Iterator LeetCode Solution99
1277Check if X can give change to every person in the Queue99
1278Number of elements less than or equal to a given number in a given subarray98
1279Different Ways to Add Parentheses Leetcode Solution98
1280Maximum Sum Increasing Subsequence97
1281Find maximum average subarray of k length97
1282Largest Submatrix With Rearrangements LeetCode Solution97
1283Range Minimum Query (Square Root Decomposition and Sparse Table)97
1284Number of indexes with equal elements in given range96
1285Queries for Decimal Values of Subarrays of a Binary Array96
1286Maximum product of an increasing subsequence95
1287Longest Substring Without Repeating Characters Leetcode Solution95
1288Minimum Total Space Wasted With K Resizing Operations LeetCode Solution95
1289Check given array of size n can represent BST of n levels or not94
1290Array Nesting Leetcode Solution94
1291Binary Tree to Binary Search Tree Conversion using STL set93
1292Arranging Coins Leetcode Solution93
1293Encoded String With Shortest Length LeetCode Solution92
1294Random Pick Index LeetCode Solution92
1295Reach a Number LeetCode Solution92
1296Minimum Number of People to Teach LeetCode Solution92
1297Convert to Base -2 LeetCode Solution91
1298Queries on XOR of greatest odd divisor of the range91
1299Find the Winner of the Circular Game LeetCode Solution91
1300Jump Game IV LeetCode Solution90
1301Insert Delete GetRandom O(1) Leetcode Solution90
1302Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1303Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1304Palindrome Number LeetCode Solution88
1305Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution88
1306Add Two Numbers II Leetcode Solution87
1307Vertical Order Traversal of Binary Tree LeetCode Solution87
1308Design Underground System Leetcode Solution85
1309Print Maximum Length Chain of Pairs84
1310Continuous Subarray Sum LeetCode Solution83
1311Detect Capital Leetcode Solution81
1312Design A Leaderboard Leetcode Solution79
1313Substring with Concatenation of All Words Leetcode Solution77
1314Minimum Swaps to Group All 1’s Together Leetcode Solution76
1315Top K Frequent Elements LeetCode Solution76
1316Minimum Path Sum Leetcode Solution73
1317Odd Even Linked List Leetcode Solution72
1318Binary Tree Inorder Traversal LeetCode Solution72
1319Count Sub Islands LeetCode Solution72
1320Decode String Leetcode Solution72
1321Shortest Unsorted Continuous Subarray LeetCode Solution71
1322Shifting Letters LeetCode Solution71
1323Sum Root to Leaf Numbers LeetCode Solution70
1324Maximum Population Year LeetCode Solution70
1325Find the Town Judge LeetCode Solution70
1326Best Meeting Point LeetCode Solution69
1327Longest Common Subsequence LeetCode Solution68
1328Find the Town Judge LeetCode Solution67
1329Design Add and Search Words Data Structure LeetCode Solution66
1330Maximum Population Year LeetCode Solution64
1331Rectangle Overlap LeetCode Solution64
1332Score of Parenthesis LeetCode Solution64
1333Insert into a Sorted Circular Linked List LeetCode Solution62
1334Stone Game IV LeetCode Solution61
1335Flatten Binary Tree to Linked List LeetCode Solution61
1336Range Sum Query 2D – Immutable LeetCode Solution60
1337Valid Triangle Number LeetCode Solution59
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution53
1340Divide Chocolate LeetCode Solution50
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution42
1342Range Sum of BST LeetCode Solution42
1343Reverse Integer Leetcode Solution39
1344Sort Colors LeetCode Solution37
1345Find K Closest Elements LeetCode Solution33
1346Excel Sheet Column Number LeetCode Solution32
1347Rotate String LeetCode Solution32
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution29
Translate »