Find the Winner of the Circular Game LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Apple Bloomberg Goldman Sachs
Array Math Queue Recursion StimulationViews 88

Problem Statement

Find the Winner of the Circular Game LeetCode Solution – There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.

The rules of the game are as follows:

  1. Start at the 1st friend.
  2. Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.
  3. The last friend you counted leaves the circle and loses the game.
  4. If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeating.
  5. Else, the last friend in the circle wins the game.

Given the number of friends, n, and an integer k, return the winner of the game.

 

Example 1:

Find the Winner of the Circular Game LeetCode SolutionPinInput:

 n = 5, k = 2

Output:

 3

Explanation:

 Here are the steps of the game:
1) Start at friend 1.
2) Count 2 friends clockwise, which are friends 1 and 2.
3) Friend 2 leaves the circle. Next start is friend 3.
4) Count 2 friends clockwise, which are friends 3 and 4.
5) Friend 4 leaves the circle. Next start is friend 5.
6) Count 2 friends clockwise, which are friends 5 and 1.
7) Friend 1 leaves the circle. Next start is friend 3.
8) Count 2 friends clockwise, which are friends 3 and 5.
9) Friend 5 leaves the circle. Only friend 3 is left, so they are the winner.

Approach

Idea:

If we know the winner index of (n – 1) persons, then we can find the winner index for n people. We can see this with an example with a group of 4 people with k being 2. We know that for 3 people (1,2,3) the winner is 3 (index 2) and this will come into play later. First, we eliminate one person out of 4 to make them 3, so for 1,2,3,4 -> we eliminate the kth person or person with (k – 1)th index, in this case being 2(index 1). Now we have 3 people remaining 1,3,4 with starting person as 3 (index 2) or person with (k + 1)th index for the next elimination, and we know that for 3 people, the winner will be the person at the 2nd index beginning with 3 as the starting point i.e. 1(index 0) or ((k + 1) + f(n – 1)) % n, where (k +1) is starting index and f(n – 1) is the answer for (n – 1) persons.

Code

Java Program of Find the Winner of the Circular Game:

class Solution {
   public int findTheWinner(int n, int k) {
        return findWinnerHelper(n, k - 1) + 1;
    }
    
    private int findWinnerHelper(int n, int k) {
        if (n == 1) {
            return 0;
        }
        
        return ((k + 1) % n + findWinnerHelper(n - 1, k)) % n;       
    }
}

C++ Program of Find the Winner of the Circular Game:

class Solution
{
    public:
    int findTheWinner(int n, int k)
    {
        return findWinnerHelper(n, k - 1) + 1;
    }
    private:
    int findWinnerHelper(int n, int k)
    {
        if (n == 1)
        {
            return 0;
        }
        return ((k + 1) % n + findWinnerHelper(n - 1, k)) % n;
    }
};

Python Program of Find the Winner of the Circular Game:

class Solution :
    def  findTheWinner(self, n,  k) :
        return self.findWinnerHelper(n, k - 1) + 1
    def  findWinnerHelper(self, n,  k) :
        if (n == 1) :
            return 0
        return ((k + 1) % n + self.findWinnerHelper(n - 1, k)) % n

Complexity Analysis for Find the Winner of the Circular Game LeetCode Solution

Time Complexity

The time complexity of the above code is O(1) because we don’t do any traverse anything, we just calculate the winner based on the number of players and k.

Space Complexity

The space complexity of the above code is O(1) because the amount of space used is always constant no matter how big n or k is since we aren’t actually traversing through the players.

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