Stone Game IV LeetCode Solution

Difficulty Level Hard
Frequently asked in Apple Bloomberg Game Theory Google Microsoft
Dynamic Programming MathViews 59

Problem Statement

Stone Game IV LeetCode Solution – Alice and Bob take turns playing a game, with Alice starting first.

Initially, there are n stones in a pile. On each player’s turn, that player makes a move consisting of removing any non-zero square number of stones in the pile.

Also, if a player cannot make a move, he/she loses the game.

Given a positive integer n, return true if and only if Alice wins the game otherwise return false, assuming both players play optimally as our answer for stone game iv leetcode solution.

Example 1:

Input:

 n = 1

Output:

 true

Explanation:

Alice can remove 1 stone winning the game because Bob doesn't have any moves.

Example 2:

Input:

 n = 2

Output:

 false

Explanation:

Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 -> 1 -> 0).

Example 3:

Input:

 n = 4

Output:

 true

Explanation:

 n is already a perfect square, Alice can win with one move, removing 4 stones (4 -> 0).

Constraints:

1 <= n <= 10

Approach:-

  • Consider the dynamic programming approach for stone game iv solution.
  • We make a dp array named as canWin of size n+1
  • canWin[i] tells us if we have i stones then the person who starts first can win or not
  • if we have 0 stones then Alice can not make a move so canWin[0]=false i.e=>alice lose
  • so for i stones if there is any  j such than canWin[i-j*j]==false then canWin[i]=true  else canWin[i]=false.

Code:

Java Leetcode Solution:

class Solution {
    Boolean[]dp;
    public boolean winnerSquareGame(int n) {
        dp=new Boolean[n+1];
        return helper(n,1);
    }
    public boolean helper(int n,int b){
 
        if(dp[n]!=null)return dp[n];
        
        int i=1;
        for(;i*i<=n;i++){
         boolean  ans=  helper(n-(i*i),(b^1));
           if(!ans)return dp[n]=true;
            
        }
        return dp[n]=false;
        
    }
}

C++ Leetcode Solution:

class Solution {
public:
    bool winnerSquareGame(int n) {
        vector<bool> dp(n+1);
        for(int i=1;i<=n;i++){
            for(int j=1;j*j<=i;j++){
                if(!dp[i-(j*j)]){
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp.back();
    }
};

Complexity Analysis of Stone Game IV Leetcode Solution:

Time Complexity:

The Time complexity is O(nsqrt(n)).

Space Complexity:

The Space Complexity is O(n).

Top Interview Questions

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