Validate Stack Sequences LeetCode Solution

Frequently asked in Adobe Amazon Apple Google Microsoft Zoho
Difficulty : Medium tiktokViews 29

Problem Statement

Validate Stack Sequences LeetCode Solution – Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.

Example 1:

Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
Output: true
Explanation: We might do the following sequence:
push(1), push(2), push(3), push(4),
pop() -> 4,
pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
Example 2:

Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
Output: false
Explanation: 1 cannot be popped before 2.


We know that if an element has been popped.

All elements before it in the pop list must have been pushed after it.

lets use that as an invariant for our algorithm.

Given an element X in pushed, find its location in popped. Its location in popped tells us how many elements need to have been pushed before it. Lets denote that as N. we can now look at all elements in Pushed starting from X up to the Nth element after X, and the subset of elements in Popped before X (of size N). Recursively check those ranges together, but also the ranges that come after the Nth element in pushed, and after X in popped (together).

  1. Iterate pushed array one by one.
  2. for each iteration push the current element to the stack.
  3. while the top of the stack is the same as popped array current element. remove a top element from the stack and increment j.
  4. when the inner loop finishes it means we have removed all the possible elements from pushed array till the current element of the pushed stack.
  5. once the outer loop finishes. it means the entire pushed array is exhausted and hence here stack must be empty if pushed and popped arrays are valid.

Validate Stack Sequences LeetCode SolutionPin


Java Solution:

