Most Stones Removed with Same Row or Column LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Apple Bloomberg Google Uber
Bfs Dfs Dsu GraphViews 4

Problem Statement

Most Stones Removed with Same Row or Column LeetCode Solution says that On a 2D plane

we place n stones at some integer coordinate points. Each coordinate point may have at most one stone. A stone can be removed if it shares either the same row or the same column as another stone that has not been removed.  An array stones of length n where stones[i] = [xi, yi] represents the location of the ith stone. We have to find the largest number of stones to be removed.

Example 1:


 stones = [[0,0],[0,1],[1,0],[1,2],[2,1],[2,2]]




 One way to remove 5 stones is as follows:
1. Remove stone [2,2] because it shares the same row as [2,1].
2. Remove stone [2,1] because it shares the same column as [0,1].
3. Remove stone [1,2] because it shares the same row as [1,0].
4. Remove stone [1,0] because it shares the same column as [0,0].
5. Remove stone [0,1] because it shares the same row as [0,0].
Stone [0,0] cannot be removed since it does not share a row/column with another stone still on the plane.

Example 2:


 stones = [[0,0],[0,2],[1,1],[2,0],[2,2]]




 One way to make 3 moves is as follows:
1. Remove stone [2,2] because it shares the same row as [2,0].
2. Remove stone [2,0] because it shares the same column as [0,0].
3. Remove stone [0,2] because it shares the same row as [0,0].
Stones [0,0] and [1,1] cannot be removed since they do not share a row/column with another stone still on the plane.

Example 3:


 stones = [[0,0]]




 [0,0] is the only stone on the plane, so you cannot remove it.


  • 1 <= stones.length <= 1000
  • 0 <= xi, yi <= 104
  • No two stones are at the same coordinate point.



  1. The idea here is that we can remove all stones from the group of connected stones except the last one.
  2. If stone a and stone b are in the same column/row, we connect them as a component. That means we can make them as connected components.
  3. The maximum number of stones can be removed = the number of stones-connected components.
  4. For finding the connected components we can use DFS/BFS or Union find algorithms.

Most Stones Removed with Same Row or Column LeetCode SolutionPin Most Stones Removed with Same Row or Column LeetCode SolutionPin


C++ Solution