class Solution {
   public boolean validateStackSequences(int[] pushed, int[] popped) {
    Deque<Integer> stack = new LinkedList<>();
    int j = 0;
    for (int i = 0; i < pushed.length; i++) {
      while (!stack.isEmpty() && popped[j] == stack.peek()) {
    return stack.isEmpty();

C++ Solution:

class Solution {
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> st; // Create a stack
        int j = 0; // Intialise one pointer pointing on popped array
        for(auto val : pushed){
            st.push(val); // insert the values in stack
            while(st.size() > 0 && == popped[j]){ // if st.peek() values equal to popped[j];
                st.pop(); // then pop out
                j++; // increment j
        return st.size() == 0; // check if stack is empty return true else false

Complexity Analysis for Validate Stack Sequences LeetCode Solution:

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Palindrome using Recursion2632
3Java program to find the number of Nodes in a Binary Tree2545
4Reverse a string without affecting special characters2529
5Delete a node of a linked list at given position2024
6Quick Sort1773
7Insert nodes in a linked list in a sorted way (Ascending Order)1713
8Find elements pair from array whose sum equal to number1691
9Sort Elements by Frequency of Occurrences1673
10Write a program to print all permutations of a given string1658
11Find Minimum Distance Between Two Numbers in an Array1521
12Create a Doubly Linked List1484
13Reverse an Array1466
14Smallest window in a string containing all characters of another string1441
15Recursively remove all adjacent duplicates1412
16Find a Triplet That Sum to a Given Value1395
17First Repeating Element1387
18Sum of numbers in String1368
19Arrange Even and Odd number such that Odd comes after Even1358
20Smallest Positive Number Missing in an Unsorted Array1327
21Check if the Elements of an Array are Consecutive1294
22Detect a loop in the Linked List1274
23Largest Sum Contiguous Subarray1265
24Quick Sort on SIngly Linked List1261
25Print all Possible Combinations of R Elements in a given Array of size N1253
26Recursive function to do substring search1253
27Subarray with Given Sum1250
28Find the Maximum Repeating Number in Array1208
29Find the First and Second Smallest Elements1157
30Binary Tree Level order traversal in Java1156
31Check if two linked lists are identical1145
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1116
34Find Leaders in an Array1095
35Swap nodes in the linked list1088
36Find the Number Occurring Odd Number of Times in an Array1037
37Find the second most frequent character1036
38Arrange given Numbers to Form the Biggest Number II1028
39Given a string find its first non-repeating character1018
40Find Triplet in Array With a Given Sum1004
41Given a sorted array and a number x, find the pair in array whose sum is closest to x997
42A Program to check if strings are rotations of each other or not993
43Total number of occurrences of a given item in the linked list991
44Print all possible words from phone digits977
45Find the Missing Number968
46Rearrange Positive and Negative Numbers Alternatively in Array954
47Longest Palindromic Substring948
48Segregate even and odd nodes in a linked list939
49Print Longest common subsequence928
50Transform one string to another using minimum number of given operations917
51Union and Intersection of Two Linked Lists906
52Check rearranged string can form a palindrome900
53Rearrange given Array in Maximum Minimum Form879
54Iterative Implementation of Quick Sort871
55Count Possible Triangles860
56Insertion Sort858
57Multiplication of Two Matrices847
58Count of Triplets With Sum Less than Given Value833
59Stock Buy Sell to Maximize Profit831
60Check if the linked list is palindrome830
61Rotate a Linked List829
62Concatenation of two strings808
63Count Number of Substrings with K Distinct Character’s800
64Tug of War799
65Print all duplicates in the input string799
66Find Nearest Greater and Smaller Element788
67Reverse String Without Temporary Variable779
68Remove ‘b’ and ‘ac’ from a given string772
69Find Pythagorean Triplets from Array772
70The Celebrity Problem772
71Find all Common Elements in Given Three Sorted Arrays766
72Remove all duplicates in an unsorted linked list742
73Remove Minimum Characters so that Two Strings Become Anagrams740
74Find the subarray whose sum is equal to a given number X739
75Find the Row with Maximum Number of 1’s739
76Find the Peak Element from an Array737
77Addition of Two Matrices731
78Generate all Binary Strings Without Consecutive 1’s728
79Find Smallest Missing Number in a Sorted Array727
80A Product Array Puzzle725
81Maximum Sum of Non Consecutive Elements713
82Implement Two Stacks in an Array709
83Lexicographic rank of string702
84Check if Two given Matrices are Identical693
85Maximum Product Subarray II690
86Multiplication of Previous and Next684
87Subtraction of Two Matrices678
88Merge K Sorted Arrays and Print Sorted Output671
89Move All the Zeros to the End of the Given Array668
90Divide a string in N equal parts667
91Online Algorithm for Checking Palindrome in a Stream667
92Form Minimum Number from Given Sequence of D’s and I’s666
93Check whether two strings are anagram of each other661
94Remove recurring digits in a given number659
95Sort a stack using a temporary stack657
96Maximum Circular Subarray Sum652
97Sort a linked list that is sorted alternating ascending and descending647
98Subarray and Subsequence640
99Find the Minimum Element in a Sorted and Rotated Array639
100Move last element of the Linked List at first place637
101First Circular Tour to Visit all the Petrol Bunks635
1023Sum Leetcode Solution635
103Palindrome Permutations of a String631
104Compare two strings(linked lists)631
105Maximum Element in an Array which is Increasing and then Decreasing629
106Largest Subarray with Equal Number of 0’s and 1’s627
107Palindromes in a given range625
108Flattening a linked list624
109Run length encoding620
110Minimum insertions to form a shortest palindrome620
111Pangram Checking619
112Majority Element619
113Print all permutations with repetition617
114Elements Appear more than N/K times in Array612
115Minimum Characters to be Added at Front to Make String Palindrome612
116Most repeating character in a string609
117Two Sum Leetcode Solution607
118Repeated Subsequence of Length Two or More607
119Rotate string to get lexicographically minimum string604
120Merge a linked list into another at alternate positions597
121Rearrange a given linked list in-place597
122Remove all duplicates in a sorted linked list597
123Print all anagrams together in a sequence of words595
124Minimum number of Merge Operations to make an Array Palindrome595
125Reorder an Array According to the Given Indexes583
126Pancake Sorting Problem582
127Transpose of a Matrix571
128Merge Overlapping Intervals II570
129Smallest Palindrome after Replacement570
130Remove duplicates from a string568
131Longest Palindrome can be Formed by Removing or Rearranging Characters568
132Clone a Linked List with next and random pointer568
133Remove Extra Spaces from a String566
134Removing Spaces from a String using stringstream564
135Check if a given string is a rotation of a palindrome561
136Maximum Sum Increasing Subsequence560
137Size of The Subarray With Maximum Sum559
138Partition Problem556
139Check whether Strings are K Distance Apart or Not550
140Generate all Binary Strings from Given Pattern547
141Delete Last Occurrence546
142Length of Longest valid Substring543
143Check if Two given Strings are Isomorphic to each other541
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized539
145Program to Toggle all Characters in a String533
146Insert Node in the Sorted Linked List533
147Given string is interleaving of two other strings or not528
148Maximum difference between two elements such as larger element comes after smaller527
149Check length of a String is Equal to the Number Appended at its Last518
150Count Minimum Steps to Get the given Array516
151Check if all Rows of a Matrix are Circular Rotations of Each Other514
152Number of Smaller Elements on Right Side512
153Find Pair with Given Difference509
154Longest Common Prefix using Divide and Conquer509
155Merge sort better than quick sort for linked lists506
156Compare Two Version Numbers504
157Print all interleavings of given two strings502
158Find nth node of the Linked list from the end501
159Sort 0s 1s and 2s in an Array499
160Find a Fixed Point in a Given Array498
161Print Reverse of a string (Recursion)498
162Median of Two Sorted Arrays LeetCode Solution497
163Reorder Array Using Given Indexes495
164Reverse words in a given string494
165Merge two sorted linked lists such that merged list is in reverse order487
166Find the Subarray of given length with Least Average486
167Split linked list using alternate nodes485
168Print all Palindromic Partitions of a String479
169Print string of odd length in ‘X’ format478
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average468
172Swap Kth Node from beginning with Kth Node from End466
173Find Duplicates in an Array in Most Efficient Way464
174Shortest Superstring Problem459
175Check if String Follows Order of Characters by a Pattern or not458
176print all palindromic partitions457
177Maximum Length of Chain Pairs451
178Sort a String According to Another String450
179Flatten a multilevel linked list447
180Sorting a K Sorted Array443
181Program to add two binary digits439
182Caesar Cipher434
183Recursively print all the sentences that can be formed from list of word lists434
184Find a Sorted Subsequence of size 3430
185Longest Common Prefix Using Binary Search II429
186Longest Span with same Sum in two Binary Arrays II429
187Reverse a Linked List in groups429
188Find the two Numbers with Odd Occurrences in an Unsorted Array428
189Kth Non-repeating Character426
190Reverse a Singly Linked List (Iterative/Non-Recursive)424
191Check if String can Become Empty by Recursively Deleting given Substring421
192Longest Common Prefix Word by Word Matching416
193Rearrange a linked list in Zig-Zag412
194Rotate Image by 90 degrees410
195Pancake Sorting409
196Permutations of a Given String Using STL408
197Perfect Reversible String408
198Merging Two Sorted Arrays407
199Find First non-repeating character in a string406
2001`s and 2`s complement of binary number402
201Maximum occurring character in a string402
202Increasing Subsequence of Length three with Maximum Product399
203List items containing all characters of a given word397
204Find the point where a monotonically increasing function becomes positive first time396
205Four Elements that Sum to Given392
206Sort a linked list with 0s, 1s and 2s390
207Longest Common Prefix using Character by Character Matching390
208Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes389
209Count Number of Occurrences in a Sorted Array386
210Valid Parentheses LeetCode Solution386
211Palindrome string (number)386
212Delete N nodes after M382
213Minimum Characters to be Removed to Make a Binary String Alternate381
214Even Substring Count380
215Split a string378
216Recursive Implementation of atoi()377
217Sorting the array of strings375
218Convert a String that is Repetition of a Substring of Length K371
219Print Shortest Path to Print a String on Screen371
220Nth Character in Concatenated Decimal String368
221Check if a Linked list of Strings form a Palindrome367
222Maximum Subarray Leetcode Solution366
223Convert string1 to string2 in one edit364
224Print All Distinct Elements of the Array362
225Reverse a String using Stack362
226Count the number of words362
227wildcard character matching361
228Reverse a singly linked list recursively361
229Find the first Repeating Number in a Given Array360
230Matrix Chain Multiplication using Dynamic Programming360
231Lower Case To Upper Case356
232Can we reverse a linked list in less than O(n) time ?353
233Binary Tree to Doubly linked list350
234Sort Elements by Frequency II349
235Longest Common Subsequence with Permutations348
236Find the Lost Element From a Duplicated Array346
237Split Four Distinct Strings344
238Merge Two Sorted Arrays343
239Roman to Integer Leetcode Solution340
240Find middle of the Linked List339
241Move all negative elements to one side of array339
242Count the Pairs at Same Distance as in English Alphabets338
243Toeplitz Matrix335
244N queen problem332
245Palindrome Permutation330
246Word Search Leetcode Solution327
247Next Greater Element in an Array326
248Sudoku Solver325
249First non Repeating Element322
250Find All Pairs With a Given Difference320
251Reverse Bits319
252Count Pairs With Given Sum319
253Print all Possible Ways to Break a String in Bracket Form318
254Searching a node in a Binary Search Tree318
255Fibonacci numbers317
256Number of Islands LeetCode Solution317
257String(represents an integer) to value317
258Find Nth Node317
259Repeated Substring Pattern315
260Types of Binary Tree314
261Reverse a String314
262Change Gender of a given String314
263Triplet from three linked lists with given sum313
264Reverse a linked list312
265Sort an array of strings312
266How to Efficiently Implement k Stacks in a Single Array?311
267Delete a Tree311
268Min Stack311
269Most Frequent Element in an Array310
270Number of sub-strings which recursively add up to 9310
271Meeting Rooms II LeetCode Solution309
272Delete a node under given conditions309
273Longest Palindromic Substring LeetCode Solution308
274Cuckoo sequence program308
275Dijkstra Algorithm305
276Remove spaces from a string304
277Longest Common Extension302
278Max stack301
279House Robber Leetcode Solution301
280Binary Tree301
281Word Search295
282Subset Leetcode295
283Sliding Window Technique294
284Best Time to Buy and Sell Stock  II Leetcode Solution293
285Shuffle a given Array292
286Remove middle points in a linked list of line segments292
287Minimize the maximum difference between the heights290
288Number Of 1 bits290
289KMP Algorithm290
290Expression Evaluation289
291Find, second, frequent, character289
292Plus One Leetcode Solution288
293Search Insert Position Leetcode Solution287
294Pair of Positive Negative Values in an Array286
295Evaluation of Postfix Expression286
296Combination Sum Leetcode Solution286
297Reverse words in a string285
298Min Stack Leetcode Solution280
299Set Matrix Zeroes279
300Rabin Karp Algorithm279
301Valid Palindrome Leetcode Solution279
302Subarray with 0 sum279
303Backspace String Compare278
304Common elements in all rows of a given matrix276
305Sort linked which is sorted on absolute values275
306Clone a linked list with next and random pointer (Hashing)272
307Merge Sorted Arrays Leetcode Solution272
308Sqrt(x) Leetcode Solution271
309Reversing a Queue271
310Delete middle element of a stack270
311Find Top K (or Most Frequent) Numbers in a Stream270
312Contains Duplicate270
313Implementation of Deque using Doubly Linked List270
314Tower Of Hanoi269
315Count Odd Numbers in an Interval Range Leetcode Solution268
316Count subarrays with equal number of 1’s and 0’s268
317String Compression267
318Product of array except self266
319Combination Sum266
320Intersection of Two Arrays II Leetcode Solution266
321Contains Duplicate II Leetcode Solution265
322How to Delete a Linked List265
323Pascal Triangle Leetcode265
324Page Replacement Algorithms in Operating Systems265
325Count of index pairs with equal elements in an array265
326Reverse individual words265
327Minimum swaps required to bring all elements less than or equal to k together264
328Segregate even and odd numbers263
329Find sum of non-repeating elements (distinct) elements in an array262
330Single Number Leetcode Solution262
331Second Most Repeated Word in a Sequence262
332Group Words With Same Set of Characters262
333Count subarrays having total distinct elements same as original array261
334Integer to Roman Leetcode Solution261
335Sum of minimum and maximum elements of all subarrays of size k260
336Postfix to Infix Conversion260
337Given two unsorted arrays find all pairs whose sum is x260
338Smallest Subarray with k Distinct Numbers260
339Bellman Ford Algorithm260
340Minimum Value to Get Positive Step by Step Sum Leetcode Solution259
341Sorting array using Stacks259
342Sort elements by frequency259
343Next Permutation259
344Arithmetic Expression Evaluation258
345K-th Smallest Element in a Sorted Matrix258
346Top K Frequent Words256
347Convex Hull Algorithm256
348First element occurring k times in an array256
349Add Binary Leetcode Solution256
350Construct Binary Tree from Given Inorder and Preorder Traversals255
351Minimum operation to make all elements equal in array255
352Maximum Number of Balloons Leetcode Solution255
353Design a stack that supports getMin() in O(1) time and O(1) extra space254
354Longest Common Prefix Leetcode Solution254
355Pow(x, n) Leetcode Solution253
356Scramble String253
357Longest Substring Without Repeating Characters LeetCode Solution253
358Palindrome Linked List Leetcode Solution252
359Special Number252
360Majority Element Leetcode Solution250
361Reversing the First K elements of a Queue250
362Evaluate Division250
363Kruskal Algorithm250
364Find Lucky Integer in an Array Leetcode Solution250
365Find duplicates in a given array when elements are not limited to a range250
366Check if two arrays are equal or not250
367Permutations Leetcode Solution248
368Running Sum of 1d Array Leetcode Solution248
369Third Maximum Number Leetcode Solution247
370Maximum possible difference of two subsets of an array247
371Fizz Buzz Leetcode245
372Maximum Distance Between two Occurrences of Same Element in Array245
373Smallest Element Repeated Exactly K Times245
374Spiral Matrix LeetCode Solution245
375Huffman Coding245
376Minimum Path Sum245
377Number of Good Pairs Leetcode Solution244
378Find the first repeating element in an array of integers244
379Find the Town Judge Leetcode Solution244
380Maximum Subarray244
381Group Anagrams244
382Prefix to Infix Conversion244
383Maximal Square244
384Range Sum Query 2D – Immutable Leetcode Solution243
385Reverse a Number Using Stack243
386Find Numbers with Even Number of Digits Leetcode Solution243
387Find the Closest Palindrome number243
388Convert String To Int243
389Minimum Steps to reach target by a Knight242
390Swap Nodes in Pairs Leetcode Solutions242
391Palindrome Substring Queries242
392Cumulative Frequency of Count of Each Element in an Unsorted Array241
393Minimum Absolute Difference Leetcode Solution241
394Count Primes Leetcode Solutions241
395Find top three repeated in array241
396Sorting using trivial hash function241
397Unique Paths241
398Zigzag Conversion240
399Single Number240
400Find All Numbers Disappeared in an Array Leetcode Solution240
401Remove Minimum Number of Elements Such That no Common Element Exist in both Array239
402Print all subarrays with 0 sum239
403Find Number of Employees Under every Employee239
404Check if Array Contains Contiguous Integers With Duplicates Allowed238
405Pascal’s Triangle II Leetcode Solution238
406Sort Array by Increasing Frequency Leetcode Solution238
407Implement Stack and Queue using Deque238
408Expression Contains Redundant Bracket or Not238
409Fizz Buzz238
410Leetcode Permutations237
411How to Implement Stack Using Priority Queue or Heap?237
412Difference between highest and least frequencies in an array237
413Power of Two Leetcode Solution237
414Bipartite Graph237
415Count Substrings with equal number of 0s, 1s and 2s237
416Print All Distinct Elements of a Given Integer Array237
417Missing Number Leetcode Solution236
418Length of the largest subarray with contiguous elements236
419Subarray Sum Equals k236
420Letter Case Permutation236
421Matrix Diagonal Sum Leetcode Solution236
422Merge Two Sorted Lists Leetcode Solutions235
423Unique Paths Leetcode Solution235
424Decode String235
425LRU Cache Implementation235
426Prim’s Algorithm235
427Sort a stack using recursion235
428Subset sum problem235
429Sort Integers by The Number of 1 Bit Leetcode Solution235
430House Robber II Leetcode Solution234
431Maximum Depth of Binary Tree Leetcode Solution234
432Subarrays with distinct elements233
433Top K Frequent Elements233
434Happy Number Leetcode Solution233
435Reverse Integer233
436Find all pairs (a, b) in an array such that a % b = k233
437Find Median from data Stream233
438Nth Catalan Number232
439Search in Rotated Sorted Array Leetcode Solution232
440Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution231
441Find Winner on a Tic Tac Toe Game Leetcode Solution231
442Count pairs from two linked lists whose sum is equal to a given value231
443Coin Change 2 Leetcode Solution231
444Max Consecutive Ones Leetcode Solution230
445Monotonic Array LeetCode Solution230
446Pair with given product230
447Capacity To Ship Packages Within D Days Leetcode Solution229
448Find elements which are present in first array and not in second229
449Check If N and Its Double Exist Leetcode Solution229
450How Many Numbers Are Smaller Than the Current Number Leetcode Solution229
451Find The Duplicate Number228
452Reverse a String228
453Valid Parenthesis String228
454Integer to English words228
455Priority Queue Using Singly Linked List228
456Reverse a Stack Using Recursion228
457Find the Difference Leetcode Solution228
458Intersection of Two Arrays228
459Edit Distance228
460Find any one of the multiple repeating elements in read only array227
461Find Minimum In Rotated Sorted Array227
462Find distinct elements common to all rows of a matrix227
463Longest subarray not having more than K distinct elements227
464Find Index of Closing Bracket for a Given Opening Bracket in an Expression227
465Floyd Warshall Algorithm227
466Count and Say227
467Subarray Sum Equals K LeetCode Solution227
468Trapping Rain Water Leetcode Solution227
469Find Common Characters Leetcode Solution227
470Subtract the Product and Sum of Digits of an Integer Leetcode Solution227
471Fibonacci Number LeetCode Solution227
472Text Justification LeetCode Solution226
473Sum of Subarray Ranges Leetcode Solution226
474Reverse Vowels of a String Leetcode Solution226
475Find four elements that sum to a given value (Hashmap)226
476Longest Common Prefix using Trie225
477Check if a given array contains duplicate elements within k distance from each other225
478Rearrange a binary string as alternate x and y occurrences225
479Best Time to Buy and Sell Stock III Leetcode Solution225
480Remove Duplicates from Sorted Array Leetcode Solution224
481Target Sum224
482The K Weakest Rows in a Matrix Leetcode Solution224
483Kth largest element in an Array Leetcode Solutions224
484Design Parking System Leetcode Solution224
485Generate a String With Characters That Have Odd Counts Leetcode Solution224
486Jump Game Leetcode Solution224
487MiniMax Algorithm223
488The Stock Span Problem223
489Delete a Node from linked list without head pointer223
490Check for Balanced Parentheses in an Expression223
491Find subarray with given sum (Handles Negative Numbers)223
492Find missing elements of a range222
493Largest Sum Contiguous Subarray222
494Iterative Tower of Hanoi222
495Prefix to Postfix Conversion222
496Multiply Strings Leetcode Solution222
497Shortest Palindrome222
498Substring With Concatenation Of All Words221
499Count number of triplets with product equal to given number221
500Iterative Inorder Traversal of a Binary Tree220
501Top View of Binary Tree220
502Longest Common Prefix using Sorting220
503Word Ladder LeetCode Solution220
504K-th Distinct Element in an Array220
505Degree of an array220
506Priority Queue in C++220
507Valid Sudoku220
508Shuffle the Array Leetcode Solution220
509Sorting a Queue without Extra Space220
510Shuffle String Leetcode Solution220
511Container with Most Water219
512Max Area of Island219
513Implement Stack using Queues219
514Slowest Key Leetcode Solution219
515Minimum Knight Moves LeetCode Solution219
517Number of Steps to Reduce a Number to Zero Leetcode Solution219
518Balanced Binary Tree Leetcode Solution219
519Flood Fill LeetCode219
520Peak Index in a Mountain Array219
521Best Time to Buy and Sell Stock LeetCode Solution218
522Next Greater Element I Leetcode Solution218
523Next Greater Frequency Element218
524Excel Sheet Column Number Leetcode Solution218
525Implement a stack using single queue218
526Kids With the Greatest Number of Candies Leetcode Solution218
527Merge Two Sorted Linked Lists218
528Hamming Distance217
529Count and Say Leetcode Solution217
530Maximum sum rectangle in a 2D matrix217
531Find First and Last Position of Element in Sorted Array Leetcode Solution217
532Postfix to Prefix Conversion217
533Minimum Delete Operations to make all Elements of Array Same217
534Arrange given numbers to form the biggest number217
535Move Zeroes LeetCode Solution217
536Longest Common Subsequence217
537Sum of Left Leaves Leetcode Solutions217
538Convert array into Zig-Zag fashion217
539Concatenation of Array LeetCode Solution217
540Jewels and Stones Leetcode Solution217
541Find the Duplicate Element217
542Reverse Words in a String III LeetCode Solution217
543Smallest Subarray With all Occurrences of a Most Frequent Element217
544Find Sum of all unique sub-array sum for a given array216
545Linked List Cycle II LeetCode Solution216
546How to check if two given sets are disjoint?216
547Change the Array into Permutation of Numbers From 1 to N216
548Kth Largest Element in a Stream Leetcode Solution215
549Shuffle an Array215
550Count the number of nodes at given level in a tree using BFS215
551Check if a queue can be sorted into another queue using a stack215
552Minimum Moves to Equal Array Elements Leetcode Solution215
553Gold Mine Problem214
554Valid Anagrams214
555Largest Perimeter Triangle Leetcode Solution214
556N-th Tribonacci Number Leetcode Solution214
557Zigzag Conversion LeetCode Solution214
558Group Multiple Occurrence of Array Elements Ordered by first Occurrence214
559Contiguous Array Leetcode213
560Convert a normal BST to Balanced BST213
561Merge Overlapping Intervals213
562Isomorphic Strings Leetcode Solution213
563Find N Unique Integers Sum up to Zero Leetcode Solution212
564Minimum number of subsets with distinct elements212
565Sieve of Eratosthenes212
566Delete Node in a Linked List Leetcode Solution212
567Excel Sheet Column Title Leetcode Solution212
568Is Subsequence Leetcode Solution212
569Minimum Bracket Reversals212
570Summary Ranges Leetcode Solution211
571Maximum Distance in Array211
572Last Stone Weight211
573Minimum Cost to Hire K Workers211
574Integer to Roman211
575Find if an Expression has Duplicate Parenthesis or Not211
576Koko Eating Bananas Leetcode Solution210
577Smallest Good Base210
578Mobile Numeric Keypad Problem210
579Word Pattern210
580Maximum path sum in a triangle210
581Number of Provinces Leetcode Solution209
5823Sum Closest LeetCode Solution209
583Maximum difference between first and last indexes of an element in array209
584Shortest Path in a Grid with Obstacles Elimination LeetCode Solution209
585Best Time to Buy and Sell Stock209
586Implementation of Deque using circular array209
587Non-overlapping sum of two sets209
588Length of Last Word Leetcode Solution209
589Longest Increasing Subsequence209
590Build Array From Permutation Leetcode Solution209
591Combinations Leetcode Solution208
592Maximum Number of Occurrences of a Substring Leetcode Solution208
593Find Words That Can Be Formed by Characters Leetcode Solution208
594Relative Sort Array Leetcode Solution208
595Distribute Candies to People Leetcode Solution208
596Frog Jump Leetcode Solution208
597Decode Ways208
598Delete consecutive same words in a sequence208
59901 Matrix LeetCode Solution207
600Island Perimeter Leetcode Solution207
601First negative integer in every window of size k207
602Sort Characters By Frequency LeetCode Solution207
603Minimum Operations to convert X to Y207
604Trapping Rain Water LeetCode Solution207
605Remove All Occurrences of a Substring LeetCode Solution207
606Iterative Method to find Height of Binary Tree207
607Rotate Image LeetCode Solution207
608LRU Cache LeetCode Solution206
609Sum of f(a[i], a[j]) over all pairs in an array of n integers206
610Remove Linked List Elements Leetcode Solution206
611The Knapsack Problem205
612Minimum number of distinct elements after removing m items205
613GCD Of Two Numbers205
614Find minimum difference between any two elements205
615Reverse a stack without using extra space in O(n)205
616Maximum Number of Chocolates to be Distributed Equally Among k Students205
617Minimum insertions to form a palindrome with permutations allowed205
618Bubble sort using two Stacks204
619Count all subsequences having product less than K204
620Rotate List Leetcode Solution204
621XOR Operation in an Array Leetcode Solution204
622Assign Cookies Leetcode Solution204
623Find the smallest positive integer value that cannot be represented as sum of any subset of a given array204
624Insert Interval Leetcode Solution203
625How to Create Mergable Stack?203
626Unique Binary Search Trees203
627Convert an array to reduced form203
628Tracking current Maximum Element in a Stack203
629Isomorphic Strings203
630Reorganize String203
631Permutation in String Leetcode Solution203
632K Empty Slots202
633Find Largest d in Array such that a + b + c = d202
634Find the Duplicate Number LeetCode Solution202
635Longest Increasing Path in a Matrix LeetCode Solution202
636Form minimum number from given sequence202
637Convert Sorted Array to Binary Search Tree Leetcode Solution202
638Stone Game LeetCode202
639Distance Between Bus Stops Leetcode Solution201
640Defanging an IP Address Leetcode Solution201
641Same Tree LeetCode Solution201
642Employee Free Time LeetCode Solution201
643Largest subarray with equal number of 0s and 1s201
644Applications of Breadth First Search and Depth First Search201
645Find Pair with Greatest Product in Array201
646Count Good Nodes in Binary Tree Leetcode Solution200
647License Key Formatting Leetcode Solution200
648Find the node with minimum value in a Binary Search Tree200
649First Unique Character in a String LeetCode Solution200
650Optimal Account Balancing LeetCode Solution200
651Word Wrap Problem199
652Letter Combinations of a Phone Number199
653Merge Two Balanced Binary Search Trees199
654Printing brackets in Matrix Chain Multiplication Problem199
655Convert a Number to Hexadecimal Leetcode Solution199
656Coin Change Problem199
657Maximum Consecutive Numbers Present in an Array199
658Valid Palindrome199
659Minimum Depth of Binary Tree Leetcode Solution199
660Replace Elements with Greatest Element on Right Side Leetcode Solution198
661Find pairs with given sum such that elements of pair are in different rows198
662Robot Room Cleaner Leetcode Solution198
663Longest Span with same Sum in two Binary arrays198
664Find the Distance Value Between Two Arrays Leetcode Solution197
665Numbers with prime frequencies greater than or equal to k197
666Painting Fence Algorithm197
667K Empty Slots LeetCode197
668Kth Missing Positive Number Leetcode Solution197
669Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions197
670Flipping an Image LeetCode Solution197
671House Robber197
672Sort Array By Parity LeetCode Solution197
673Check If It Is a Straight Line Leetcode Solution197
674Longest Substring with At Most K Distinct Characters LeetCode Solution197
675String to Integer (atoi) LeetCode Solution196
676Distance of nearest cell having 1 in a binary matrix196
677Strobogrammatic Number LeetCode Solution196
678Count quadruples from four sorted arrays whose sum is equal to a given value x196
679Maximum Product of Two Elements in an Array Leetcode Solution196
680Moving Average from Data Stream Leetcode Solution196
681Reservoir Sampling196
682k-th missing element in increasing sequence which is not present in a given sequence196
683Partition Labels LeetCode Solution196
684Segregate 0s and 1s in an Array196
685Number of Dice Rolls With Target Sum LeetCode Solution196
686Reducing Dishes LeetCode Solution196
687Print the Fibonacci numbers in reverse order195
688Valid Palindrome II Leetcode Solution195
689Power of Four Leetcode Solution195
690Longest Substring with At Least K Repeating Characters LeetCode Solution195
691Generate all possible sorted arrays from alternate elements of two given sorted arrays195
692String Compression LeetCode Solution195
693Partition Array Into Three Parts With Equal Sum Leetcode Solution194
694Reverse Only Letters LeetCode Solution194
695Find unique character in a string194
696Dynamic Programming Basics194
697Find Maximum Level sum in Binary Tree194
698Find Leaves of Binary Tree LeetCode Solution194
699Queries for counts of array elements with values in given range194
700Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
701Find whether an array is subset of another array193
702Binary Tree Maximum Path Sum LeetCode Solution193
703Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest193
704Sum of All Odd Length Subarrays Leetcode Solution193
705Snakes and Ladders LeetCode Solution193
706Increasing Decreasing String Leetcode Solution193
707Find the largest multiple of 3193
708Elements to be added so that all elements of a range are present in array192
709Growable array based stack192
710Stack Permutations (Check if an array is stack permutation of other)192
711Wiggle Sort192
712Remove brackets from an algebraic string containing + and – operators192
713Remove Invalid Parentheses Leetcode Solution192
714To Lower Case Leetcode Solution192
715Check for Palindrome after every character replacement Query192
716Find the Smallest Divisor given a Threshold Leetcode Solution192
717Unique Paths II Leetcode Solution192
718Check If Two String Arrays are Equivalent Leetcode Solution192
719Path With Maximum Minimum Value LeetCode Solution192
720Valid Perfect Square Leetcode Solution191
721Binary Tree zigzag level order Traversal191
722Edit Distance LeetCode Solution191
723Keyboard Row Leetcode Solution191
724Sort Array by Increasing Frequency Leetcode Solution191
725Maximum Number of Coins You Can Get Leetcode Solution191
726Bulb Switcher LeetCode Solution191
727Inorder Successor of a node in Binary Tree191
728Populating Next Right Pointers in Each Node191
729Lucky Numbers in a Matrix Leetcode Solution191
730Find Maximum Depth of Nested Parenthesis in a String191
731BFS vs DFS for Binary Tree190
732Permutation Sequence LeetCode Solution190
733Race Car LeetCode Solution190
734Base 7 Leetcode Solution190
735Minimum Cost For Tickets Leetcode Solution190
736Merge Sorted Array LeetCode Solution190
737String comparison containing wildcards190
738Recover Binary Search Tree190
739Merge Two Binary Trees LeetCode Solution190
740Valid Number190
741Non-decreasing Array LeetCode Solution190
742Ugly Number Leetcode Solution190
743Subset Sum Leetcode190
744Reversing a Queue using Recursion190
745Majority Element II Leetcode Solution190
746Factorial Trailing Zeroes Leetcode Solution190
747Delete Nth node from the end of the given linked list190
748Binary Tree Zigzag Level Order Traversal LeetCode Solution190
749Number of NGEs to the Right190
750Perform String Shifts Leetcode189
751Print a Binary Tree in Vertical Order189
752Maximum Length of a Concatenated String with Unique Characters Leetcode Solution189
753Tiling Problem189
754Find if Path Exists in Graph Leetcode Solution189
755Priority Queue using doubly linked list189
756Program for Bridge and Torch problem188
757Check if Two Expressions With Brackets are Same188
758Minimum sum of multiplications of n numbers188
759Maximum 69 Number Leetcode Solution188
760Best Meeting Point LeetCode Solution188
761Regular Expression Matching188
762Restore IP Addresses Leetcode Solution188
763Morris Traversal188
764Finding K closest element188
765Count items common to both the lists but with different prices188
766Student Attendance Record I Leetcode Solution188
767Maximum Profit in Job Scheduling Leetcode Solution188
768Longest Subarray Having Count of 1s One More than Count of 0s188
769Split a String in Balanced Strings Leetcode Solution187
770Maximum Product of Three Numbers LeetCode Solution187
771Circular Queue187
772Word Pattern LeetCode Solution187
773Add and Search Word – Data structure design LeetCode187
774Construct BST from given Preorder Traversal187
775Number of Days Between Two Dates LeetCode Solution187
776Evaluate Reverse Polish Notation LeetCode Solution187
777Partition to K Equal Sum Subsets Leetcode Solution187
778Minimum Distance Between BST Nodes Leetcode Solution187
779Find All Duplicates in an Array LeetCode Solution186
780Rank Transform of an Array Leetcode Solution186
781Symmetric Tree Leetcode Solution186
782Sort an array according to the order defined by another array186
783Largest Rectangle in Histogram LeetCode Solution186
784N-Queens LeetCode Solution186
785Find Median from Data Stream LeetCode Solution186
786Top K Frequent Words LeetCode Solution186
787Minimum Height Trees186
788Check If Array Pairs Are Divisible by k LeetCode Solution186
789Decompress Run-Length Encoded List Leetcode Solution186
790Form Minimum Number From Given Sequence186
791Jump Game186
792Binomial Coefficient186
793Minimum Time Visiting All Points Leetcode Solution186
794Hamming Distance Leetcode Solution186
795Find All Possible Recipes from Given Supplies LeetCode Solution185
796Sorted Linked List to Balanced BST185
797Brick Wall LeetCode Solution185
798Minimize Maximum Pair Sum in Array LeetCode Solution185
799Invert Binary Tree LeetCode Solution185
800Nested List Weight Sum II LeetCode Solution185
801Maximum Depth of N-ary Tree Leetcode Solution185
802Total Numbers With no Repeated Digits in a Range184
803Merge K Sorted Linked Lists184
804Linked List Cycle184
805Queue based approach for first non-repeating character in a stream184
806Maximum Nesting Depth of the Parentheses Leetcode Solution184
807Search in a Binary Search Tree Leetcode Solution184
808Special Array With X Elements Greater Than or Equal X Leetcode Solution184
809Find all permuted rows of a given row in a matrix184
810Identify and Mark Unmatched Parenthesis in an Expression184
811Remove Nth Node From End of List Leetcode Solution183
812Number of Islands II LeetCode Solution183
813Crawler Log Folder Leetcode Solution183
814Kth ancestor of a node in binary tree183
815Largest rectangular sub-matrix whose sum is 0183
816Balanced Expression with Replacement183
817Nearest Exit from Entrance in Maze LeetCode Solution183
818Minimum Swaps to Make Strings Equal Leetcode Solution182
819Repeated Substring Pattern LeetCode Solution182
820Relative Ranks Leetcode Solution182
821Given an Array of Pairs Find all Symmetric Pairs in it182
822Split Array Into Consecutive Subsequences182
823Interval Tree182
824Minimum time required to rot all oranges182
825Course Schedule II – LeetCode182
826Diagonal Traversal of Binary Tree182
827Transpose Graph182
828One Edit Distance LeetCode Solution182
829Maximum Difference Between Increasing Elements LeetCode Solution182
830A Space Optimized DP solution for 0-1 Knapsack Problem181
831Brightest Position on Street LeetCode Solution181
832Insert Delete GetRandom181
833Minimum Number of Taps to Open to Water a Garden LeetCode Solution181
834Final Prices With a Special Discount in a Shop Leetcode Solution181
835Deletion in a Binary Tree181
836Permutation Coefficient181
837Find Maximum Sum Possible Equal Sum of Three Stacks181
838Lemonade Change Leetcode Solution180
839Last Stone Weight II LeetCode Solution180
840Tree Traversal (Preorder, Inorder & Postorder)180
841Subsequence of Size K With the Largest Even Sum LeetCode Solution180
842Reorder Data in Log Files LeetCode Solution180
843Search a 2D Matrix II Leetcode Solution180
844Check if stack elements are pairwise consecutive180
845Path with maximum average value180
846Remove Duplicates from Sorted List II180
847Design Browser History LeetCode Solution180
848Subarray Product Less Than K LeetCode Solution180
849Daily Temperatures Leetcode Solution179
850LCS (Longest Common Subsequence) of three strings179
851Remove Duplicates from Sorted List LeetCode Solution179
852Sort Array By Parity II Leetcode Solution179
853Sliding Window Maximum179
854Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
855Iterative Preorder Traversal179
856Iterative Postorder Traversal Using Two Stacks179
857Minimum Jumps to Reach Home LeetCode Solution179
858Check if an Array is Stack Sortable179
859Distinct adjacent elements in an array179
860Binary Search Tree Search and Insertion179
861Clone Graph LeetCode Solution179
862Valid Parentheses Leetcode Solution179
863Missing Element in Sorted Array LeetCode Solution179
864Check if a given array can represent Preorder Traversal of Binary Search Tree179
865Find the Only Repetitive Element Between 1 to N-1179
866Minimum Sum Path in a Triangle179
867Least Number of Unique Integers after K Removals Leetcode Solution179
868Number Complement Leetcode Solution179
869Median of Two Sorted Arrays178
870Matrix Chain Multiplication178
871Guess Number Higher or Lower LeetCode Solution178
872Sum of nearest smaller and greater number178
873Can Place Flowers LeetCode Solution178
874Minimum number of jumps to reach end178
875Maximum Score After Splitting a String Leetcode Solution178
876Alien Dictionary LeetCode Solution178
877Range LCM Queries178
878Sort Colors178
879Spiral Matrix II Leetcode Solution178
880Union and Intersection of two Linked Lists177
881An Interesting Method to generate Binary Numbers from 1 to n177
882Get Maximum in Generated Array Leetcode Solution177
883Minimum swaps to make sequences increasing177
884Count Negative Numbers in a Sorted Matrix LeetCode Solution177
885Diagonal Traverse LeetCode Solution177
886Count Distinct Elements in Every Window of Size K177
887Dividing Array into Pairs With Sum Divisible by K177
888Find all triplets with zero sum177
889Partition List Leetcode Solution177
890Friends Pairing Problem177
891Find distance between two nodes of a Binary Tree177
892Convert BST to Min Heap177
893Maximum size subarray sum equals k177
894A program to check if a binary tree is BST or not176
895Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i176
896Minesweeper LeetCode Solution176
897Count Submatrices With All Ones LeetCode Solution176
898Design a Stack With Increment Operation Leetcode Solution176
899Count ways to reach the nth stair using step 1, 2 or 3176
900Level order Traversal in Spiral Form176
901Infix to Postfix176
902Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution176
903Find the subarray with least average176
904Sequences of given length where every element is more than or equal to twice of previous176
905Subset with sum divisible by m176
906GCDs of given index ranges in an array176
907Sorted Array to Balanced BST176
908Check whether a given Binary Tree is Complete or not176
909Diagonal Traversal LeetCode Solution176
910Check if any two intervals overlap among a given set of intervals175
911Pattern Occurrences using Stack175
912Insert into a Binary Search Tree Leetcode Solution175
913Time Based Key-Value Store LeetCode Solution175
914Binary array after M range toggle operations175
915Number of Distinct Islands Leetcode Solution175
916Water Bottles Leetcode Solution175
917Delete And Earn175
918Binary Tree Longest Consecutive Sequence LeetCode Solution174
919Destination City Leetcode Solution174
920Three way partitioning of an array around a given range174
921Construct the Rectangle Leetcode Solution174
922Convert Sorted List to Binary Search Tree174
923Range sum queries without updates174
924Guess Number Higher or Lower II174
925All Unique Triplets that Sum up to a Given Value174
926Averages of Levels in Binary Tree174
927Product of Array Except Self LeetCode Solution173
928Rearrange an Array Such that arr[i] is equal to i173
929Shortest Word Distance Leetcode Solution173
930Rearrange Spaces Between Words Leetcode Solution173
931Set Matrix Zeroes Leetcode Solution173
932Robot Bounded In Circle LeetCode Solution173
933Number of Equivalent Domino Pairs Leetcode Solution173
934Check if the given array can represent Level Order Traversal of Binary Search Tree173
935Queue using Stacks173
936Trim a Binary Search Tree173
937Lexicographical Numbers Leetcode Solution173
938K’th Largest Element in BST when modification to BST is not allowed173
939Longest Palindromic Subsequence173
940Print Fibonacci sequence using 2 variables172
941Alien Dictionary172
942Palindrome Partitioning Leetcode Solution172
943Difference Array | Range update query in O(1)172
944Special Positions in a Binary Matrix Leetcode Solution172
945Queries for GCD of all numbers of an array except elements in a given range172
946Construct Complete Binary Tree from its Linked List Representation172
947Analyze User Website Visit Pattern LeetCode Solution172
948Find Common Characters Leetcode Solution172
949Depth First Search (DFS) for a Graph171
9503 Sum171
951Intersection of Two Linked Lists LeetCode Solution171
952BFS for Disconnected Graph171
954Count Subarrays with Same Even and Odd Elements171
955Maximum Frequency Stack Leetcode Solution171
956My Calendar I LeetCode Solution171
957Spiral Matrix III LeetCode Solution171
958Construct BST from its given Level Order Traversal170
959Create Maximum Number170
960Remove Duplicates from Sorted List II LeetCode Solution170
961Maximize Sum of Array after K Negations Leetcode Solution170
962Three Consecutive Odds Leetcode Solution170
963Vertical sum in a given binary tree170
964Minimum Height Trees LeetCode Solution170
965Merge Two Sorted Lists Leetcode170
966Climbing stairs170
967Symmetric Tree170
968Count subarrays where second highest lie before highest169
969Strongly Connected Component169
970Count Primes in Ranges169
971Merging Intervals169
972Breadth First Search (BFS) for a Graph169
973Sign of the Product of an Array LeetCode Solution169
974Word Break169
975Count pair with Given Sum169
976Unique Paths II169
977Largest area rectangular sub-matrix with equal number of 1’s and 0’s169
978Longest Nice Substring LeetCode Solution168
979Stone Game II Leetcode168
980Design Hit Counter LeetCode Solution168
981Find Maximum of Minimum for Every Window Size in a Given Array168
982K maximum sums of overlapping contiguous sub-arrays168
983Maximum Subarray Sum Excluding Certain Elements168
984Reverse Nodes in K-Group168
985Combination Sum IV LeetCode Solution168
986Largest Number Leetcode Solution168
987Maximum length subsequence with difference between adjacent elements as either 0 or 1168
988Kth Smallest Element in a BST Leetcode Solution168
989Longest subsequence such that difference between adjacents is one168
990Largest Substring Between Two Equal Characters Leetcode Solution167
991Count pairs from two sorted arrays whose sum is equal to a given value x167
992Asteroid Collision LeetCode Solution167
993Valid Boomerang Leetcode Solution167
994Number of palindromic paths in a matrix167
995Maximum Product Subarray167
996Next Permutation Leetcode Solution167
997Serialize and Deserialize Binary Tree167
998Scramble String LeetCode Solution166
999Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution166
1000Length of Longest Fibonacci Subsequence166
1001Graph Valid Tree LeetCode Solution166
1002Segment Tree166
1003Print Next Greater Number of Q queries166
1004Height of a generic tree from parent array166
1005Shuffle 2n integers as without using extra space166
1006Maximum Length of Repeated Subarray166
1007Maximum difference between frequency of two elements such that element having greater frequency is also greater166
1008Find number of pairs in an array such that their XOR is 0166
1009K Closest Points to Origin Leetcode Solution166
1010String Matching in an Array Leetcode Solution166
1011Maximum Product of Indexes of Next Greater on Left and Right166
1012Can Make Arithmetic Progression From Sequence Leetcode Solution166
1013The Painter’s Partition Problem165
1014Friends Of Appropriate Ages LeetCode Solution165
1015Find the Difference Leetcode Solution165
1016Generate Parentheses Leetcode Solution165
1017Binary Search Tree Delete Operation165
1018Find postorder traversal of BST from preorder traversal165
1019Remove Duplicates from Sorted Array II Leetcode Solution165
1020The Maze III LeetCode Solution165
1021Balanced Binary Tree165
1022Collect maximum points in a grid using two traversals165
1023Palindrome Partitioning165
1024Kth Smallest Element in a Sorted Matrix LeetCode Solution165
1025Shortest Completing Word Leetcode Solution165
1026Find the First Circular Tour that visits all the Petrol Pumps165
1027Find Duplicate Subtrees164
1028Rearrange array such that even positioned are greater than odd164
1029Find a Peak Element II LeetCode Solution164
1030Newman-Conway Sequence164
1031Validate Binary Search Tree164
1032Number Of Longest Increasing Subsequence164
1033Maximum Number of Ways to Partition an Array LeetCode Solution164
1034Consecutive Characters LeetCode Solution164
1035Level Order Traversal of Binary Tree164
1036Largest divisible pairs subset164
1037Decrypt String from Alphabet to Integer Mapping Leetcode Solution164
1038Minimum Index Sum of Two Lists164
1039Binary Search Tree164
1040Boundary Traversal of binary tree164
1041Build an Array With Stack Operations Leetcode Solution164
1042Advantages of BST over Hash Table163
1043Double the first element and move zero to end163
1044Kill Process LeetCode Solution163
1045Invalid Transactions LeetCode Solution163
1046Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’163
1047Path Sum II LeetCode Solution163
1048Construct Binary Tree from given Parent Array representation163
1049Boolean Parenthesization Problem163
1050Merge Sort163
1051Move all negative elements to end in order with extra space allowed163
1052Bitwise AND of Numbers Range LeetCode Solution162
1053Construction of Longest Increasing Subsequence (N log N)162
1054Compute nCr % p162
1055Available Captures for Rook Leetcode Solution162
1056Insertion in a Binary Tree162
1057Iterative Depth First Traversal of Graph162
1058Maximum subsequence sum such that no three are consecutive162
1059Maximum Sum of 3 Non-Overlapping Subarrays162
1060Subarrays with K Different Integers Leetcode Solution161
1061Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution161
1062Make The String Great Leetcode Solution161
1063Ugly Numbers161
1064Next Greater Element III LeetCode Solution161
1065Find Three Element From Different Three Arrays Such That a + b + c = sum161
1066Count minimum steps to get the given desired array161
1067First missing positive161
1068Custom Sort String Leetcode Solution161
1069Recover Binary Search Tree Leetcode Solution160
1070Rearrange array such that even index elements are smaller and odd index elements are greater160
1071Add two numbers160
1072Find maximum difference between nearest left and right smaller elements160
1073Find Peak Element160
1074Employee Importance LeetCode Solution160
1075Lowest Common Ancestor160
1076Maximize Distance to Closest Person LeetCode Solution159
1077Maximum weight transformation of a given string159
1078Smallest Common Region Leetcode Solution159
1079Level order traversal using two Queues159
1080Super Ugly Number159
1081Partition Equal Subset Sum159
1082Minimum Size Subarray Sum159
1083Regular Expression Matching Regular Expression Matching LeetCode Solution159
1084Print Right View of a Binary Tree159
1085Number of Closed Islands Leetcode Solution159
1086Defanging an IP Address LeetCode Solution159
1087Morris Inorder Traversal159
1088Find whether a subarray is in form of a mountain or not159
1089Remove duplicates from sorted array159
1090Implement Trie (Prefix Tree) Leetcode Solution158
1091Increasing Triplet Subsequence LeetCode Solution158
1092Kth Smallest Product of Two Sorted Arrays LeetCode Solution158
1093Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution158
1094Remove Palindromic Subsequences Leetcode Solution158
1095Print all triplets in sorted array that form AP158
1096Largest BST Subtree LeetCode Solution158
1097Valid Tic-Tac-Toe State LeetCode Solution158
1098Number of siblings of a given Node in n-ary Tree158
1099Binary Tree Data Structure157
1100Find the minimum distance between two numbers157
1101Ugly Number II LeetCode Solution157
1102Palindromic Substrings Leetcode Solution157
1103Palindrome Permutation LeetCode Solution157
1104Cells with Odd Values in a Matrix LeetCode Solution157
1105Binary Tree Right Side View LeetCode Solution157
1106Serialize and Deserialize Binary Tree LeetCode Solution157
1107Number of Students Doing Homework at a Given Time Leetcode Solution156
1108Count Largest Group Leetcode Solution156
1109Search in Sorted Rotated Array156
1110Day of the Year Leetcode Solution156
1111Path Sum156
1112Reformat The String Leetcode Solution156
1113Bus Routes Leetcode Solution156
1114Longest Bitonic Subsequence156
1115Products of ranges in an array156
1116Populating Next Right Pointers in Each Node Leetcode Solution156
1117Search Insert Position155
1118Maximum Depth Of Binary Tree155
1119Distinct Subsequences155
1120Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution155
1121Sum of Even Numbers After Queries155
1122Root to Leaf path with target sum Leetcode Solutions155
1123Divisible Pairs Counting155
1124Find Smallest Range Containing Elements from k Lists155
1125Iterative method to find ancestors of a given binary tree154
1126Clone a Binary Tree with Random Pointers154
1127Minimum Score Triangulation of Polygon Leetcode Solution154
1128Write Code to Determine if Two Trees are Identical154
1129Bottom View of a Binary Tree154
1130Thousand Separator Leetcode Solution154
1131Prime Palindrome LeetCode Solution154
1132Longest Increasing Consecutive Subsequence153
1133Moser-de Bruijn Sequence153
1134Third Maximum Number Leetcode Solution153
1135Mean of Array After Removing Some Elements Leetcode Solution153
1136Longest Repeated Subsequence153
1137Minimum Absolute Difference in BST Leetcode Solution153
1138Queries for Number of Distinct Elements in a Subarray153
1139Golomb sequence152
1140Construct K Palindrome Strings LeetCode Solution152
1141Print modified array after executing the commands of addition and subtraction152
1142Minimum Swaps To Make Sequences Increasing LeetCode Solution152
1143Minimum sum of squares of character counts in a given string after removing k characters152
1144Diameter of N-Ary Tree LeetCode Solution152
1145Maximum Product of Splitted Binary Tree LeetCode Solution152
1146Closest Binary Search Tree Value Leetcode Solution152
1147Reformat Date LeetCode Solution152
1148Find a sorted subsequence of size 3 in linear time152
1149Longest Subarray of 1’s After Deleting One Element LeetCode Solution152
1150Level of Each node in a Tree from source node152
1151Find Largest Value in Each Tree Row LeetCode Solution151
1152Replace two consecutive equal values with one greater151
1153Maximize sum of consecutive differences in a circular array151
1154Swap Nodes In Pairs151
1155Minimum Moves to Equal Array Elements LeetCode Solution151
1156Rotate Array151
1157Search an Element in Sorted Rotated Array151
1158Constant time range add operation on an array151
1159Cutting a Rod151
1160Maximum Product Subarray151
1161Closest Leaf in a Binary Tree LeetCode Solution151
1162Priority Queue151
1163Count even length binary sequences with same sum of first and second half bits151
1164Topological Sorting150
1165Find maximum length Snake sequence150
1166Convert BST into a Min-Heap without using array150
1167Contiguous Array LeetCode Solution150
1168Kth Smallest Number in Multiplication Table Leetcode Solution150
1169Delete Nodes and Return Forest Leetcode Solution150
1170Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1171Minimum Cost to Move Chips to The Same Position LeetCode Solution150
1172Web Crawler LeetCode Solution149
1173Decrease Elements To Make Array Zigzag LeetCode Solution149
1174Search Suggestions System LeetCode Solution149
1175Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution149
1176Factorial Trailing Zeroes LeetCode Solution149
1177Check Array Formation Through Concatenation Leetcode Solution149
1178First Bad Version149
1179Count Pairs Whose Products Exist in Array149
1180Decision Tree149
1181Subset Sum Problem in O(sum) space149
1182Possible Bipartition LeetCode Solution148
1183Maximum number of segments of lengths a, b and c148
1184Maximum Binary Tree148
1185Perfect Squares LeetCode Solution148
1186Merge two BSTs with limited extra space148
1187Binary Tree to Binary Search Tree Conversion147
1188Reverse a Path in BST using Queue147
1189Matchsticks to Square Leetcode Solution147
1190Minimum Sideway Jumps LeetCode Solution147
1191Transform a BST to Greater sum Tree147
1192K’th Largest element in BST using constant extra space147
1193Valid Triangle Number147
1194Given a binary tree, how do you remove all the half nodes?147
1195Red-Black Tree Introduction146
1196Concatenation of Array LeetCode Solution146
1197Divide Two Integers Leetcode Solution146
1198Sliding Window Median Leetcode Solution146
1199Maximum Value at a Given Index in a Bounded Array LeetCode Solution146
1200Maximum sum of a path in a Right Number Triangle146
1201Path Crossing Leetcode Solution146
1202Number of Orders in the Backlog Leetcode Solution146
1203Sum of Left Leaves LeetCode Solution146
1204Convert Sorted Array to Binary Search Tree LeetCode Solutions146
1205Queries on Probability of Even or Odd Number in given Ranges145
1206Maximum sum bitonic subarray145
1207Swapping Nodes in a Linked List Leetcode Solution145
1208Maximum sum of pairs with specific difference145
1209Valid Perfect Square LeetCode Solution144
1210Lowest Common Ancestor of a Binary Tree Leetcode Solution144
1211Champagne Tower LeetCode Solution144
1212Find the smallest binary digit multiple of given number144
1213Integer Break LeetCode Solution144
1214How to print maximum number of A’s using given four keys144
1215Queue Reconstruction by Height144
1216New 21 Game144
1217Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution144
1218Find minimum number of merge operations to make an array palindrome144
1219Range Queries for Longest Correct Bracket Subsequence143
1220Print n terms of Newman-Conway Sequence143
1221Graph and its representation142
1222Guess The Word142
1223Lowest Common Ancestor in Binary Search Tree142
1224Moving Stones Until Consecutive Leetcode Solution142
1225Maximum Array from Two given Arrays Keeping Order Same142
1226LRU Cache Leetcode Solution142
1227Array Queries for multiply replacements and product142
1228Check if all levels of two Binary Tree are anagrams or not142
1229Find Minimum in Rotated Sorted Array II LeetCode Solution142
1230Range Sum Query using Sparse Table142
1231The kth Factor of n Leetcode Solution142
1232Flatten 2D Vector LeetCode Solution142
1233Maximum Sum Increasing Subsequence142
1234Maximize Elements Using Another Array141
1235Kth Smallest Element in a BST141
1236Longest Common Prefix Using Word by Word Matching141
1237Bold Words in String LeetCode Solution141
1238Print modified array after multiple array range increment operations140
1239Arithmetic Slices II – Subsequence LeetCode Solution140
1240Mean of range in array140
1241Contiguous Array140
1242Largest Plus Sign Leetcode Solution140
1243Merge k Sorted Lists Leetcode Solution140
1244Write a function to get the intersection point of two Linked Lists140
1245Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution139
1246Graph Cloning139
1247Count Subsets Having Distinct Even Numbers139
1248BST to a Tree with Sum of all Smaller Keys139
1249Maximum Product Subarray139
1250Minimum Remove to Make Valid Parentheses LeetCode Solution138
1251Missing Number138
1252Design Skiplist LeetCode Solution138
1253Find k-th smallest element in BST (Order Statistics in BST)138
1254Parallel Courses II LeetCode Solution137
1255Power of Two137
1256Check for Identical BSTs without building the trees137
1257Different Ways to Add Parentheses Leetcode Solution137
1258Check if each internal node of a BST has exactly one child136
1259Symmetric Tree LeetCode Solution Leetcode Solution136
1260Minimum Time to Collect All Apples in a Tree LeetCode Solution136
1261Image Overlap LeetCode Solution136
1262Min Cost Climbing Stairs LeetCode Solution136
1263Check Completeness of a Binary Tree LeetCode Solution135
1264Check if two nodes are on the same path in a Tree135
1265Verify Preorder Serialization of a Binary Tree135
1266Check in binary array the number represented by a subarray is odd or even135
1267Next greater element135
1268Koko Eating Bananas LeetCode Solution134
1269Print Ancestors of a Given Binary Tree Node Without Recursion134
1270Smallest Range II Leetcode Solution134
1271Excel Sheet Column Title LeetCode Solution134
1272Longest Substring Without Repeating Characters Leetcode Solution133
1273Orderly Queue LeetCode Solution133
1274Count and Toggle Queries on a Binary Array133
1275Palindrome Number LeetCode Solution133
1276Vertical Order Traversal of Binary Tree LeetCode Solution132
1277Merge Sorted Array132
1278Check if X can give change to every person in the Queue131
1279Array Nesting Leetcode Solution131
1280Arranging Coins Leetcode Solution131
1281Largest Submatrix With Rearrangements LeetCode Solution131
1282Number of elements less than or equal to a given number in a given subarray131
1283Check If a String Can Break Another String Leetcode Solution130
1284Palindrome Partitioning129
1285Peeking Iterator LeetCode Solution129
1286Continuous Subarray Sum LeetCode Solution129
1287Add Two Numbers II Leetcode Solution128
1288Find the Winner of the Circular Game LeetCode Solution128
1289Find maximum average subarray of k length128
1290Queries for Decimal Values of Subarrays of a Binary Array128
1291Maximum product of an increasing subsequence127
1292Insert Delete GetRandom O(1) Leetcode Solution126
1293Newman–Shanks–Williams prime126
1294Range Minimum Query (Square Root Decomposition and Sparse Table)125
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution125
1296Encoded String With Shortest Length LeetCode Solution124
1297Reach a Number LeetCode Solution123
1298Jump Game IV LeetCode Solution123
1299Number of indexes with equal elements in given range123
1300Check given array of size n can represent BST of n levels or not123
1301Convert to Base -2 LeetCode Solution123
1302Random Pick Index LeetCode Solution122
1303Minimum Number of People to Teach LeetCode Solution121
1304Binary Tree to Binary Search Tree Conversion using STL set121
1305Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1306Convert a BST to a Binary Tree such that sum of all greater keys is added to every key120
1307Design A Leaderboard Leetcode Solution119
1308Minimum Total Space Wasted With K Resizing Operations LeetCode Solution119
1309Design Underground System Leetcode Solution118
1310Queries on XOR of greatest odd divisor of the range118
1311Shifting Letters LeetCode Solution117
1312Print Maximum Length Chain of Pairs116
1313Detect Capital Leetcode Solution113
1314Minimum Swaps to Group All 1’s Together Leetcode Solution113
1315Minimum Path Sum Leetcode Solution111
1316Count Sub Islands LeetCode Solution110
1317Top K Frequent Elements LeetCode Solution110
1318Substring with Concatenation of All Words Leetcode Solution109
1319Odd Even Linked List Leetcode Solution108
1320Monotonic Array Leetcode Solution107
1321Binary Tree Inorder Traversal LeetCode Solution105
1322Maximum Population Year LeetCode Solution105
1323Decode String Leetcode Solution105
1324Longest Common Subsequence LeetCode Solution104
1325Find the Town Judge LeetCode Solution104
1326Shortest Unsorted Continuous Subarray LeetCode Solution99
1327Rectangle Overlap LeetCode Solution97
1328Sum Root to Leaf Numbers LeetCode Solution96
1329Best Meeting Point LeetCode Solution96
1330Find the Town Judge LeetCode Solution95
1331Maximum Population Year LeetCode Solution94
1332Flatten Binary Tree to Linked List LeetCode Solution94
1333Insert into a Sorted Circular Linked List LeetCode Solution94
1334Design Add and Search Words Data Structure LeetCode Solution93
1335Score of Parenthesis LeetCode Solution92
1336Reveal Cards In Increasing Order Leetcode Solution91
1337Stone Game IV LeetCode Solution91
1338Valid Triangle Number LeetCode Solution90
1339Range Sum Query 2D – Immutable LeetCode Solution90
1340Is Graph Bipartite? LeetCode Solution90
1341Divide Chocolate LeetCode Solution84
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution71
1344Reverse Integer Leetcode Solution71
1345Rotate String LeetCode Solution69
1346Find K Closest Elements LeetCode Solution67
1347Sort Colors LeetCode Solution65
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution64
1349Excel Sheet Column Number LeetCode Solution61
1350Maximum Size Subarray Sum Equals k Leetcode Solution55
1351Valid Anagram Leetcode Solution47
1352H-Index Leetcode Solution47
1353Camelcase Matching Leetcode Solution47
1354Most Stones Removed with Same Row or Column LeetCode Solution46
1355Sliding Window Maximum LeetCode Solution46
1356Container With Most Water LeetCode Solution45
1357Group Anagrams LeetCode Solution44
1358Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution44
1359Next Permutation LeetCode Solution44
1360High Five LeetCode Solution43
1361Find Peak Element LeetCode Solution43
1362Binary Search LeetCode Solution43
1363Paint House LeetCode Solution42
1364Group Shifted Strings Leetcode Solution40
1365Flatten Binary Tree to Linked List LeetCode Solution39
1366Minimum Number of Arrows to Burst Balloons LeetCode Solution38
1367Sentence Screen Fitting LeetCode Solution38
1368Split Linked List in Parts Leetcode Solution38
1369Next Greater Element I Leetcode Solution38
1370The Number of Weak Characters in the Game LeetCode Solution38
1371Isomorphic Strings LeetCode Solution37
1372Unique Binary Search Trees LeetCode Solution36
1373Valid Triangle Number LeetCode Solution36
1374Count Good Nodes in Binary Tree LeetCode Solution35
1375Break a Palindrome LeetCode Solution34
1376Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution34
1377Peak Index in a Mountain Array LeetCode Solution34
1378Swim in Rising Water LeetCode Solution33
1379All Possible Full Binary Trees LeetCode Solution33
1380Minimum Increment to Make Array Unique Leetcode Solution33
1381Best Time to Buy and Sell Stock IV LeetCode Solution33
1382Closest Binary Search Tree Value II LeetCode Solution33
1383Single Element in a Sorted Array LeetCode Solution32
1384Max Sum of Two Non-Overlapping Subarrays LeetCode Solution32
1385Implement Rand10() Using Rand7() Leetcode Solution31
1386Contains Duplicate LeetCode Solution31
1387Remove All Ones With Row and Column Flips Leetcode Solution31
1388Trapping Rain Water II LeetCode Solution30
1389Find First and Last Position of Element in Sorted Array LeetCode Solution30
1390Validate Stack Sequences LeetCode Solution29
1391Lowest Common Ancestor of a Binary Search Tree Leetcode Solution29
1392Greatest Sum Divisible by Three LeetCode Solution28
1393Reverse Nodes in k-Group LeetCode Solution28
1394Detect Squares LeetCode Solution27
1395Implement strStr() LeetCode Solution27
1396Stone Game IV LeetCode Solution26
1397Fibonacci Number LeetCode Solution24
1398Invert Binary Tree LeetCode Solution24
1399Design Bounded Blocking Queue LeetCode Solution23
1400Total Hamming Distance LeetCode Solution23
1401Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution22
1402Unique Paths III LeetCode Solution20
1403Candy LeetCode Solution18
Translate »