class Solution {
    #define ll int
    ll par[10005];
    void make()
        ll i;
    ll find(ll x)
   if(par[x]==x)return x;
  return par[x]=find(par[x]);
    ll unite(ll x,ll y)
        ll p1=find(x);
        ll p2=find(y);
        return 0;
    int removeStones(vector<vector<int>>& stones) {
        ll i,j,n=stones.size();
               if(stones[i][0]==stones[j][0] or stones[i][1]==stones[j][1])
        ll cnt=0;
        return stones.size()-cnt;

Java Solution

class Solution {
    int[] par=new int[10005];
    void make()
        int i;
    int find(int x)
    return x;
  return par[x]=find(par[x]);
    int unite(int x,int y)
        int p1=find(x);
        int p2=find(y);
        return 0;
    public int removeStones(int[][] stones) {
        int i,j,n=stones.length;
               if(stones[i][0]==stones[j][0] || stones[i][1]==stones[j][1])
        int cnt=0;
        int k=n-cnt;
        return k;

Complexity Analysis of Most Stones Removed with Same Row or Column LeetCode Solution

Time Complexity

Time complexity is O(N*N). As we are looping in the array to connect them. Where N is the array size.

Space Complexity

Space complexity is 0(N). We are taking extra space to store the parents.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2831
2Java program to find the number of Nodes in a Binary Tree2510
3Reverse a string without affecting special characters2470
4Delete a node of a linked list at given position1984
5Palindrome using Recursion1884
6Insert nodes in a linked list in a sorted way (Ascending Order)1669
7Find elements pair from array whose sum equal to number1655
8Sort Elements by Frequency of Occurrences1643
9Quick Sort1627
10Write a program to print all permutations of a given string1615
11Find Minimum Distance Between Two Numbers in an Array1480
12Create a Doubly Linked List1456
13Reverse an Array1417
14Smallest window in a string containing all characters of another string1402
15Find a Triplet That Sum to a Given Value1366
16Recursively remove all adjacent duplicates1363
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1328
19Sum of numbers in String1325
20Smallest Positive Number Missing in an Unsorted Array1293
21Check if the Elements of an Array are Consecutive1262
22Detect a loop in the Linked List1247
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1226
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1212
27Recursive function to do substring search1208
28Find the Maximum Repeating Number in Array1161
29Binary Tree Level order traversal in Java1132
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1113
32Maximum Subarray Sum using Divide and Conquer1111
33Remove characters from first string which are in second1077
34Find Leaders in an Array1066
35Swap nodes in the linked list1044
36Find the Number Occurring Odd Number of Times in an Array1009
37Arrange given Numbers to Form the Biggest Number II999
38Find the second most frequent character998
39Given a string find its first non-repeating character977
40Find Triplet in Array With a Given Sum969
41Total number of occurrences of a given item in the linked list960
42Given a sorted array and a number x, find the pair in array whose sum is closest to x959
43A Program to check if strings are rotations of each other or not958
44Print all possible words from phone digits940
45Find the Missing Number932
46Rearrange Positive and Negative Numbers Alternatively in Array928
47Longest Palindromic Substring911
48Segregate even and odd nodes in a linked list895
49Print Longest common subsequence891
50Union and Intersection of Two Linked Lists880
51Transform one string to another using minimum number of given operations875
52Check rearranged string can form a palindrome857
53Rearrange given Array in Maximum Minimum Form852
54Iterative Implementation of Quick Sort841
55Count Possible Triangles829
56Multiplication of Two Matrices811
57Check if the linked list is palindrome803
58Count of Triplets With Sum Less than Given Value802
59Rotate a Linked List802
60Stock Buy Sell to Maximize Profit797
61Insertion Sort773
62Concatenation of two strings769
63Tug of War767
64Count Number of Substrings with K Distinct Character’s764
65Print all duplicates in the input string762
66Find Nearest Greater and Smaller Element751
67The Celebrity Problem745
68Find Pythagorean Triplets from Array744
69Remove ‘b’ and ‘ac’ from a given string739
70Reverse String Without Temporary Variable739
71Find all Common Elements in Given Three Sorted Arrays735
72Remove all duplicates in an unsorted linked list717
73Find the Row with Maximum Number of 1’s712
74Find the Peak Element from an Array707
75Find the subarray whose sum is equal to a given number X705
76Remove Minimum Characters so that Two Strings Become Anagrams698
77Addition of Two Matrices693
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s686
81Implement Two Stacks in an Array682
82Maximum Sum of Non Consecutive Elements679
83Maximum Product Subarray II665
84Lexicographic rank of string662
85Check if Two given Matrices are Identical655
86Multiplication of Previous and Next653
87Subtraction of Two Matrices644
88Merge K Sorted Arrays and Print Sorted Output639
89Move All the Zeros to the End of the Given Array638
90Divide a string in N equal parts634
91Online Algorithm for Checking Palindrome in a Stream629
92Form Minimum Number from Given Sequence of D’s and I’s629
93Check whether two strings are anagram of each other624
94Remove recurring digits in a given number622
95Sort a linked list that is sorted alternating ascending and descending617
96Maximum Circular Subarray Sum617
97Sort a stack using a temporary stack615
98Find the Minimum Element in a Sorted and Rotated Array611
99Move last element of the Linked List at first place610
100Subarray and Subsequence607
101First Circular Tour to Visit all the Petrol Bunks605
102Largest Subarray with Equal Number of 0’s and 1’s602
103Compare two strings(linked lists)601
104Flattening a linked list600
105Maximum Element in an Array which is Increasing and then Decreasing599
106Palindrome Permutations of a String595
107Elements Appear more than N/K times in Array588
108Palindromes in a given range585
109Run length encoding584
110Majority Element584
111Print all permutations with repetition583
112Pangram Checking581
113Minimum insertions to form a shortest palindrome581
114Minimum Characters to be Added at Front to Make String Palindrome573
115Rearrange a given linked list in-place572
116Merge a linked list into another at alternate positions571
117Remove all duplicates in a sorted linked list571
118Most repeating character in a string569
119Rotate string to get lexicographically minimum string569
120Minimum number of Merge Operations to make an Array Palindrome568
121Repeated Subsequence of Length Two or More566
122Print all anagrams together in a sequence of words561
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem548
125Merge Overlapping Intervals II546
126Two Sum Leetcode Solution546
127Clone a Linked List with next and random pointer544
1283Sum Leetcode Solution543
129Size of The Subarray With Maximum Sum534
130Transpose of a Matrix533
131Remove Extra Spaces from a String530
132Removing Spaces from a String using stringstream529
133Partition Problem527
134Remove duplicates from a string527
135Check if a given string is a rotation of a palindrome526
136Longest Palindrome can be Formed by Removing or Rearranging Characters525
137Maximum Sum Increasing Subsequence524
138Smallest Palindrome after Replacement524
139Check whether Strings are K Distance Apart or Not515
140Generate all Binary Strings from Given Pattern515
141Length of Longest valid Substring510
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized509
143Insert Node in the Sorted Linked List507
144Delete Last Occurrence506
145Check if Two given Strings are Isomorphic to each other502
146Maximum difference between two elements such as larger element comes after smaller495
147Program to Toggle all Characters in a String493
148Given string is interleaving of two other strings or not492
149Count Minimum Steps to Get the given Array487
150Merge sort better than quick sort for linked lists484
151Number of Smaller Elements on Right Side483
152Check if all Rows of a Matrix are Circular Rotations of Each Other481
153Check length of a String is Equal to the Number Appended at its Last481
154Find Pair with Given Difference480
155Longest Common Prefix using Divide and Conquer477
156Find nth node of the Linked list from the end477
157Print all interleavings of given two strings468
158Find a Fixed Point in a Given Array468
159Sort 0s 1s and 2s in an Array468
160Compare Two Version Numbers465
161Reverse words in a given string462
162Merge two sorted linked lists such that merged list is in reverse order462
163Reorder Array Using Given Indexes461
164Find the Subarray of given length with Least Average461
165Print Reverse of a string (Recursion)460
166Median of Two Sorted Arrays LeetCode Solution459
167Split linked list using alternate nodes459
168Print string of odd length in ‘X’ format445
169Print all Palindromic Partitions of a String441
170Find K Length Subarray of Maximum Average441
171Swap Kth Node from beginning with Kth Node from End441
172Find Element Using Binary Search in Sorted Array440
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions427
175Flatten a multilevel linked list424
176Shortest Superstring Problem424
177Maximum Length of Chain Pairs423
178Check if String Follows Order of Characters by a Pattern or not420
179Sorting a K Sorted Array418
180Sort a String According to Another String413
181Longest Span with same Sum in two Binary Arrays II404
182Reverse a Linked List in groups402
183Find a Sorted Subsequence of size 3401
184Recursively print all the sentences that can be formed from list of word lists399
185Program to add two binary digits398
186Longest Common Prefix Using Binary Search II396
187Find the two Numbers with Odd Occurrences in an Unsorted Array394
188Reverse a Singly Linked List (Iterative/Non-Recursive)394
189Caesar Cipher390
190Kth Non-repeating Character389
191Rearrange a linked list in Zig-Zag386
192Check if String can Become Empty by Recursively Deleting given Substring385
193Longest Common Prefix Word by Word Matching382
194Pancake Sorting381
195Rotate Image by 90 degrees380
196Permutations of a Given String Using STL373
197Perfect Reversible String372
198Merging Two Sorted Arrays370
199Increasing Subsequence of Length three with Maximum Product368
200Sort a linked list with 0s, 1s and 2s367
2011`s and 2`s complement of binary number367
202Find First non-repeating character in a string366
203Find the point where a monotonically increasing function becomes positive first time366
204Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes366
205Four Elements that Sum to Given363
206List items containing all characters of a given word361
207Delete N nodes after M360
208Longest Common Prefix using Character by Character Matching357
209Count Number of Occurrences in a Sorted Array354
210Palindrome string (number)351
211Split a string349
212Minimum Characters to be Removed to Make a Binary String Alternate344
213Recursive Implementation of atoi()342
214Check if a Linked list of Strings form a Palindrome341
215Print All Distinct Elements of the Array339
216Sorting the array of strings339
217Maximum occurring character in a string337
218Convert a String that is Repetition of a Substring of Length K336
219Even Substring Count336
220Valid Parentheses LeetCode Solution335
221Reverse a singly linked list recursively334
222Find the first Repeating Number in a Given Array334
223Print Shortest Path to Print a String on Screen331
224Can we reverse a linked list in less than O(n) time ?331
225Convert string1 to string2 in one edit330
226Binary Tree to Doubly linked list329
227Nth Character in Concatenated Decimal String328
228wildcard character matching326
229Reverse a String using Stack326
230Sort Elements by Frequency II325
231Lower Case To Upper Case324
232Maximum Subarray Leetcode Solution324
233Merge Two Sorted Arrays319
234Count the number of words318
235Split Four Distinct Strings317
236Find the Lost Element From a Duplicated Array315
237Find middle of the Linked List313
238Count the Pairs at Same Distance as in English Alphabets309
239Longest Common Subsequence with Permutations309
240Matrix Chain Multiplication using Dynamic Programming309
241Next Greater Element in an Array303
242Palindrome Permutation299
243Roman to Integer Leetcode Solution293
244Find Nth Node293
245Searching a node in a Binary Search Tree291
246Find All Pairs With a Given Difference290
247Triplet from three linked lists with given sum286
248Delete a Tree286
249String(represents an integer) to value285
250Reverse a String284
251Word Search Leetcode Solution283
252Reverse Bits282
253Delete a node under given conditions282
254Print all Possible Ways to Break a String in Bracket Form281
255Binary Tree279
256Change Gender of a given String279
257How to Efficiently Implement k Stacks in a Single Array?277
258Sort an array of strings277
259Toeplitz Matrix276
260Count Pairs With Given Sum275
261First non Repeating Element274
262Number of sub-strings which recursively add up to 9273
263Meeting Rooms II LeetCode Solution273
264Repeated Substring Pattern272
265Longest Common Extension271
266N queen problem271
267Remove middle points in a linked list of line segments271
268Move all negative elements to one side of array270
269Remove spaces from a string268
270Longest Palindromic Substring LeetCode Solution266
271Shuffle a given Array264
272Min Stack264
273Dijkstra Algorithm261
274Number of Islands LeetCode Solution260
275Cuckoo sequence program259
276House Robber Leetcode Solution258
277Find, second, frequent, character258
278Max stack258
279Fibonacci numbers257
280Most Frequent Element in an Array256
281Minimize the maximum difference between the heights255
282Clone a linked list with next and random pointer (Hashing)253
283Search Insert Position Leetcode Solution253
284Expression Evaluation252
285Sort linked which is sorted on absolute values250
286KMP Algorithm250
287Sudoku Solver249
288Subset Leetcode249
289Valid Palindrome Leetcode Solution248
290Plus One Leetcode Solution247
291Word Search247
292Evaluation of Postfix Expression246
293Number Of 1 bits246
294Reverse words in a string246
295Combination Sum Leetcode Solution245
296How to Delete a Linked List245
297Min Stack Leetcode Solution244
298Backspace String Compare241
299Set Matrix Zeroes238
300Pair of Positive Negative Values in an Array237
301Rabin Karp Algorithm237
302Sqrt(x) Leetcode Solution237
303Merge Sorted Arrays Leetcode Solution236
304Reversing a Queue236
305Subarray with 0 sum234
306Tower Of Hanoi233
307Common elements in all rows of a given matrix233
308Combination Sum231
309Integer to Roman Leetcode Solution230
310Delete middle element of a stack230
311Contains Duplicate II Leetcode Solution230
312Product of array except self230
313Pascal Triangle Leetcode229
314String Compression228
315Intersection of Two Arrays II Leetcode Solution228
316Reverse individual words227
317Minimum swaps required to bring all elements less than or equal to k together227
318Segregate even and odd numbers226
319Construct Binary Tree from Given Inorder and Preorder Traversals225
320Count of index pairs with equal elements in an array225
321Count subarrays with equal number of 1’s and 0’s225
322Find Top K (or Most Frequent) Numbers in a Stream225
323Bellman Ford Algorithm224
324Add Binary Leetcode Solution224
325Implementation of Deque using Doubly Linked List224
326Sliding Window Technique224
327Count Odd Numbers in an Interval Range Leetcode Solution223
328Minimum Value to Get Positive Step by Step Sum Leetcode Solution223
329Contains Duplicate223
330Single Number Leetcode Solution223
331Find sum of non-repeating elements (distinct) elements in an array222
332Arithmetic Expression Evaluation222
333Second Most Repeated Word in a Sequence221
334Postfix to Infix Conversion221
335Sort elements by frequency221
336Palindrome Linked List Leetcode Solution221
337Pow(x, n) Leetcode Solution220
338Page Replacement Algorithms in Operating Systems219
339Maximum Number of Balloons Leetcode Solution219
340Kruskal Algorithm218
341Group Words With Same Set of Characters218
342Next Permutation218
343Design a stack that supports getMin() in O(1) time and O(1) extra space218
344Sum of minimum and maximum elements of all subarrays of size k216
345Smallest Subarray with k Distinct Numbers216
346Longest Common Prefix Leetcode Solution216
347K-th Smallest Element in a Sorted Matrix216
348Scramble String216
349Find Lucky Integer in an Array Leetcode Solution215
350Count subarrays having total distinct elements same as original array215
351Convex Hull Algorithm215
352Third Maximum Number Leetcode Solution215
353Maximum Subarray215
354Permutations Leetcode Solution214
355Top K Frequent Words214
356Sorting array using Stacks214
357Minimum operation to make all elements equal in array214
358Longest Substring Without Repeating Characters LeetCode Solution214
359Find the Town Judge Leetcode Solution213
360Find Numbers with Even Number of Digits Leetcode Solution212
361Special Number211
362Evaluate Division211
363Majority Element Leetcode Solution210
364Given two unsorted arrays find all pairs whose sum is x210
365Number of Good Pairs Leetcode Solution210
366Swap Nodes in Pairs Leetcode Solutions210
367Huffman Coding209
368Spiral Matrix LeetCode Solution209
369Minimum Path Sum209
370First element occurring k times in an array209
371Prefix to Infix Conversion208
372Check if two arrays are equal or not208
373Maximal Square207
374Reversing the First K elements of a Queue207
375Single Number207
376Reverse a Number Using Stack207
377Count Primes Leetcode Solutions207
378Merge Two Sorted Lists Leetcode Solutions207
379Best Time to Buy and Sell Stock  II Leetcode Solution206
380Pascal’s Triangle II Leetcode Solution206
381Group Anagrams206
382Missing Number Leetcode Solution206
383Minimum Absolute Difference Leetcode Solution205
384Search in Rotated Sorted Array Leetcode Solution205
385Running Sum of 1d Array Leetcode Solution205
386Minimum Steps to reach target by a Knight205
387Find duplicates in a given array when elements are not limited to a range205
388Sort Array by Increasing Frequency Leetcode Solution204
389House Robber II Leetcode Solution204
390Maximum Distance Between two Occurrences of Same Element in Array204
391Palindrome Substring Queries204
392Matrix Diagonal Sum Leetcode Solution203
393Maximum possible difference of two subsets of an array203
394Power of Two Leetcode Solution203
395Convert String To Int202
396Unique Paths202
397Find the first repeating element in an array of integers202
398Find All Numbers Disappeared in an Array Leetcode Solution202
399Top K Frequent Elements202
400How to Implement Stack Using Priority Queue or Heap?202
401Zigzag Conversion202
402Find Minimum In Rotated Sorted Array202
403Range Sum Query 2D – Immutable Leetcode Solution202
404Find the Closest Palindrome number201
405Smallest Element Repeated Exactly K Times201
406Fizz Buzz Leetcode201
407Check if Array Contains Contiguous Integers With Duplicates Allowed201
408Expression Contains Redundant Bracket or Not201
409Unique Paths Leetcode Solution201
410Sorting using trivial hash function201
411Subarray Sum Equals k201
412Sort Integers by The Number of 1 Bit Leetcode Solution200
413Leetcode Permutations200
414How Many Numbers Are Smaller Than the Current Number Leetcode Solution200
415Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
416Letter Case Permutation199
417Decode String199
418Cumulative Frequency of Count of Each Element in an Unsorted Array199
419Subset sum problem199
420Find Number of Employees Under every Employee199
421Max Consecutive Ones Leetcode Solution199
422Find Winner on a Tic Tac Toe Game Leetcode Solution199
423Coin Change 2 Leetcode Solution198
424Length of the largest subarray with contiguous elements198
425Happy Number Leetcode Solution198
426Monotonic Array LeetCode Solution198
427Difference between highest and least frequencies in an array198
428Find top three repeated in array197
429Best Time to Buy and Sell Stock III Leetcode Solution197
430Subarray Sum Equals K LeetCode Solution197
431Print All Distinct Elements of a Given Integer Array197
432Sort a stack using recursion197
433Nth Catalan Number197
434Implement Stack and Queue using Deque197
435Reverse Integer197
436Print all subarrays with 0 sum196
437Count Substrings with equal number of 0s, 1s and 2s196
438LRU Cache Implementation196
439Fibonacci Number LeetCode Solution196
440Maximum Depth of Binary Tree Leetcode Solution196
441Remove Duplicates from Sorted Array Leetcode Solution196
442Check If N and Its Double Exist Leetcode Solution196
443Reverse Vowels of a String Leetcode Solution195
444Capacity To Ship Packages Within D Days Leetcode Solution195
445Sum of Subarray Ranges Leetcode Solution195
446Subarrays with distinct elements195
447Prim’s Algorithm194
448Find The Duplicate Number194
449Generate a String With Characters That Have Odd Counts Leetcode Solution194
450Find Median from data Stream194
451Reverse a Stack Using Recursion194
452Subtract the Product and Sum of Digits of an Integer Leetcode Solution194
453Kth largest element in an Array Leetcode Solutions193
454Bipartite Graph193
455Reverse Words in a String III LeetCode Solution193
456Integer to English words193
457Shuffle the Array Leetcode Solution193
458Merge Two Sorted Linked Lists193
459Delete a Node from linked list without head pointer193
460Find the Difference Leetcode Solution192
461Edit Distance192
462Find all pairs (a, b) in an array such that a % b = k192
463Count pairs from two linked lists whose sum is equal to a given value192
464Count and Say192
465Find elements which are present in first array and not in second192
466Trapping Rain Water Leetcode Solution192
467Find the Duplicate Element192
468Find Common Characters Leetcode Solution192
469Target Sum192
470Remove Minimum Number of Elements Such That no Common Element Exist in both Array191
471Longest Common Subsequence191
472Sorting a Queue without Extra Space191
473Reverse a String191
474The K Weakest Rows in a Matrix Leetcode Solution190
475Priority Queue Using Singly Linked List190
476Iterative Tower of Hanoi190
477Excel Sheet Column Number Leetcode Solution190
478Fizz Buzz190
479Floyd Warshall Algorithm190
480Balanced Binary Tree Leetcode Solution190
481Longest Common Prefix using Trie189
482Reverse a linked list189
483Concatenation of Array LeetCode Solution189
484Text Justification LeetCode Solution189
485Longest subarray not having more than K distinct elements188
486Design Parking System Leetcode Solution188
487Kth Largest Element in a Stream Leetcode Solution188
488Flood Fill LeetCode188
489Find First and Last Position of Element in Sorted Array Leetcode Solution188
490Degree of an array188
491Kids With the Greatest Number of Candies Leetcode Solution188
492Merge Overlapping Intervals188
493Prefix to Postfix Conversion188
494Minimum Moves to Equal Array Elements Leetcode Solution188
495Next Greater Element I Leetcode Solution188
496Valid Parenthesis String187
497Word Ladder LeetCode Solution187
498Slowest Key Leetcode Solution187
499Find subarray with given sum (Handles Negative Numbers)187
500Number of Steps to Reduce a Number to Zero Leetcode Solution187
501MiniMax Algorithm187
502Top View of Binary Tree187
503Priority Queue in C++186
504Zigzag Conversion LeetCode Solution186
505The Stock Span Problem186
506Find four elements that sum to a given value (Hashmap)186
507Shortest Palindrome186
508Find missing elements of a range186
509Pair with given product186
510Find N Unique Integers Sum up to Zero Leetcode Solution186
511Multiply Strings Leetcode Solution186
512Max Area of Island185
513Count and Say Leetcode Solution185
514Convert array into Zig-Zag fashion185
515Postfix to Prefix Conversion185
516Jump Game Leetcode Solution185
517Find any one of the multiple repeating elements in read only array184
518Implement a stack using single queue184
519Length of Last Word Leetcode Solution184
520Mobile Numeric Keypad Problem184
521Find distinct elements common to all rows of a matrix184
522Move Zeroes LeetCode Solution184
523Find Index of Closing Bracket for a Given Opening Bracket in an Expression184
524Check if a given array contains duplicate elements within k distance from each other184
525Substring With Concatenation Of All Words184
526Rearrange a binary string as alternate x and y occurrences184
528Count number of triplets with product equal to given number184
529Next Greater Frequency Element183
530Largest Sum Contiguous Subarray183
531Intersection of Two Arrays183
532Shuffle String Leetcode Solution183
533Peak Index in a Mountain Array183
534Longest Common Prefix using Sorting183
535Implement Stack using Queues183
536Last Stone Weight182
537Smallest Subarray With all Occurrences of a Most Frequent Element182
538Iterative Inorder Traversal of a Binary Tree182
539Contiguous Array Leetcode182
540Convert a normal BST to Balanced BST181
541Relative Sort Array Leetcode Solution181
542Koko Eating Bananas Leetcode Solution181
543Delete Node in a Linked List Leetcode Solution181
544Excel Sheet Column Title Leetcode Solution181
545Group Multiple Occurrence of Array Elements Ordered by first Occurrence181
546Sum of Left Leaves Leetcode Solutions181
547Change the Array into Permutation of Numbers From 1 to N181
548Minimum Bracket Reversals180
549Shuffle an Array180
550Assign Cookies Leetcode Solution180
551Best Time to Buy and Sell Stock180
552K-th Distinct Element in an Array180
553Valid Sudoku180
554Linked List Cycle II LeetCode Solution180
555Implementation of Deque using circular array179
556First negative integer in every window of size k179
557Minimum Delete Operations to make all Elements of Array Same179
558Minimum Operations to convert X to Y179
559Is Subsequence Leetcode Solution179
560Island Perimeter Leetcode Solution179
561Integer to Roman179
562Number of Provinces Leetcode Solution179
563Find Words That Can Be Formed by Characters Leetcode Solution179
564Container with Most Water179
565Isomorphic Strings Leetcode Solution179
566N-th Tribonacci Number Leetcode Solution179
567Distribute Candies to People Leetcode Solution179
568Hamming Distance178
569Arrange given numbers to form the biggest number178
570Largest Perimeter Triangle Leetcode Solution178
571Check for Balanced Parentheses in an Expression178
572Jewels and Stones Leetcode Solution178
573Minimum Knight Moves LeetCode Solution178
574Build Array From Permutation Leetcode Solution178
575Unique Binary Search Trees177
576Combinations Leetcode Solution177
577Valid Anagrams177
578Rotate List Leetcode Solution177
579Summary Ranges Leetcode Solution177
580Count the number of nodes at given level in a tree using BFS177
58101 Matrix LeetCode Solution177
582Maximum path sum in a triangle177
583Count all subsequences having product less than K177
584Gold Mine Problem177
585Convert Sorted Array to Binary Search Tree Leetcode Solution177
586The Knapsack Problem177
587LRU Cache LeetCode Solution176
588Maximum sum rectangle in a 2D matrix176
589Trapping Rain Water LeetCode Solution176
590Remove Linked List Elements Leetcode Solution176
591Find the smallest positive integer value that cannot be represented as sum of any subset of a given array175
592Minimum number of subsets with distinct elements175
593Shortest Path in a Grid with Obstacles Elimination LeetCode Solution175
5943Sum Closest LeetCode Solution175
595Decode Ways175
596Find Sum of all unique sub-array sum for a given array174
597Minimum number of distinct elements after removing m items174
598Insert Interval Leetcode Solution174
599Maximum Distance in Array174
600Find minimum difference between any two elements174
601Rotate Image LeetCode Solution174
602Minimum insertions to form a palindrome with permutations allowed174
603Sort Characters By Frequency LeetCode Solution173
604Same Tree LeetCode Solution173
605Maximum Number of Chocolates to be Distributed Equally Among k Students173
606How to check if two given sets are disjoint?173
607Distance Between Bus Stops Leetcode Solution173
608Bubble sort using two Stacks173
609Frog Jump Leetcode Solution172
610Sieve of Eratosthenes172
611Longest Increasing Subsequence172
612XOR Operation in an Array Leetcode Solution172
613Painting Fence Algorithm172
614Find if an Expression has Duplicate Parenthesis or Not172
615Stone Game LeetCode172
616Defanging an IP Address Leetcode Solution172
617Minimum Cost to Hire K Workers172
618Reverse a stack without using extra space in O(n)172
619Replace Elements with Greatest Element on Right Side Leetcode Solution171
620Word Wrap Problem171
621Remove All Occurrences of a Substring LeetCode Solution171
622Permutation in String Leetcode Solution171
623Word Pattern171
624Applications of Breadth First Search and Depth First Search171
625License Key Formatting Leetcode Solution171
626Find the Duplicate Number LeetCode Solution171
627Maximum Consecutive Numbers Present in an Array170
628Smallest Good Base170
629Sort Array By Parity LeetCode Solution170
630Distance of nearest cell having 1 in a binary matrix170
631Non-overlapping sum of two sets170
632Best Time to Buy and Sell Stock LeetCode Solution170
633Printing brackets in Matrix Chain Multiplication Problem170
634House Robber170
635K Empty Slots LeetCode170
636Iterative Method to find Height of Binary Tree170
637Isomorphic Strings170
638Longest Substring with At Least K Repeating Characters LeetCode Solution169
639Tracking current Maximum Element in a Stack169
640Minimum Depth of Binary Tree Leetcode Solution169
641Moving Average from Data Stream Leetcode Solution169
642Optimal Account Balancing LeetCode Solution169
643Segregate 0s and 1s in an Array169
644Best Time to Buy and Sell Stock with Cooldown Leetcode Solution168
645Merge Two Balanced Binary Search Trees168
646Longest Substring with At Most K Distinct Characters LeetCode Solution168
647Valid Palindrome II Leetcode Solution168
648Kth Missing Positive Number Leetcode Solution168
649Coin Change Problem168
650Queries for counts of array elements with values in given range168
651GCD Of Two Numbers168
652Wiggle Sort168
653Employee Free Time LeetCode Solution168
654Binary Tree Zigzag Level Order Traversal LeetCode Solution168
655Find Maximum Level sum in Binary Tree167
656Reorganize String167
657Sum of All Odd Length Subarrays Leetcode Solution167
658Valid Palindrome167
659Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions167
660Maximum difference between first and last indexes of an element in array167
661Strobogrammatic Number LeetCode Solution167
662Path With Maximum Minimum Value LeetCode Solution167
663Check If It Is a Straight Line Leetcode Solution167
664How to Create Mergable Stack?167
665Count Good Nodes in Binary Tree Leetcode Solution167
666Find the Distance Value Between Two Arrays Leetcode Solution166
667Find Largest d in Array such that a + b + c = d166
668Delete consecutive same words in a sequence166
669Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest166
670To Lower Case Leetcode Solution166
671Flipping an Image LeetCode Solution166
672Remove Invalid Parentheses Leetcode Solution166
673Check if a queue can be sorted into another queue using a stack166
674Maximum Number of Occurrences of a Substring Leetcode Solution166
675Letter Combinations of a Phone Number165
676Partition Array Into Three Parts With Equal Sum Leetcode Solution165
677Find pairs with given sum such that elements of pair are in different rows165
678Inorder Successor of a node in Binary Tree165
679Increasing Decreasing String Leetcode Solution165
680Convert an array to reduced form165
681Maximum Number of Coins You Can Get Leetcode Solution165
682Partition Labels LeetCode Solution165
683Sum of f(a[i], a[j]) over all pairs in an array of n integers165
684Lucky Numbers in a Matrix Leetcode Solution165
685Check If Two String Arrays are Equivalent Leetcode Solution165
686Reducing Dishes LeetCode Solution165
687Print the Fibonacci numbers in reverse order165
688K Empty Slots165
689Valid Perfect Square Leetcode Solution164
690Find the Smallest Divisor given a Threshold Leetcode Solution164
691Reverse Only Letters LeetCode Solution164
692Delete Nth node from the end of the given linked list164
693Factorial Trailing Zeroes Leetcode Solution164
694Permutation Sequence LeetCode Solution164
695Number of Dice Rolls With Target Sum LeetCode Solution164
696BFS vs DFS for Binary Tree164
697Maximum Product of Two Elements in an Array Leetcode Solution163
698Form minimum number from given sequence163
699String to Integer (atoi) LeetCode Solution163
700Dynamic Programming Basics163
701Subset Sum Leetcode163
702Binary Tree zigzag level order Traversal163
703Find whether an array is subset of another array163
704Populating Next Right Pointers in Each Node163
705Longest Increasing Path in a Matrix LeetCode Solution163
706Edit Distance LeetCode Solution163
707Power of Four Leetcode Solution163
708Recover Binary Search Tree163
709Unique Paths II Leetcode Solution163
710Convert a Number to Hexadecimal Leetcode Solution163
711Find Leaves of Binary Tree LeetCode Solution163
712Ugly Number Leetcode Solution163
713Reversing a Queue using Recursion163
714Perform String Shifts Leetcode162
715Sort Array by Increasing Frequency Leetcode Solution162
716Construct BST from given Preorder Traversal162
717Reservoir Sampling162
718Merge Two Binary Trees LeetCode Solution162
719Robot Room Cleaner Leetcode Solution162
720Find the largest multiple of 3161
721Keyboard Row Leetcode Solution161
722Find the node with minimum value in a Binary Search Tree161
723Decompress Run-Length Encoded List Leetcode Solution161
724Add and Search Word – Data structure design LeetCode161
725Binomial Coefficient161
726Hamming Distance Leetcode Solution160
727Minimum Cost For Tickets Leetcode Solution160
728Bulb Switcher LeetCode Solution160
729Tiling Problem160
730Find Pair with Greatest Product in Array160
731Student Attendance Record I Leetcode Solution160
732Finding K closest element160
733Majority Element II Leetcode Solution160
734Restore IP Addresses Leetcode Solution160
735Numbers with prime frequencies greater than or equal to k159
736Check if Two Expressions With Brackets are Same159
737Generate all possible sorted arrays from alternate elements of two given sorted arrays159
738Minimum Distance Between BST Nodes Leetcode Solution159
739Word Pattern LeetCode Solution159
740Longest Span with same Sum in two Binary arrays159
741Snakes and Ladders LeetCode Solution159
742Binary Tree Maximum Path Sum LeetCode Solution159
743Rank Transform of an Array Leetcode Solution159
744Race Car LeetCode Solution159
745Kth ancestor of a node in binary tree159
746Find unique character in a string159
747Find Maximum Depth of Nested Parenthesis in a String159
748Remove brackets from an algebraic string containing + and – operators159
749Non-decreasing Array LeetCode Solution159
750Linked List Cycle158
751Stack Permutations (Check if an array is stack permutation of other)158
752String Compression LeetCode Solution158
753Number of Islands II LeetCode Solution158
754Merge K Sorted Linked Lists158
755Queue based approach for first non-repeating character in a stream158
756First Unique Character in a String LeetCode Solution158
757Invert Binary Tree LeetCode Solution158
758Minimum time required to rot all oranges158
759Largest Rectangle in Histogram LeetCode Solution158
760Maximum Depth of N-ary Tree Leetcode Solution158
761Morris Traversal158
762Sorted Linked List to Balanced BST158
763Diagonal Traversal of Binary Tree158
764Maximum 69 Number Leetcode Solution158
765Maximum Product of Three Numbers LeetCode Solution158
766Minimum Height Trees158
767Jump Game157
768Largest rectangular sub-matrix whose sum is 0157
769Final Prices With a Special Discount in a Shop Leetcode Solution157
770Largest subarray with equal number of 0s and 1s157
771Transpose Graph157
772Best Meeting Point LeetCode Solution157
773Find if Path Exists in Graph Leetcode Solution157
774Minimize Maximum Pair Sum in Array LeetCode Solution157
775Remove Nth Node From End of List Leetcode Solution157
776One Edit Distance LeetCode Solution156
777Maximum Length of a Concatenated String with Unique Characters Leetcode Solution156
778Growable array based stack156
779k-th missing element in increasing sequence which is not present in a given sequence156
780Program for Bridge and Torch problem156
781Symmetric Tree Leetcode Solution156
782Find All Duplicates in an Array LeetCode Solution156
783Partition to K Equal Sum Subsets Leetcode Solution156
784Maximum Difference Between Increasing Elements LeetCode Solution156
785Total Numbers With no Repeated Digits in a Range156
786Special Array With X Elements Greater Than or Equal X Leetcode Solution156
787Evaluate Reverse Polish Notation LeetCode Solution156
788Elements to be added so that all elements of a range are present in array156
789Check If Array Pairs Are Divisible by k LeetCode Solution156
790Crawler Log Folder Leetcode Solution155
791Longest Subarray Having Count of 1s One More than Count of 0s155
792Search in a Binary Search Tree Leetcode Solution155
793Number of NGEs to the Right155
794Search a 2D Matrix II Leetcode Solution155
795Check for Palindrome after every character replacement Query155
796Split a String in Balanced Strings Leetcode Solution155
797Count items common to both the lists but with different prices155
798Interval Tree155
799Find Median from Data Stream LeetCode Solution155
800Print a Binary Tree in Vertical Order155
801Sort an array according to the order defined by another array155
802Nested List Weight Sum II LeetCode Solution154
803Course Schedule II – LeetCode154
804N-Queens LeetCode Solution154
805Minimum Jumps to Reach Home LeetCode Solution154
806Base 7 Leetcode Solution154
807Merge Sorted Array LeetCode Solution154
808Number Complement Leetcode Solution154
809Circular Queue154
810Valid Number154
811Deletion in a Binary Tree154
812Minimum swaps to make sequences increasing154
813String comparison containing wildcards154
814Count quadruples from four sorted arrays whose sum is equal to a given value x154
815Minimum Time Visiting All Points Leetcode Solution154
816Nearest Exit from Entrance in Maze LeetCode Solution154
817Convert BST to Min Heap153
818Remove Duplicates from Sorted List II153
819Spiral Matrix II Leetcode Solution153
820Minimum number of jumps to reach end153
821Reorder Data in Log Files LeetCode Solution153
822A Space Optimized DP solution for 0-1 Knapsack Problem153
823Sort Array By Parity II Leetcode Solution153
824Maximum Profit in Job Scheduling Leetcode Solution153
825Get Maximum in Generated Array Leetcode Solution153
826Last Stone Weight II LeetCode Solution153
827Regular Expression Matching152
828Maximum size subarray sum equals k152
829Find the subarray with least average152
830Find Maximum Sum Possible Equal Sum of Three Stacks152
831Priority Queue using doubly linked list152
832Form Minimum Number From Given Sequence152
833Relative Ranks Leetcode Solution152
834Minimum Swaps to Make Strings Equal Leetcode Solution152
835Subarray Product Less Than K LeetCode Solution152
836Remove Duplicates from Sorted List LeetCode Solution152
837Iterative Preorder Traversal152
838Find all triplets with zero sum152
839Path with maximum average value151
840Sequences of given length where every element is more than or equal to twice of previous151
841Sort Colors151
842Maximum Nesting Depth of the Parentheses Leetcode Solution151
843Alien Dictionary LeetCode Solution151
844Identify and Mark Unmatched Parenthesis in an Expression151
845Permutation Coefficient151
846Subset with sum divisible by m151
847Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution151
848Tree Traversal (Preorder, Inorder & Postorder)151
849LCS (Longest Common Subsequence) of three strings151
850Insert into a Binary Search Tree Leetcode Solution151
851Partition List Leetcode Solution151
852Number of Days Between Two Dates LeetCode Solution151
853Can Place Flowers LeetCode Solution151
854Top K Frequent Words LeetCode Solution150
855Given an Array of Pairs Find all Symmetric Pairs in it150
856Check if a given array can represent Preorder Traversal of Binary Search Tree150
857Check whether a given Binary Tree is Complete or not150
858Valid Parentheses Leetcode Solution150
859Count Distinct Elements in Every Window of Size K150
860Level order Traversal in Spiral Form150
861Count Negative Numbers in a Sorted Matrix LeetCode Solution150
862Design a Stack With Increment Operation Leetcode Solution150
863Subsequence of Size K With the Largest Even Sum LeetCode Solution150
864Sum of nearest smaller and greater number150
865Minimum Sum Path in a Triangle150
866Guess Number Higher or Lower LeetCode Solution150
867Brick Wall LeetCode Solution150
868Friends Pairing Problem150
869Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution150
870Find the Only Repetitive Element Between 1 to N-1150
871Minimum Number of Taps to Open to Water a Garden LeetCode Solution150
872Find All Possible Recipes from Given Supplies LeetCode Solution150
873Binary Search Tree Search and Insertion150
874Check if stack elements are pairwise consecutive149
875Sorted Array to Balanced BST149
876Destination City Leetcode Solution149
877Range sum queries without updates149
878Range LCM Queries149
879Missing Element in Sorted Array LeetCode Solution149
880Clone Graph LeetCode Solution149
881Union and Intersection of two Linked Lists149
882Brightest Position on Street LeetCode Solution149
883Matrix Chain Multiplication149
884GCDs of given index ranges in an array149
885Find distance between two nodes of a Binary Tree149
886Distinct adjacent elements in an array149
887Repeated Substring Pattern LeetCode Solution149
888Balanced Expression with Replacement149
889Find Common Characters Leetcode Solution149
890K’th Largest Element in BST when modification to BST is not allowed148
891Water Bottles Leetcode Solution148
892Check if an Array is Stack Sortable148
893BFS for Disconnected Graph148
894Time Based Key-Value Store LeetCode Solution148
895Design Browser History LeetCode Solution148
896Diagonal Traverse LeetCode Solution148
897An Interesting Method to generate Binary Numbers from 1 to n148
898Construct Complete Binary Tree from its Linked List Representation148
899Minimum sum of multiplications of n numbers148
900Rearrange an Array Such that arr[i] is equal to i148
901Three way partitioning of an array around a given range148
902Count ways to reach the nth stair using step 1, 2 or 3148
903Shortest Word Distance Leetcode Solution148
904Rearrange Spaces Between Words Leetcode Solution147
905Least Number of Unique Integers after K Removals Leetcode Solution147
906Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i147
907Lemonade Change Leetcode Solution147
908Guess Number Higher or Lower II147
909Averages of Levels in Binary Tree147
910Delete And Earn147
911Spiral Matrix III LeetCode Solution147
912Queries for GCD of all numbers of an array except elements in a given range147
913Daily Temperatures Leetcode Solution147
914Convert Sorted List to Binary Search Tree147
915Insert Delete GetRandom147
916Diagonal Traversal LeetCode Solution147
917Find all permuted rows of a given row in a matrix146
918Special Positions in a Binary Matrix Leetcode Solution146
919Vertical sum in a given binary tree146
920Set Matrix Zeroes Leetcode Solution146
921Queue using Stacks146
922Count Subarrays with Same Even and Odd Elements146
923Robot Bounded In Circle LeetCode Solution146
924Maximum Score After Splitting a String Leetcode Solution146
925Check if the given array can represent Level Order Traversal of Binary Search Tree145
926Largest area rectangular sub-matrix with equal number of 1’s and 0’s145
927Split Array Into Consecutive Subsequences145
928Maximum Subarray Sum Excluding Certain Elements145
929Dividing Array into Pairs With Sum Divisible by K145
930Binary Tree Longest Consecutive Sequence LeetCode Solution145
931Check if any two intervals overlap among a given set of intervals145
932Merge Two Sorted Lists Leetcode145
933A program to check if a binary tree is BST or not145
934Construct the Rectangle Leetcode Solution145
935Palindrome Partitioning Leetcode Solution145
936Number of Distinct Islands Leetcode Solution145
937Median of Two Sorted Arrays145
938Iterative Postorder Traversal Using Two Stacks145
939Alien Dictionary145
941Three Consecutive Odds Leetcode Solution144
9423 Sum144
943Lexicographical Numbers Leetcode Solution144
944Longest Palindromic Subsequence144
945All Unique Triplets that Sum up to a Given Value144
946Construct BST from its given Level Order Traversal144
947Print Fibonacci sequence using 2 variables144
948Stone Game II Leetcode143
949Analyze User Website Visit Pattern LeetCode Solution143
950Remove Duplicates from Sorted List II LeetCode Solution143
951Maximize Sum of Array after K Negations Leetcode Solution143
952Minimum Height Trees LeetCode Solution143
953Count Submatrices With All Ones LeetCode Solution143
954Strongly Connected Component143
955Sliding Window Maximum143
956Number of Equivalent Domino Pairs Leetcode Solution143
957Maximum Frequency Stack Leetcode Solution143
958Create Maximum Number143
959Maximum Product Subarray143
960Difference Array | Range update query in O(1)143
961Unique Paths II142
962My Calendar I LeetCode Solution142
963Shuffle 2n integers as without using extra space142
964Infix to Postfix142
965Count subarrays where second highest lie before highest142
966Binary array after M range toggle operations142
967Trim a Binary Search Tree142
968Collect maximum points in a grid using two traversals142
969Can Make Arithmetic Progression From Sequence Leetcode Solution142
970Length of Longest Fibonacci Subsequence142
971Find the Difference Leetcode Solution141
972Find postorder traversal of BST from preorder traversal141
973The Painter’s Partition Problem141
974Symmetric Tree141
975Count Primes in Ranges141
976Minesweeper LeetCode Solution141
977Merging Intervals141
978Intersection of Two Linked Lists LeetCode Solution141
979Find Maximum of Minimum for Every Window Size in a Given Array141
980Count pair with Given Sum141
981Kth Smallest Element in a BST Leetcode Solution141
982Climbing stairs140
983Height of a generic tree from parent array140
984Pattern Occurrences using Stack140
985Palindrome Partitioning140
986Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution140
987K Closest Points to Origin Leetcode Solution140
988Sign of the Product of an Array LeetCode Solution140
989Word Break140
990Valid Boomerang Leetcode Solution140
991Reverse Nodes in K-Group140
992Product of Array Except Self LeetCode Solution140
993Minimum Index Sum of Two Lists140
994Boundary Traversal of binary tree140
995Longest Nice Substring LeetCode Solution140
996Friends Of Appropriate Ages LeetCode Solution139
997Find the First Circular Tour that visits all the Petrol Pumps139
998Binary Search Tree Delete Operation139
999Asteroid Collision LeetCode Solution139
1000Breadth First Search (BFS) for a Graph139
1001Segment Tree139
1002Graph Valid Tree LeetCode Solution139
1003Level Order Traversal of Binary Tree139
1004Number Of Longest Increasing Subsequence139
1005Largest Substring Between Two Equal Characters Leetcode Solution139
1006Largest Number Leetcode Solution139
1007Newman-Conway Sequence139
1008Largest divisible pairs subset139
1009Maximum Sum of 3 Non-Overlapping Subarrays139
1010Maximum length subsequence with difference between adjacent elements as either 0 or 1139
1011Next Greater Element III LeetCode Solution138
1012Rearrange array such that even positioned are greater than odd138
1013Find number of pairs in an array such that their XOR is 0138
1014Compute nCr % p138
1015Scramble String LeetCode Solution138
1016Double the first element and move zero to end138
1017Shortest Completing Word Leetcode Solution138
1018Maximum subsequence sum such that no three are consecutive138
1019The Maze III LeetCode Solution138
1020Construction of Longest Increasing Subsequence (N log N)138
1021Insertion in a Binary Tree138
1022Maximum Length of Repeated Subarray138
1023Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’138
1024Find Duplicate Subtrees138
1025Boolean Parenthesization Problem138
1026Maximum Number of Ways to Partition an Array LeetCode Solution138
1027Merge Sort138
1028Construct Binary Tree from given Parent Array representation138
1029Longest subsequence such that difference between adjacents is one138
1030K maximum sums of overlapping contiguous sub-arrays138
1031Partition Equal Subset Sum137
1032String Matching in an Array Leetcode Solution137
1033Build an Array With Stack Operations Leetcode Solution137
1034Depth First Search (DFS) for a Graph137
1035Maximum Product of Indexes of Next Greater on Left and Right137
1036Maximum weight transformation of a given string137
1037Number of palindromic paths in a matrix137
1038Iterative Depth First Traversal of Graph137
1039Kill Process LeetCode Solution137
1040Design Hit Counter LeetCode Solution137
1041Decrypt String from Alphabet to Integer Mapping Leetcode Solution137
1042Binary Search Tree137
1043Make The String Great Leetcode Solution137
1044Ugly Numbers137
1045Advantages of BST over Hash Table136
1046Level order traversal using two Queues136
1047Serialize and Deserialize Binary Tree136
1048Morris Inorder Traversal136
1049Available Captures for Rook Leetcode Solution136
1050First missing positive136
1051Count minimum steps to get the given desired array136
1052Invalid Transactions LeetCode Solution135
1053Lowest Common Ancestor135
1054Custom Sort String Leetcode Solution135
1055Find a Peak Element II LeetCode Solution135
1056Add two numbers135
1057Maximum difference between frequency of two elements such that element having greater frequency is also greater135
1058Balanced Binary Tree135
1059Bitwise AND of Numbers Range LeetCode Solution135
1060Kth Smallest Element in a Sorted Matrix LeetCode Solution135
1061Generate Parentheses Leetcode Solution134
1062Count pairs from two sorted arrays whose sum is equal to a given value x134
1063Regular Expression Matching Regular Expression Matching LeetCode Solution134
1064Remove Duplicates from Sorted Array II Leetcode Solution134
1065Validate Binary Search Tree134
1066Path Sum II LeetCode Solution134
1067Super Ugly Number134
1068Ugly Number II LeetCode Solution134
1069Combination Sum IV LeetCode Solution134
1070Employee Importance LeetCode Solution134
1071Minimum Size Subarray Sum134
1072Find Peak Element134
1073Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution133
1074Binary Tree Right Side View LeetCode Solution133
1075Defanging an IP Address LeetCode Solution133
1076Increasing Triplet Subsequence LeetCode Solution133
1077Recover Binary Search Tree Leetcode Solution133
1078Implement Trie (Prefix Tree) Leetcode Solution133
1079Root to Leaf path with target sum Leetcode Solutions133
1080Move all negative elements to end in order with extra space allowed133
1081Find whether a subarray is in form of a mountain or not133
1082Rearrange array such that even index elements are smaller and odd index elements are greater133
1083Subarrays with K Different Integers Leetcode Solution132
1084Consecutive Characters LeetCode Solution132
1085Search in Sorted Rotated Array132
1086Number of Closed Islands Leetcode Solution132
1087Largest BST Subtree LeetCode Solution132
1088Day of the Year Leetcode Solution132
1089Populating Next Right Pointers in Each Node Leetcode Solution132
1090Remove Palindromic Subsequences Leetcode Solution131
1091Serialize and Deserialize Binary Tree LeetCode Solution131
1092Find Smallest Range Containing Elements from k Lists131
1093Number of Students Doing Homework at a Given Time Leetcode Solution131
1094Types of Binary Tree131
1095Smallest Common Region Leetcode Solution131
1096Longest Bitonic Subsequence131
1097Count Largest Group Leetcode Solution131
1098Find the minimum distance between two numbers130
1099Level of Each node in a Tree from source node130
1100Print all triplets in sorted array that form AP130
1101Clone a Binary Tree with Random Pointers130
1102Convert BST into a Min-Heap without using array130
1103Number of siblings of a given Node in n-ary Tree130
1104Find maximum difference between nearest left and right smaller elements130
1105Remove duplicates from sorted array130
1106Minimum Absolute Difference in BST Leetcode Solution130
1107Maximize Distance to Closest Person LeetCode Solution130
1108Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1109Binary Tree Data Structure130
1110Palindrome Permutation LeetCode Solution130
1111Distinct Subsequences130
1112Find Three Element From Different Three Arrays Such That a + b + c = sum130
1113Next Permutation Leetcode Solution130
1114Third Maximum Number Leetcode Solution129
1115Cutting a Rod129
1116Print Next Greater Number of Q queries129
1117Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution129
1118Divisible Pairs Counting129
1119Thousand Separator Leetcode Solution129
1120Mean of Array After Removing Some Elements Leetcode Solution129
1121Write Code to Determine if Two Trees are Identical129
1122Path Sum129
1123Sum of Even Numbers After Queries129
1124Bottom View of a Binary Tree129
1125Construct K Palindrome Strings LeetCode Solution129
1126Diameter of N-Ary Tree LeetCode Solution128
1127Delete Nodes and Return Forest Leetcode Solution128
1128Constant time range add operation on an array128
1129Products of ranges in an array128
1130Longest Increasing Consecutive Subsequence128
1131Maximum Product Subarray128
1132Print Right View of a Binary Tree128
1133Iterative method to find ancestors of a given binary tree128
1134Valid Tic-Tac-Toe State LeetCode Solution128
1135Minimum Score Triangulation of Polygon Leetcode Solution128
1136Queries for Number of Distinct Elements in a Subarray128
1137Reformat The String Leetcode Solution128
1138Minimum sum of squares of character counts in a given string after removing k characters128
1139Maximum Product of Splitted Binary Tree LeetCode Solution127
1140Prime Palindrome LeetCode Solution127
1141Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution127
1142Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1143Palindromic Substrings Leetcode Solution127
1144Search an Element in Sorted Rotated Array126
1145Subset Sum Problem in O(sum) space126
1146Search Insert Position126
1147Cells with Odd Values in a Matrix LeetCode Solution126
1148Swap Nodes In Pairs126
1149Moser-de Bruijn Sequence126
1150Find maximum length Snake sequence126
1151Transform a BST to Greater sum Tree125
1152Print modified array after executing the commands of addition and subtraction125
1153Maximum Binary Tree125
1154Topological Sorting125
1155Priority Queue125
1156Red-Black Tree Introduction125
1157Merge two BSTs with limited extra space125
1158Bus Routes Leetcode Solution125
1159Kth Smallest Number in Multiplication Table Leetcode Solution125
1160Closest Binary Search Tree Value Leetcode Solution124
1161Maximize sum of consecutive differences in a circular array124
1162Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution124
1163Check Array Formation Through Concatenation Leetcode Solution124
1164Minimum Sideway Jumps LeetCode Solution123
1165Find Largest Value in Each Tree Row LeetCode Solution123
1166Web Crawler LeetCode Solution123
1167Possible Bipartition LeetCode Solution123
1168K’th Largest element in BST using constant extra space123
1169Rotate Array123
1170Decision Tree123
1171Golomb sequence123
1172Given a binary tree, how do you remove all the half nodes?123
1173Minimum Cost to Move Chips to The Same Position LeetCode Solution123
1174Count even length binary sequences with same sum of first and second half bits123
1175Search Suggestions System LeetCode Solution123
1176Factorial Trailing Zeroes LeetCode Solution122
1177Longest Repeated Subsequence122
1178Find a sorted subsequence of size 3 in linear time122
1179Binary Tree to Binary Search Tree Conversion122
1180Contiguous Array LeetCode Solution122
1181Maximum number of segments of lengths a, b and c122
1182Compare Strings by Frequency of the Smallest Character Leetcode Solution122
1183Find the smallest binary digit multiple of given number122
1184Minimum Moves to Equal Array Elements LeetCode Solution122
1185Sum of Left Leaves LeetCode Solution121
1186Decrease Elements To Make Array Zigzag LeetCode Solution121
1187Matchsticks to Square Leetcode Solution121
1188Swapping Nodes in a Linked List Leetcode Solution121
1189Lowest Common Ancestor in Binary Search Tree121
1190Maximum Depth Of Binary Tree121
1191Closest Leaf in a Binary Tree LeetCode Solution121
1192Graph and its representation121
1193Reverse a Path in BST using Queue121
1194Valid Triangle Number121
1195First Bad Version121
1196Reformat Date LeetCode Solution120
1197Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution120
1198Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1199Maximum sum of pairs with specific difference120
1200Queue Reconstruction by Height120
1201Count Pairs Whose Products Exist in Array120
1202Maximum sum bitonic subarray120
1203Number of Orders in the Backlog Leetcode Solution120
1204Range Queries for Longest Correct Bracket Subsequence120
1205Path Crossing Leetcode Solution119
1206Concatenation of Array LeetCode Solution119
1207Moving Stones Until Consecutive Leetcode Solution119
1208Champagne Tower LeetCode Solution119
1209How to print maximum number of A’s using given four keys119
1210Lowest Common Ancestor of a Binary Tree Leetcode Solution119
1211Divide Two Integers Leetcode Solution118
1212Queries on Probability of Even or Odd Number in given Ranges118
1213Write a function to get the intersection point of two Linked Lists118
1214Perfect Squares LeetCode Solution118
1215BST to a Tree with Sum of all Smaller Keys118
1216Minimum Swaps To Make Sequences Increasing LeetCode Solution118
1217Kth Smallest Element in a BST118
1218Check if all levels of two Binary Tree are anagrams or not117
1219Replace two consecutive equal values with one greater117
1220Maximize Elements Using Another Array117
1221Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution117
1222Guess The Word117
1223Valid Perfect Square LeetCode Solution117
1224Maximum Value at a Given Index in a Bounded Array LeetCode Solution117
1225Integer Break LeetCode Solution117
1226LRU Cache Leetcode Solution117
1227Array Queries for multiply replacements and product117
1228Maximum sum of a path in a Right Number Triangle116
1229Mean of range in array116
1230Count Subsets Having Distinct Even Numbers116
1231Flatten 2D Vector LeetCode Solution116
1232Power of Two116
1233New 21 Game116
1234Sliding Window Median Leetcode Solution116
1235Print modified array after multiple array range increment operations115
1236Check Completeness of a Binary Tree LeetCode Solution115
1237Design Skiplist LeetCode Solution115
1238Maximum Array from Two given Arrays Keeping Order Same115
1239Missing Number115
1240The kth Factor of n Leetcode Solution115
1241Range Sum Query using Sparse Table115
1242Parallel Courses II LeetCode Solution115
1243Arithmetic Slices II – Subsequence LeetCode Solution115
1244Graph Cloning114
1245Contiguous Array114
1246Find minimum number of merge operations to make an array palindrome114
1247Check for Identical BSTs without building the trees114
1248Bold Words in String LeetCode Solution114
1249Find k-th smallest element in BST (Order Statistics in BST)114
1250Check if each internal node of a BST has exactly one child114
1251Longest Common Prefix Using Word by Word Matching114
1252Find Minimum in Rotated Sorted Array II LeetCode Solution114
1253Merge k Sorted Lists Leetcode Solution113
1254Print Ancestors of a Given Binary Tree Node Without Recursion113
1255Largest Plus Sign Leetcode Solution113
1256Maximum Product Subarray113
1257Symmetric Tree LeetCode Solution Leetcode Solution112
1258Print n terms of Newman-Conway Sequence112
1259Image Overlap LeetCode Solution112
1260Check if two nodes are on the same path in a Tree112
1261Verify Preorder Serialization of a Binary Tree111
1262Count and Toggle Queries on a Binary Array111
1263Excel Sheet Column Title LeetCode Solution111
1264Minimum Remove to Make Valid Parentheses LeetCode Solution111
1265Smallest Range II Leetcode Solution110
1266Minimum Time to Collect All Apples in a Tree LeetCode Solution110
1267Number of elements less than or equal to a given number in a given subarray110
1268Check If a String Can Break Another String Leetcode Solution109
1269Palindrome Partitioning109
1270Next greater element109
1271Min Cost Climbing Stairs LeetCode Solution108
1272Orderly Queue LeetCode Solution108
1273Koko Eating Bananas LeetCode Solution107
1274Different Ways to Add Parentheses Leetcode Solution107
1275Check in binary array the number represented by a subarray is odd or even106
1276Peeking Iterator LeetCode Solution106
1277Largest Submatrix With Rearrangements LeetCode Solution106
1278Longest Substring Without Repeating Characters Leetcode Solution106
1279Merge Sorted Array105
1280Newman–Shanks–Williams prime105
1281Check if X can give change to every person in the Queue105
1282Queries for Decimal Values of Subarrays of a Binary Array104
1283Range Minimum Query (Square Root Decomposition and Sparse Table)104
1284Encoded String With Shortest Length LeetCode Solution102
1285Find maximum average subarray of k length102
1286Maximum Sum Increasing Subsequence102
1287Array Nesting Leetcode Solution102
1288Arranging Coins Leetcode Solution102
1289Number of indexes with equal elements in given range102
1290Maximum product of an increasing subsequence102
1291Check given array of size n can represent BST of n levels or not101
1292Convert a BST to a Binary Tree such that sum of all greater keys is added to every key100
1293Find the Winner of the Circular Game LeetCode Solution99
1294Minimum Number of People to Teach LeetCode Solution99
1295Convert to Base -2 LeetCode Solution99
1296Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1297Binary Tree to Binary Search Tree Conversion using STL set98
1298Random Pick Index LeetCode Solution98
1299Continuous Subarray Sum LeetCode Solution98
1300Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution98
1301Jump Game IV LeetCode Solution98
1302Vertical Order Traversal of Binary Tree LeetCode Solution97
1303Reach a Number LeetCode Solution97
1304Add Two Numbers II Leetcode Solution97
1305Queries on XOR of greatest odd divisor of the range96
1306Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution95
1307Palindrome Number LeetCode Solution95
1308Insert Delete GetRandom O(1) Leetcode Solution95
1309Design Underground System Leetcode Solution91
1310Shifting Letters LeetCode Solution90
1311Print Maximum Length Chain of Pairs89
1312Detect Capital Leetcode Solution88
1313Design A Leaderboard Leetcode Solution88
1314Substring with Concatenation of All Words Leetcode Solution85
1315Minimum Swaps to Group All 1’s Together Leetcode Solution84
1316Count Sub Islands LeetCode Solution83
1317Top K Frequent Elements LeetCode Solution83
1318Minimum Path Sum Leetcode Solution82
1319Binary Tree Inorder Traversal LeetCode Solution81
1320Odd Even Linked List Leetcode Solution79
1321Maximum Population Year LeetCode Solution78
1322Decode String Leetcode Solution78
1323Longest Common Subsequence LeetCode Solution78
1324Best Meeting Point LeetCode Solution77
1325Find the Town Judge LeetCode Solution77
1326Find the Town Judge LeetCode Solution76
1327Shortest Unsorted Continuous Subarray LeetCode Solution76
1328Sum Root to Leaf Numbers LeetCode Solution75
1329Rectangle Overlap LeetCode Solution72
1330Maximum Population Year LeetCode Solution71
1331Design Add and Search Words Data Structure LeetCode Solution71
1332Score of Parenthesis LeetCode Solution69
1333Flatten Binary Tree to Linked List LeetCode Solution69
1334Stone Game IV LeetCode Solution68
1335Insert into a Sorted Circular Linked List LeetCode Solution68
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution65
1338Is Graph Bipartite? LeetCode Solution64
1339Valid Triangle Number LeetCode Solution64
1340Divide Chocolate LeetCode Solution57
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution53
1342Reverse Integer Leetcode Solution47
1343Range Sum of BST LeetCode Solution46
1344Find K Closest Elements LeetCode Solution43
1345Sort Colors LeetCode Solution43
1346Rotate String LeetCode Solution40
1347Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution40
1348Excel Sheet Column Number LeetCode Solution39
1349H-Index Leetcode Solution20
1350Maximum Size Subarray Sum Equals k Leetcode Solution20
1351High Five LeetCode Solution19
1352Camelcase Matching Leetcode Solution18
1353Monotonic Array Leetcode Solution16
1354Valid Anagram Leetcode Solution14
1355Group Shifted Strings Leetcode Solution14
1356Peak Index in a Mountain Array LeetCode Solution12
1357Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution12
1358Next Permutation LeetCode Solution11
1359Unique Binary Search Trees LeetCode Solution11
1360Next Greater Element I Leetcode Solution11
1361Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution11
1362Valid Triangle Number LeetCode Solution10
1363Container With Most Water LeetCode Solution10
1364Flatten Binary Tree to Linked List LeetCode Solution10
1365Minimum Number of Arrows to Burst Balloons LeetCode Solution10
1366Closest Binary Search Tree Value II LeetCode Solution10
1367Paint House LeetCode Solution9
1368Isomorphic Strings LeetCode Solution9
1369Find Peak Element LeetCode Solution8
1370Sentence Screen Fitting LeetCode Solution8
1371Swim in Rising Water LeetCode Solution7
1372Group Anagrams LeetCode Solution7
1373Binary Search LeetCode Solution6
1374Sliding Window Maximum LeetCode Solution6
1375Most Stones Removed with Same Row or Column LeetCode Solution4
Translate »