Best Meeting Point LeetCode Solution

Difficulty Level Hard
Frequently asked in Amazon Bloomberg Expedia Facebook Google Microsoft Snapchat Twitter
Array Math Matrix Reddit SortingViews 71

Problem Statement:

Best Meeting Point Leetcode Solution says – Given a m x n binary grid grid where each 1 marks the home of one friend, return the minimal total travel distance. The total travel distance is the sum of the distances between the houses of the friends and the meeting point. The distance is calculated using Manhattan Distance, where distance(p1, p2) = |p2.x - p1.x| + |p2.y - p1.y|.

Example:

Input:

Best Meeting Point Leetcode SolutionPin

 grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]]

Output:

 6

Explanation:

Given three friends living at (0,0), (0,4), and (2,2). The point (0,2) is an ideal meeting point, as the total travel distance of 2 + 2 + 2 = 6 is minimal.

Approach:

Idea:

The idea is to select the coordinate closest to all the points in order to minimize the total distance. If we consider this problem only for a 1 dimension then the point i.e. closest to all the points turns out to be the median of the points. Now in the case of 2 dimensions, we need to consider the point which is median w.r.t both the dimensions. So we just need to calculate the median of the given points.

We first create 2 lists one for the x coordinates and another for the y coordinates for all the values where the value is 1. Now we will sort them and will take the median value from both the lists, say x_median and y_median. This (x_median,y_median) will be our meeting point. Finally, we calculate the Manhattan distance of all the friends from this median coordinate.

Code:

Best Meeting Point Leetcode C++ Solution:

class Solution {
public:
    int minTotalDistance(vector<vector<int>>& grid) {
        int friends=0;
        int n = grid.size();
        int m = grid[0].size();
        
        vector<int> x_cords;
        vector<int> y_cords;
        
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(grid[i][j]==1){
                    x_cords.push_back(i);
                    y_cords.push_back(j);
                    friends++;
                }
            }
        }
        
        sort(x_cords.begin(),x_cords.end());
        sort(y_cords.begin(),y_cords.end());
        
        int median_x = x_cords[friends/2];
        int median_y = y_cords[friends/2];
            
        int distance=0;
        for(int i=0;i<friends;i++){
            distance += abs(x_cords[i]-median_x) + abs(y_cords[i]-median_y);
        }
        return distance;
    }
};

Best Meeting Point Leetcode Python Solution

class Solution:
    def minTotalDistance(self, grid: List[List[int]]) -> int:
        friends=0;
        n = len(grid);
        m = len(grid[0]);
        
        x_cords = []
        y_cords = []
        
        for i in range(n):
            for j in range(m):
                if grid[i][j]==1:
                    x_cords.append(i)
                    y_cords.append(j)
                    friends+=1
        
        x_cords.sort();
        y_cords.sort();
        
        median_x = x_cords[friends//2]
        median_y = y_cords[friends//2]
            
        distance=0
        for i in range(friends):
            distance += abs(x_cords[i]-median_x) + abs(y_cords[i]-median_y)
        return distance

Complexity Analysis of Best Meeting Point Leetcode Solution:

  • Time Complexity: The time complexity of the above code is O(n*m) because we are traversing the entire grid.
  • Space Complexity: The space complexity of the above code is O(max(n,m)) because we are using a list to store the x and y coordinates.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2822
2Java program to find the number of Nodes in a Binary Tree2505
3Reverse a string without affecting special characters2465
4Delete a node of a linked list at given position1979
5Palindrome using Recursion1839
6Insert nodes in a linked list in a sorted way (Ascending Order)1662
7Find elements pair from array whose sum equal to number1650
8Sort Elements by Frequency of Occurrences1633
9Write a program to print all permutations of a given string1607
10Find Minimum Distance Between Two Numbers in an Array1477
11Create a Doubly Linked List1445
12Quick Sort1422
13Reverse an Array1414
14Smallest window in a string containing all characters of another string1399
15Find a Triplet That Sum to a Given Value1357
16Recursively remove all adjacent duplicates1356
17First Repeating Element1341
18Arrange Even and Odd number such that Odd comes after Even1325
19Sum of numbers in String1319
20Smallest Positive Number Missing in an Unsorted Array1285
21Check if the Elements of an Array are Consecutive1256
22Detect a loop in the Linked List1239
23Largest Sum Contiguous Subarray1232
24Quick Sort on SIngly Linked List1219
25Subarray with Given Sum1216
26Print all Possible Combinations of R Elements in a given Array of size N1207
27Recursive function to do substring search1198
28Find the Maximum Repeating Number in Array1158
29Binary Tree Level order traversal in Java1128
30Find the First and Second Smallest Elements1123
31Check if two linked lists are identical1104
32Maximum Subarray Sum using Divide and Conquer1099
33Remove characters from first string which are in second1072
34Find Leaders in an Array1063
35Swap nodes in the linked list1039
36Find the Number Occurring Odd Number of Times in an Array1006
37Arrange given Numbers to Form the Biggest Number II995
38Find the second most frequent character990
39Given a string find its first non-repeating character972
40Find Triplet in Array With a Given Sum965
41Given a sorted array and a number x, find the pair in array whose sum is closest to x956
42Total number of occurrences of a given item in the linked list955
43A Program to check if strings are rotations of each other or not946
44Print all possible words from phone digits935
45Find the Missing Number927
46Rearrange Positive and Negative Numbers Alternatively in Array922
47Longest Palindromic Substring906
48Segregate even and odd nodes in a linked list884
49Print Longest common subsequence883
50Union and Intersection of Two Linked Lists874
51Transform one string to another using minimum number of given operations869
52Rearrange given Array in Maximum Minimum Form849
53Check rearranged string can form a palindrome847
54Count Possible Triangles821
55Iterative Implementation of Quick Sort816
56Multiplication of Two Matrices804
57Check if the linked list is palindrome797
58Rotate a Linked List795
59Count of Triplets With Sum Less than Given Value794
60Stock Buy Sell to Maximize Profit792
61Concatenation of two strings763
62Tug of War761
63Count Number of Substrings with K Distinct Character’s758
64Print all duplicates in the input string755
65Find Nearest Greater and Smaller Element748
66Find Pythagorean Triplets from Array739
67The Celebrity Problem738
68Reverse String Without Temporary Variable735
69Remove ‘b’ and ‘ac’ from a given string731
70Find all Common Elements in Given Three Sorted Arrays729
71Remove all duplicates in an unsorted linked list711
72Find the Row with Maximum Number of 1’s708
73Find the Peak Element from an Array703
74Find the subarray whose sum is equal to a given number X697
75Remove Minimum Characters so that Two Strings Become Anagrams690
76Find Smallest Missing Number in a Sorted Array689
77Addition of Two Matrices687
78A Product Array Puzzle687
79Insertion Sort686
80Implement Two Stacks in an Array679
81Generate all Binary Strings Without Consecutive 1’s678
82Maximum Sum of Non Consecutive Elements669
83Maximum Product Subarray II659
84Lexicographic rank of string655
85Check if Two given Matrices are Identical647
86Multiplication of Previous and Next645
87Subtraction of Two Matrices636
88Merge K Sorted Arrays and Print Sorted Output633
89Move All the Zeros to the End of the Given Array631
90Online Algorithm for Checking Palindrome in a Stream626
91Form Minimum Number from Given Sequence of D’s and I’s625
92Divide a string in N equal parts623
93Maximum Circular Subarray Sum615
94Check whether two strings are anagram of each other615
95Sort a linked list that is sorted alternating ascending and descending610
96Remove recurring digits in a given number610
97Sort a stack using a temporary stack609
98Find the Minimum Element in a Sorted and Rotated Array608
99Subarray and Subsequence602
100Move last element of the Linked List at first place602
101First Circular Tour to Visit all the Petrol Bunks602
102Largest Subarray with Equal Number of 0’s and 1’s599
103Flattening a linked list593
104Compare two strings(linked lists)592
105Maximum Element in an Array which is Increasing and then Decreasing590
106Palindrome Permutations of a String585
107Elements Appear more than N/K times in Array584
108Majority Element577
109Run length encoding576
110Palindromes in a given range574
111Minimum insertions to form a shortest palindrome573
112Print all permutations with repetition572
113Pangram Checking572
114Merge a linked list into another at alternate positions569
115Minimum Characters to be Added at Front to Make String Palindrome566
116Remove all duplicates in a sorted linked list565
117Rearrange a given linked list in-place564
118Minimum number of Merge Operations to make an Array Palindrome562
119Most repeating character in a string559
120Rotate string to get lexicographically minimum string558
121Repeated Subsequence of Length Two or More557
122Print all anagrams together in a sequence of words552
123Reorder an Array According to the Given Indexes551
124Pancake Sorting Problem543
125Two Sum Leetcode Solution539
126Merge Overlapping Intervals II539
127Clone a Linked List with next and random pointer538
128Transpose of a Matrix528
129Size of The Subarray With Maximum Sum528
130Removing Spaces from a String using stringstream522
131Remove duplicates from a string522
132Smallest Palindrome after Replacement521
133Remove Extra Spaces from a String521
134Check if a given string is a rotation of a palindrome519
135Maximum Sum Increasing Subsequence518
136Partition Problem517
137Longest Palindrome can be Formed by Removing or Rearranging Characters514
138Check whether Strings are K Distance Apart or Not504
139Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized504
140Delete Last Occurrence502
141Generate all Binary Strings from Given Pattern502
142Insert Node in the Sorted Linked List502
1433Sum Leetcode Solution500
144Length of Longest valid Substring499
145Check if Two given Strings are Isomorphic to each other494
146Maximum difference between two elements such as larger element comes after smaller489
147Program to Toggle all Characters in a String486
148Given string is interleaving of two other strings or not484
149Count Minimum Steps to Get the given Array481
150Number of Smaller Elements on Right Side481
151Merge sort better than quick sort for linked lists479
152Find Pair with Given Difference474
153Check length of a String is Equal to the Number Appended at its Last472
154Check if all Rows of a Matrix are Circular Rotations of Each Other471
155Find nth node of the Linked list from the end470
156Longest Common Prefix using Divide and Conquer470
157Find a Fixed Point in a Given Array466
158Sort 0s 1s and 2s in an Array464
159Print all interleavings of given two strings458
160Compare Two Version Numbers457
161Reverse words in a given string455
162Merge two sorted linked lists such that merged list is in reverse order454
163Find the Subarray of given length with Least Average453
164Median of Two Sorted Arrays LeetCode Solution453
165Reorder Array Using Given Indexes452
166Split linked list using alternate nodes450
167Print Reverse of a string (Recursion)450
168Find K Length Subarray of Maximum Average439
169Print string of odd length in ‘X’ format438
170Find Element Using Binary Search in Sorted Array435
171Swap Kth Node from beginning with Kth Node from End433
172Print all Palindromic Partitions of a String432
173Find Duplicates in an Array in Most Efficient Way429
174print all palindromic partitions422
175Maximum Length of Chain Pairs418
176Shortest Superstring Problem417
177Flatten a multilevel linked list416
178Check if String Follows Order of Characters by a Pattern or not413
179Sorting a K Sorted Array410
180Sort a String According to Another String404
181Longest Span with same Sum in two Binary Arrays II399
182Find a Sorted Subsequence of size 3398
183Reverse a Linked List in groups396
184Program to add two binary digits394
185Recursively print all the sentences that can be formed from list of word lists392
186Find the two Numbers with Odd Occurrences in an Unsorted Array390
187Longest Common Prefix Using Binary Search II385
188Reverse a Singly Linked List (Iterative/Non-Recursive)383
189Check if String can Become Empty by Recursively Deleting given Substring380
190Kth Non-repeating Character379
191Caesar Cipher379
192Rearrange a linked list in Zig-Zag378
193Rotate Image by 90 degrees374
194Pancake Sorting374
195Longest Common Prefix Word by Word Matching371
196Permutations of a Given String Using STL371
197Perfect Reversible String368
198Merging Two Sorted Arrays364
199Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes362
200Sort a linked list with 0s, 1s and 2s362
201Find the point where a monotonically increasing function becomes positive first time362
202Increasing Subsequence of Length three with Maximum Product361
203Find First non-repeating character in a string361
2041`s and 2`s complement of binary number358
205Four Elements that Sum to Given355
206Delete N nodes after M354
207List items containing all characters of a given word352
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Split a string344
211Palindrome string (number)343
212Minimum Characters to be Removed to Make a Binary String Alternate340
213Recursive Implementation of atoi()336
214Check if a Linked list of Strings form a Palindrome333
215Print All Distinct Elements of the Array332
216Convert a String that is Repetition of a Substring of Length K331
217Sorting the array of strings331
218Valid Parentheses LeetCode Solution329
219Maximum occurring character in a string329
220Reverse a singly linked list recursively328
221Even Substring Count328
222Find the first Repeating Number in a Given Array326
223Can we reverse a linked list in less than O(n) time ?326
224Print Shortest Path to Print a String on Screen323
225Binary Tree to Doubly linked list323
226Reverse a String using Stack322
227Convert string1 to string2 in one edit321
228Maximum Subarray Leetcode Solution320
229Nth Character in Concatenated Decimal String319
230wildcard character matching319
231Sort Elements by Frequency II318
232Lower Case To Upper Case316
233Count the number of words313
234Merge Two Sorted Arrays311
235Split Four Distinct Strings311
236Find the Lost Element From a Duplicated Array310
237Find middle of the Linked List308
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets301
240Matrix Chain Multiplication using Dynamic Programming298
241Next Greater Element in an Array295
242Palindrome Permutation290
243Roman to Integer Leetcode Solution288
244Find Nth Node285
245Find All Pairs With a Given Difference284
246Searching a node in a Binary Search Tree283
247Triplet from three linked lists with given sum281
248Delete a Tree280
249String(represents an integer) to value280
250Reverse a String278
251Print all Possible Ways to Break a String in Bracket Form277
252Reverse Bits277
253Word Search Leetcode Solution275
254Binary Tree274
255How to Efficiently Implement k Stacks in a Single Array?273
256Change Gender of a given String273
257Delete a node under given conditions273
258Sort an array of strings272
259Meeting Rooms II LeetCode Solution270
260Number of sub-strings which recursively add up to 9269
261Count Pairs With Given Sum269
262First non Repeating Element268
263Repeated Substring Pattern268
264Longest Common Extension268
265Remove middle points in a linked list of line segments267
266Move all negative elements to one side of array265
267Toeplitz Matrix265
268Longest Palindromic Substring LeetCode Solution264
269Remove spaces from a string263
270Min Stack261
271Shuffle a given Array260
272N queen problem260
273Number of Islands LeetCode Solution254
274Cuckoo sequence program254
275Minimize the maximum difference between the heights253
276Dijkstra Algorithm253
277House Robber Leetcode Solution252
278Find, second, frequent, character252
279Clone a linked list with next and random pointer (Hashing)249
280Max stack249
281Most Frequent Element in an Array248
282Search Insert Position Leetcode Solution248
283Sort linked which is sorted on absolute values246
284Expression Evaluation245
285Valid Palindrome Leetcode Solution244
286Subset Leetcode244
287KMP Algorithm244
288Reverse words in a string243
289Fibonacci numbers243
290Sudoku Solver242
291Plus One Leetcode Solution242
292Min Stack Leetcode Solution242
293Number Of 1 bits242
294How to Delete a Linked List241
295Evaluation of Postfix Expression240
296Word Search239
297Combination Sum Leetcode Solution238
298Backspace String Compare234
299Merge Sorted Arrays Leetcode Solution234
300Sqrt(x) Leetcode Solution232
301Reversing a Queue231
302Pair of Positive Negative Values in an Array231
303Set Matrix Zeroes231
304Subarray with 0 sum231
305Contains Duplicate II Leetcode Solution229
306Product of array except self228
307Rabin Karp Algorithm228
308Tower Of Hanoi226
309Combination Sum226
310Delete middle element of a stack225
311Intersection of Two Arrays II Leetcode Solution225
312Common elements in all rows of a given matrix225
313Integer to Roman Leetcode Solution224
314Pascal Triangle Leetcode224
315String Compression223
316Count subarrays with equal number of 1’s and 0’s221
317Minimum swaps required to bring all elements less than or equal to k together221
318Reverse individual words221
319Single Number Leetcode Solution219
320Find Top K (or Most Frequent) Numbers in a Stream219
321Arithmetic Expression Evaluation218
322Implementation of Deque using Doubly Linked List218
323Sliding Window Technique218
324Bellman Ford Algorithm218
325Add Binary Leetcode Solution218
326Segregate even and odd numbers217
327Construct Binary Tree from Given Inorder and Preorder Traversals217
328Pow(x, n) Leetcode Solution217
329Count of index pairs with equal elements in an array217
330Second Most Repeated Word in a Sequence216
331Count Odd Numbers in an Interval Range Leetcode Solution216
332Contains Duplicate216
333Palindrome Linked List Leetcode Solution216
334Design a stack that supports getMin() in O(1) time and O(1) extra space216
335Postfix to Infix Conversion214
336Page Replacement Algorithms in Operating Systems214
337Third Maximum Number Leetcode Solution214
338Next Permutation214
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution213
340Maximum Number of Balloons Leetcode Solution213
341Kruskal Algorithm212
342Find sum of non-repeating elements (distinct) elements in an array212
343Convex Hull Algorithm211
344K-th Smallest Element in a Sorted Matrix211
345Permutations Leetcode Solution210
346Group Words With Same Set of Characters210
347Sort elements by frequency210
348Longest Substring Without Repeating Characters LeetCode Solution209
349Find Lucky Integer in an Array Leetcode Solution209
350Longest Common Prefix Leetcode Solution209
351Find the Town Judge Leetcode Solution209
352Maximum Subarray207
353Spiral Matrix LeetCode Solution207
354Sum of minimum and maximum elements of all subarrays of size k207
355Majority Element Leetcode Solution207
356Find Numbers with Even Number of Digits Leetcode Solution206
357Evaluate Division206
358Top K Frequent Words206
359Prefix to Infix Conversion205
360Sorting array using Stacks205
361Minimum Path Sum205
362Minimum operation to make all elements equal in array205
363Scramble String205
364Count subarrays having total distinct elements same as original array205
365Smallest Subarray with k Distinct Numbers204
366Number of Good Pairs Leetcode Solution204
367First element occurring k times in an array204
368Swap Nodes in Pairs Leetcode Solutions204
369Count Primes Leetcode Solutions203
370Special Number203
371Given two unsorted arrays find all pairs whose sum is x203
372Merge Two Sorted Lists Leetcode Solutions202
373Missing Number Leetcode Solution202
374Best Time to Buy and Sell Stock  II Leetcode Solution202
375Power of Two Leetcode Solution202
376Check if two arrays are equal or not202
377Search in Rotated Sorted Array Leetcode Solution201
378Sort Array by Increasing Frequency Leetcode Solution201
379Pascal’s Triangle II Leetcode Solution201
380Find All Numbers Disappeared in an Array Leetcode Solution200
381Huffman Coding200
382Reverse a Number Using Stack200
383Minimum Steps to reach target by a Knight199
384House Robber II Leetcode Solution199
385Fizz Buzz Leetcode199
386Unique Paths Leetcode Solution199
387Running Sum of 1d Array Leetcode Solution198
388Top K Frequent Elements198
389Maximal Square198
390Minimum Absolute Difference Leetcode Solution198
391Group Anagrams198
392Reversing the First K elements of a Queue198
393How to Implement Stack Using Priority Queue or Heap?197
394Coin Change 2 Leetcode Solution197
395Matrix Diagonal Sum Leetcode Solution197
396Leetcode Permutations197
397Find duplicates in a given array when elements are not limited to a range197
398Maximum possible difference of two subsets of an array197
399Range Sum Query 2D – Immutable Leetcode Solution196
400Sort Integers by The Number of 1 Bit Leetcode Solution196
401Single Number196
402How Many Numbers Are Smaller Than the Current Number Leetcode Solution196
403Find Minimum In Rotated Sorted Array196
404Max Consecutive Ones Leetcode Solution195
405Find Number of Employees Under every Employee195
406Happy Number Leetcode Solution195
407Expression Contains Redundant Bracket or Not195
408Zigzag Conversion195
409Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution195
410Maximum Distance Between two Occurrences of Same Element in Array195
411Sorting using trivial hash function194
412Decode String194
413Check if Array Contains Contiguous Integers With Duplicates Allowed194
414Fibonacci Number LeetCode Solution193
415Unique Paths193
416Find The Duplicate Number193
417Remove Duplicates from Sorted Array Leetcode Solution193
418Subarray Sum Equals k193
419Subarray Sum Equals K LeetCode Solution193
420Convert String To Int193
421Difference between highest and least frequencies in an array192
422Best Time to Buy and Sell Stock III Leetcode Solution192
423Length of the largest subarray with contiguous elements192
424Reverse Vowels of a String Leetcode Solution192
425Reverse Integer192
426Implement Stack and Queue using Deque192
427Find the Closest Palindrome number192
428Smallest Element Repeated Exactly K Times192
429Reverse a Stack Using Recursion191
430Check If N and Its Double Exist Leetcode Solution191
431Subtract the Product and Sum of Digits of an Integer Leetcode Solution191
432Find Median from data Stream191
433Subset sum problem191
434Find Winner on a Tic Tac Toe Game Leetcode Solution191
435Maximum Depth of Binary Tree Leetcode Solution190
436Shuffle the Array Leetcode Solution190
437Monotonic Array LeetCode Solution190
438Generate a String With Characters That Have Odd Counts Leetcode Solution189
439LRU Cache Implementation189
440Nth Catalan Number189
441Kth largest element in an Array Leetcode Solutions189
442Palindrome Substring Queries189
443Trapping Rain Water Leetcode Solution189
444Find top three repeated in array189
445Delete a Node from linked list without head pointer189
446Cumulative Frequency of Count of Each Element in an Unsorted Array189
447Letter Case Permutation188
448Capacity To Ship Packages Within D Days Leetcode Solution188
449Find the Duplicate Element188
450Subarrays with distinct elements188
451Reverse Words in a String III LeetCode Solution188
452Count Substrings with equal number of 0s, 1s and 2s188
453Priority Queue Using Singly Linked List188
454Print All Distinct Elements of a Given Integer Array188
455Sorting a Queue without Extra Space187
456Sort a stack using recursion187
457Integer to English words187
458Minimum Moves to Equal Array Elements Leetcode Solution187
459The K Weakest Rows in a Matrix Leetcode Solution187
460Find Common Characters Leetcode Solution186
461Target Sum186
462Find all pairs (a, b) in an array such that a % b = k186
463Excel Sheet Column Number Leetcode Solution186
464Bipartite Graph186
465Find the first repeating element in an array of integers186
466Reverse a String185
467Fizz Buzz185
468Count pairs from two linked lists whose sum is equal to a given value185
469Find First and Last Position of Element in Sorted Array Leetcode Solution185
470Iterative Tower of Hanoi185
471Floyd Warshall Algorithm185
472Word Ladder LeetCode Solution185
473Longest Common Subsequence185
474Concatenation of Array LeetCode Solution185
475Next Greater Element I Leetcode Solution185
476Merge Two Sorted Linked Lists185
477Find elements which are present in first array and not in second184
478Sum of Subarray Ranges Leetcode Solution184
479Prim’s Algorithm184
480Kids With the Greatest Number of Candies Leetcode Solution184
481Balanced Binary Tree Leetcode Solution184
482Text Justification LeetCode Solution184
483Multiply Strings Leetcode Solution184
484Print all subarrays with 0 sum183
485Find the Difference Leetcode Solution183
486Merge Overlapping Intervals183
487Zigzag Conversion LeetCode Solution183
488Edit Distance183
489Move Zeroes LeetCode Solution182
490Flood Fill LeetCode182
491Remove Minimum Number of Elements Such That no Common Element Exist in both Array182
492Kth Largest Element in a Stream Leetcode Solution182
493Count and Say182
494Reverse a linked list182
495Degree of an array182
496Number of Steps to Reduce a Number to Zero Leetcode Solution182
497Slowest Key Leetcode Solution182
498Top View of Binary Tree181
499Longest Common Prefix using Trie181
500Design Parking System Leetcode Solution181
501Length of Last Word Leetcode Solution181
502Implement a stack using single queue181
503MiniMax Algorithm181
504Intersection of Two Arrays180
505Substring With Concatenation Of All Words180
506Jump Game Leetcode Solution180
507Count and Say Leetcode Solution180
508Valid Parenthesis String179
509The Stock Span Problem179
510Convert array into Zig-Zag fashion179
511Pair with given product179
512Peak Index in a Mountain Array179
513Find subarray with given sum (Handles Negative Numbers)179
514Max Area of Island179
515Find N Unique Integers Sum up to Zero Leetcode Solution178
516Longest subarray not having more than K distinct elements178
517Last Stone Weight178
518Postfix to Prefix Conversion178
519Contiguous Array Leetcode178
520Find four elements that sum to a given value (Hashmap)178
521Priority Queue in C++178
522Mobile Numeric Keypad Problem178
523N-th Tribonacci Number Leetcode Solution178
524Delete Node in a Linked List Leetcode Solution177
525Prefix to Postfix Conversion177
526Find missing elements of a range177
527Longest Common Prefix using Sorting177
528Check if a given array contains duplicate elements within k distance from each other177
529Shuffle String Leetcode Solution177
530Koko Eating Bananas Leetcode Solution177
531Relative Sort Array Leetcode Solution177
532Find Index of Closing Bracket for a Given Opening Bracket in an Expression176
533Largest Perimeter Triangle Leetcode Solution176
534Shortest Palindrome176
535Container with Most Water175
536Best Time to Buy and Sell Stock175
537K-th Distinct Element in an Array175
538Is Subsequence Leetcode Solution175
539Iterative Inorder Traversal of a Binary Tree175
540Find any one of the multiple repeating elements in read only array175
541Find distinct elements common to all rows of a matrix175
542Recursion175
543Isomorphic Strings Leetcode Solution175
544Implement Stack using Queues174
54501 Matrix LeetCode Solution174
546Excel Sheet Column Title Leetcode Solution174
547Minimum Operations to convert X to Y174
548Count number of triplets with product equal to given number174
549Build Array From Permutation Leetcode Solution174
550Implementation of Deque using circular array174
551Change the Array into Permutation of Numbers From 1 to N174
552First negative integer in every window of size k174
553Smallest Subarray With all Occurrences of a Most Frequent Element174
554Distribute Candies to People Leetcode Solution174
555Jewels and Stones Leetcode Solution174
556Valid Sudoku173
557Convert Sorted Array to Binary Search Tree Leetcode Solution173
558Island Perimeter Leetcode Solution173
559Convert a normal BST to Balanced BST173
560Linked List Cycle II LeetCode Solution173
561Valid Anagrams173
562Maximum sum rectangle in a 2D matrix173
563Remove Linked List Elements Leetcode Solution173
564Hamming Distance173
565Next Greater Frequency Element172
566The Knapsack Problem172
567Sum of Left Leaves Leetcode Solutions172
568Rotate List Leetcode Solution172
569Shuffle an Array172
570Find the smallest positive integer value that cannot be represented as sum of any subset of a given array172
571Assign Cookies Leetcode Solution171
572Minimum Delete Operations to make all Elements of Array Same171
573Insert Interval Leetcode Solution171
574Group Multiple Occurrence of Array Elements Ordered by first Occurrence171
575Summary Ranges Leetcode Solution171
576Trapping Rain Water LeetCode Solution171
577Check for Balanced Parentheses in an Expression171
578Find Words That Can Be Formed by Characters Leetcode Solution171
579Gold Mine Problem171
580Arrange given numbers to form the biggest number171
581Count the number of nodes at given level in a tree using BFS171
582Minimum Bracket Reversals171
583Integer to Roman170
584Maximum Number of Chocolates to be Distributed Equally Among k Students170
5853Sum Closest LeetCode Solution170
586Shortest Path in a Grid with Obstacles Elimination LeetCode Solution170
587Maximum path sum in a triangle170
588Rearrange a binary string as alternate x and y occurrences170
589Minimum number of distinct elements after removing m items170
590Rotate Image LeetCode Solution170
591Count all subsequences having product less than K170
592Maximum Distance in Array169
593Combinations Leetcode Solution169
594Distance Between Bus Stops Leetcode Solution169
595Permutation in String Leetcode Solution169
596LRU Cache LeetCode Solution169
597Unique Binary Search Trees169
598Minimum Knight Moves LeetCode Solution168
599K Empty Slots LeetCode168
600Stone Game LeetCode168
601Decode Ways168
602XOR Operation in an Array Leetcode Solution168
603Same Tree LeetCode Solution168
604How to check if two given sets are disjoint?168
605Segregate 0s and 1s in an Array167
606Printing brackets in Matrix Chain Multiplication Problem167
607Find the Duplicate Number LeetCode Solution167
608Replace Elements with Greatest Element on Right Side Leetcode Solution167
609Sieve of Eratosthenes167
610Distance of nearest cell having 1 in a binary matrix167
611Remove All Occurrences of a Substring LeetCode Solution167
612Sort Array By Parity LeetCode Solution166
613Best Time to Buy and Sell Stock LeetCode Solution166
614Find if an Expression has Duplicate Parenthesis or Not166
615Word Wrap Problem166
616License Key Formatting Leetcode Solution166
617Find Sum of all unique sub-array sum for a given array166
618Sort Characters By Frequency LeetCode Solution166
619Minimum number of subsets with distinct elements165
620Frog Jump Leetcode Solution165
621Painting Fence Algorithm165
622Maximum difference between first and last indexes of an element in array165
623Applications of Breadth First Search and Depth First Search165
624Find minimum difference between any two elements165
625Word Pattern165
626Minimum insertions to form a palindrome with permutations allowed165
627Tracking current Maximum Element in a Stack164
628Defanging an IP Address Leetcode Solution164
629Smallest Good Base164
630Maximum Consecutive Numbers Present in an Array164
631House Robber164
632Coin Change Problem163
633Binary Tree Zigzag Level Order Traversal LeetCode Solution163
634Minimum Depth of Binary Tree Leetcode Solution163
635GCD Of Two Numbers163
636Check If It Is a Straight Line Leetcode Solution163
637Find pairs with given sum such that elements of pair are in different rows163
638Strobogrammatic Number LeetCode Solution163
639Queries for counts of array elements with values in given range163
640Find Maximum Level sum in Binary Tree163
641Best Time to Buy and Sell Stock with Cooldown Leetcode Solution163
642Longest Substring with At Most K Distinct Characters LeetCode Solution163
643Optimal Account Balancing LeetCode Solution162
644Minimum Cost to Hire K Workers162
645Maximum Number of Coins You Can Get Leetcode Solution162
646Employee Free Time LeetCode Solution162
647Iterative Method to find Height of Binary Tree162
648Non-overlapping sum of two sets162
649Letter Combinations of a Phone Number162
650Kth Missing Positive Number Leetcode Solution162
651Isomorphic Strings162
652Valid Palindrome II Leetcode Solution162
653Print the Fibonacci numbers in reverse order162
654Count Good Nodes in Binary Tree Leetcode Solution162
655Delete consecutive same words in a sequence161
656Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions161
657Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
658Power of Four Leetcode Solution161
659Longest Increasing Subsequence161
660Longest Substring with At Least K Repeating Characters LeetCode Solution161
661Wiggle Sort161
662Sum of All Odd Length Subarrays Leetcode Solution161
663Maximum Number of Occurrences of a Substring Leetcode Solution161
664Merge Two Balanced Binary Search Trees161
665Number of Provinces Leetcode Solution161
666Reverse a stack without using extra space in O(n)160
667K Empty Slots160
668Longest Increasing Path in a Matrix LeetCode Solution160
669Ugly Number Leetcode Solution160
670Partition Labels LeetCode Solution160
671Number of Dice Rolls With Target Sum LeetCode Solution160
672Moving Average from Data Stream Leetcode Solution160
673Sort Array by Increasing Frequency Leetcode Solution159
674Find the Distance Value Between Two Arrays Leetcode Solution159
675Reversing a Queue using Recursion159
676Valid Perfect Square Leetcode Solution159
677Reverse Only Letters LeetCode Solution159
678Find Leaves of Binary Tree LeetCode Solution159
679BFS vs DFS for Binary Tree159
680Form minimum number from given sequence159
681Convert an array to reduced form159
682Maximum Product of Two Elements in an Array Leetcode Solution159
683Check If Two String Arrays are Equivalent Leetcode Solution159
684Convert a Number to Hexadecimal Leetcode Solution158
685Largest Sum Contiguous Subarray158
686Reservoir Sampling158
687Binary Tree zigzag level order Traversal158
688Flipping an Image LeetCode Solution158
689Check if a queue can be sorted into another queue using a stack158
690Remove Invalid Parentheses Leetcode Solution158
691Edit Distance LeetCode Solution158
692Find the Smallest Divisor given a Threshold Leetcode Solution158
693Unique Paths II Leetcode Solution158
694To Lower Case Leetcode Solution158
695Path With Maximum Minimum Value LeetCode Solution158
696String to Integer (atoi) LeetCode Solution158
697Reducing Dishes LeetCode Solution158
698Majority Element II Leetcode Solution158
699Dynamic Programming Basics157
700Recover Binary Search Tree157
701Populating Next Right Pointers in Each Node157
702Construct BST from given Preorder Traversal157
703How to Create Mergable Stack?157
704Reorganize String157
705Robot Room Cleaner Leetcode Solution157
706Merge Two Binary Trees LeetCode Solution157
707Sum of f(a[i], a[j]) over all pairs in an array of n integers157
708Find Largest d in Array such that a + b + c = d157
709Delete Nth node from the end of the given linked list157
710Increasing Decreasing String Leetcode Solution157
711Lucky Numbers in a Matrix Leetcode Solution157
712Inorder Successor of a node in Binary Tree157
713Subset Sum Leetcode157
714Find whether an array is subset of another array157
715Permutation Sequence LeetCode Solution157
716Keyboard Row Leetcode Solution156
717Restore IP Addresses Leetcode Solution156
718Valid Palindrome156
719Partition Array Into Three Parts With Equal Sum Leetcode Solution156
720Find the node with minimum value in a Binary Search Tree156
721Minimum Cost For Tickets Leetcode Solution156
722Factorial Trailing Zeroes Leetcode Solution156
723Bulb Switcher LeetCode Solution155
724Decompress Run-Length Encoded List Leetcode Solution155
725Add and Search Word – Data structure design LeetCode155
726First Unique Character in a String LeetCode Solution154
727Maximum Product of Three Numbers LeetCode Solution154
728Student Attendance Record I Leetcode Solution154
729Rank Transform of an Array Leetcode Solution154
730Hamming Distance Leetcode Solution154
731Search a 2D Matrix II Leetcode Solution154
732Finding K closest element154
733Maximum 69 Number Leetcode Solution154
734Find unique character in a string153
735Bubble sort using two Stacks153
736Symmetric Tree Leetcode Solution153
737Word Pattern LeetCode Solution153
738Numbers with prime frequencies greater than or equal to k153
739Minimum Distance Between BST Nodes Leetcode Solution153
740Maximum Depth of N-ary Tree Leetcode Solution153
741Sorted Linked List to Balanced BST153
742Diagonal Traversal of Binary Tree153
743Evaluate Reverse Polish Notation LeetCode Solution153
744Find Median from Data Stream LeetCode Solution153
745Non-decreasing Array LeetCode Solution153
746Invert Binary Tree LeetCode Solution153
747Stack Permutations (Check if an array is stack permutation of other)153
748Queue based approach for first non-repeating character in a stream153
749String Compression LeetCode Solution153
750Morris Traversal153
751Find the largest multiple of 3153
752Perform String Shifts Leetcode152
753Number of Islands II LeetCode Solution152
754Search in a Binary Search Tree Leetcode Solution152
755Generate all possible sorted arrays from alternate elements of two given sorted arrays152
756Deletion in a Binary Tree152
757Largest rectangular sub-matrix whose sum is 0152
758Maximum Length of a Concatenated String with Unique Characters Leetcode Solution152
759Minimum Height Trees152
760Largest Rectangle in Histogram LeetCode Solution152
761Largest subarray with equal number of 0s and 1s152
762Find All Duplicates in an Array LeetCode Solution152
763Binary Tree Maximum Path Sum LeetCode Solution152
764Elements to be added so that all elements of a range are present in array152
765Best Meeting Point LeetCode Solution152
766Jump Game152
767Binomial Coefficient152
768Snakes and Ladders LeetCode Solution152
769Longest Span with same Sum in two Binary arrays152
770Remove Duplicates from Sorted List LeetCode Solution151
771Merge K Sorted Linked Lists151
772Remove Nth Node From End of List Leetcode Solution151
773k-th missing element in increasing sequence which is not present in a given sequence151
774Find Maximum Depth of Nested Parenthesis in a String151
775Linked List Cycle151
776Kth ancestor of a node in binary tree151
777Maximum Difference Between Increasing Elements LeetCode Solution151
778Check If Array Pairs Are Divisible by k LeetCode Solution151
779Split a String in Balanced Strings Leetcode Solution151
780Race Car LeetCode Solution151
781Minimum number of jumps to reach end151
782N-Queens LeetCode Solution151
783Special Array With X Elements Greater Than or Equal X Leetcode Solution150
784Transpose Graph150
785Count quadruples from four sorted arrays whose sum is equal to a given value x150
786Find if Path Exists in Graph Leetcode Solution150
787Minimize Maximum Pair Sum in Array LeetCode Solution150
788Find Pair with Greatest Product in Array150
789Crawler Log Folder Leetcode Solution150
790Final Prices With a Special Discount in a Shop Leetcode Solution150
791Nearest Exit from Entrance in Maze LeetCode Solution149
792Alien Dictionary LeetCode Solution149
793Tiling Problem149
794Merge Sorted Array LeetCode Solution149
795Relative Ranks Leetcode Solution149
796Can Place Flowers LeetCode Solution149
797Nested List Weight Sum II LeetCode Solution149
798Growable array based stack149
799Minimum time required to rot all oranges149
800Number of NGEs to the Right149
801Convert BST to Min Heap148
802Remove brackets from an algebraic string containing + and – operators148
803Interval Tree148
804Check if Two Expressions With Brackets are Same148
805Sort an array according to the order defined by another array148
806Check if a given array can represent Preorder Traversal of Binary Search Tree148
807Partition to K Equal Sum Subsets Leetcode Solution148
808Valid Number148
809Minimum Jumps to Reach Home LeetCode Solution148
810Iterative Preorder Traversal148
811Print a Binary Tree in Vertical Order148
812Minimum Time Visiting All Points Leetcode Solution148
813Remove Duplicates from Sorted List II148
814Check for Palindrome after every character replacement Query148
815Get Maximum in Generated Array Leetcode Solution148
816String comparison containing wildcards148
817Program for Bridge and Torch problem148
818Number Complement Leetcode Solution148
819One Edit Distance LeetCode Solution147
820Base 7 Leetcode Solution147
821Find all triplets with zero sum147
822Regular Expression Matching147
823Total Numbers With no Repeated Digits in a Range147
824Find the Only Repetitive Element Between 1 to N-1147
825Sort Array By Parity II Leetcode Solution147
826Top K Frequent Words LeetCode Solution147
827Maximum Profit in Job Scheduling Leetcode Solution147
828Maximum size subarray sum equals k147
829Minimum swaps to make sequences increasing147
830Sort Colors147
831Subarray Product Less Than K LeetCode Solution147
832Design a Stack With Increment Operation Leetcode Solution147
833Count items common to both the lists but with different prices147
834Reorder Data in Log Files LeetCode Solution147
835A Space Optimized DP solution for 0-1 Knapsack Problem147
836Priority Queue using doubly linked list147
837Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution147
838Friends Pairing Problem147
839Path with maximum average value146
840Minimum Number of Taps to Open to Water a Garden LeetCode Solution146
841Brightest Position on Street LeetCode Solution146
842Circular Queue146
843Longest Subarray Having Count of 1s One More than Count of 0s146
844Subset with sum divisible by m145
845K’th Largest Element in BST when modification to BST is not allowed145
846Repeated Substring Pattern LeetCode Solution145
847Sorted Array to Balanced BST145
848Given an Array of Pairs Find all Symmetric Pairs in it145
849Guess Number Higher or Lower LeetCode Solution145
850Union and Intersection of two Linked Lists145
851Clone Graph LeetCode Solution145
852Partition List Leetcode Solution145
853Find the subarray with least average145
854Binary Search Tree Search and Insertion145
855Subsequence of Size K With the Largest Even Sum LeetCode Solution145
856Count Distinct Elements in Every Window of Size K145
857Maximum Nesting Depth of the Parentheses Leetcode Solution144
858Find All Possible Recipes from Given Supplies LeetCode Solution144
859Three way partitioning of an array around a given range144
860Sum of nearest smaller and greater number144
861Tree Traversal (Preorder, Inorder & Postorder)144
862Permutation Coefficient144
863Level order Traversal in Spiral Form144
864Insert into a Binary Search Tree Leetcode Solution144
865Last Stone Weight II LeetCode Solution144
866Course Schedule II – LeetCode144
867Minimum Swaps to Make Strings Equal Leetcode Solution144
868Check if an Array is Stack Sortable144
869Brick Wall LeetCode Solution144
870Valid Parentheses Leetcode Solution144
871Minimum Sum Path in a Triangle144
872Rearrange Spaces Between Words Leetcode Solution143
873Daily Temperatures Leetcode Solution143
874Count ways to reach the nth stair using step 1, 2 or 3143
875Distinct adjacent elements in an array143
876Water Bottles Leetcode Solution143
877Check whether a given Binary Tree is Complete or not143
878Form Minimum Number From Given Sequence142
879LCS (Longest Common Subsequence) of three strings142
880Number of Days Between Two Dates LeetCode Solution142
881Guess Number Higher or Lower II142
882Lemonade Change Leetcode Solution142
883An Interesting Method to generate Binary Numbers from 1 to n142
884Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution142
885Sequences of given length where every element is more than or equal to twice of previous142
886Least Number of Unique Integers after K Removals Leetcode Solution142
887Minimum sum of multiplications of n numbers142
888Spiral Matrix II Leetcode Solution142
889Balanced Expression with Replacement142
890Range sum queries without updates142
891GCDs of given index ranges in an array142
8924Sum142
893Destination City Leetcode Solution142
894Count Negative Numbers in a Sorted Matrix LeetCode Solution142
895Matrix Chain Multiplication142
896Missing Element in Sorted Array LeetCode Solution142
897Identify and Mark Unmatched Parenthesis in an Expression142
898Robot Bounded In Circle LeetCode Solution142
899Palindrome Partitioning Leetcode Solution141
900Queries for GCD of all numbers of an array except elements in a given range141
901BFS for Disconnected Graph141
902Delete And Earn141
903Design Browser History LeetCode Solution141
904Convert Sorted List to Binary Search Tree140
905Spiral Matrix III LeetCode Solution140
906Diagonal Traversal LeetCode Solution140
907Shortest Word Distance Leetcode Solution140
908Intersection of Two Linked Lists LeetCode Solution140
909Maximum Score After Splitting a String Leetcode Solution140
910Check if the given array can represent Level Order Traversal of Binary Search Tree140
911Construct Complete Binary Tree from its Linked List Representation140
912Strongly Connected Component140
913Remove Duplicates from Sorted List II LeetCode Solution140
914Find distance between two nodes of a Binary Tree140
915Special Positions in a Binary Matrix Leetcode Solution140
916Insert Delete GetRandom140
917Time Based Key-Value Store LeetCode Solution140
918Find Maximum Sum Possible Equal Sum of Three Stacks140
919Find all permuted rows of a given row in a matrix140
920Count Subarrays with Same Even and Odd Elements140
921Rearrange an Array Such that arr[i] is equal to i139
922Merge Two Sorted Lists Leetcode139
923Lexicographical Numbers Leetcode Solution139
924Find Common Characters Leetcode Solution139
925Alien Dictionary139
926Trim a Binary Search Tree139
927Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i139
928Set Matrix Zeroes Leetcode Solution139
929Maximum Frequency Stack Leetcode Solution139
930Number of Distinct Islands Leetcode Solution139
931Diagonal Traverse LeetCode Solution139
932Construct BST from its given Level Order Traversal139
933Check if stack elements are pairwise consecutive139
934A program to check if a binary tree is BST or not139
935Range LCM Queries139
936Construct the Rectangle Leetcode Solution138
9373 Sum138
938Print Fibonacci sequence using 2 variables138
939Collect maximum points in a grid using two traversals138
940Longest Palindromic Subsequence138
941Analyze User Website Visit Pattern LeetCode Solution138
942Merging Intervals138
943Vertical sum in a given binary tree138
944Iterative Postorder Traversal Using Two Stacks138
945Word Break138
946Three Consecutive Odds Leetcode Solution137
947Count Submatrices With All Ones LeetCode Solution137
948All Unique Triplets that Sum up to a Given Value137
949Infix to Postfix137
950Longest Nice Substring LeetCode Solution137
951Count pair with Given Sum137
952Stone Game II Leetcode137
953Queue using Stacks137
954Can Make Arithmetic Progression From Sequence Leetcode Solution137
955Number of Equivalent Domino Pairs Leetcode Solution136
956Binary Tree Longest Consecutive Sequence LeetCode Solution136
957Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space136
958Level order traversal using two Queues136
959Product of Array Except Self LeetCode Solution136
960Palindrome Partitioning136
961Maximum Subarray Sum Excluding Certain Elements136
962Averages of Levels in Binary Tree136
963Reverse Nodes in K-Group136
964K Closest Points to Origin Leetcode Solution136
965Difference Array | Range update query in O(1)136
966Dividing Array into Pairs With Sum Divisible by K136
967Sliding Window Maximum136
968Largest area rectangular sub-matrix with equal number of 1’s and 0’s136
969Minimum Height Trees LeetCode Solution136
970Maximize Sum of Array after K Negations Leetcode Solution136
971Find postorder traversal of BST from preorder traversal136
972Create Maximum Number135
973Count Primes in Ranges135
974Binary array after M range toggle operations135
975Breadth First Search (BFS) for a Graph135
976Pattern Occurrences using Stack135
977Friends Of Appropriate Ages LeetCode Solution135
978Maximum Product of Indexes of Next Greater on Left and Right135
979Split Array Into Consecutive Subsequences135
980Kth Smallest Element in a BST Leetcode Solution135
981Largest divisible pairs subset135
982Asteroid Collision LeetCode Solution135
983Check if any two intervals overlap among a given set of intervals135
984Median of Two Sorted Arrays135
985Height of a generic tree from parent array134
986Newman-Conway Sequence134
987Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution134
988The Maze III LeetCode Solution134
989Maximum subsequence sum such that no three are consecutive134
990Level Order Traversal of Binary Tree134
991Largest Substring Between Two Equal Characters Leetcode Solution134
992Find Maximum of Minimum for Every Window Size in a Given Array134
993Segment Tree134
994Maximum Product Subarray134
995Minesweeper LeetCode Solution134
996Symmetric Tree134
997Length of Longest Fibonacci Subsequence133
998Unique Paths II133
999Binary Search Tree Delete Operation133
1000Depth First Search (DFS) for a Graph133
1001Find Duplicate Subtrees133
1002Kill Process LeetCode Solution133
1003First missing positive133
1004Next Greater Element III LeetCode Solution133
1005Find the Difference Leetcode Solution133
1006Sign of the Product of an Array LeetCode Solution133
1007The Painter’s Partition Problem133
1008Build an Array With Stack Operations Leetcode Solution133
1009Boundary Traversal of binary tree133
1010Count subarrays where second highest lie before highest133
1011Decrypt String from Alphabet to Integer Mapping Leetcode Solution133
1012Maximum Number of Ways to Partition an Array LeetCode Solution133
1013Boolean Parenthesization Problem133
1014Rearrange array such that even positioned are greater than odd133
1015Serialize and Deserialize Binary Tree133
1016Maximum Length of Repeated Subarray133
1017Graph Valid Tree LeetCode Solution132
1018Partition Equal Subset Sum132
1019Design Hit Counter LeetCode Solution132
1020My Calendar I LeetCode Solution132
1021Balanced Binary Tree132
1022Number Of Longest Increasing Subsequence132
1023Longest subsequence such that difference between adjacents is one132
1024Find the First Circular Tour that visits all the Petrol Pumps132
1025Climbing stairs132
1026Insertion in a Binary Tree132
1027Find number of pairs in an array such that their XOR is 0132
1028Super Ugly Number132
1029Validate Binary Search Tree131
1030Construct Binary Tree from given Parent Array representation131
1031Morris Inorder Traversal131
1032Largest Number Leetcode Solution131
1033Advantages of BST over Hash Table131
1034Move all negative elements to end in order with extra space allowed131
1035Double the first element and move zero to end131
1036Valid Boomerang Leetcode Solution131
1037Make The String Great Leetcode Solution131
1038Shortest Completing Word Leetcode Solution130
1039Recover Binary Search Tree Leetcode Solution130
1040Compute nCr % p130
1041Path Sum II LeetCode Solution130
1042Add two numbers130
1043Ugly Numbers130
1044Implement Trie (Prefix Tree) Leetcode Solution130
1045Binary Search Tree129
1046Employee Importance LeetCode Solution129
1047Ugly Number II LeetCode Solution129
1048Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’129
1049Maximum difference between frequency of two elements such that element having greater frequency is also greater129
1050Minimum Size Subarray Sum129
1051Available Captures for Rook Leetcode Solution129
1052Bitwise AND of Numbers Range LeetCode Solution129
1053Minimum Index Sum of Two Lists129
1054Generate Parentheses Leetcode Solution129
1055Kth Smallest Element in a Sorted Matrix LeetCode Solution129
1056String Matching in an Array Leetcode Solution129
1057Count minimum steps to get the given desired array129
1058Construction of Longest Increasing Subsequence (N log N)128
1059Invalid Transactions LeetCode Solution128
1060Scramble String LeetCode Solution128
1061Count pairs from two sorted arrays whose sum is equal to a given value x128
1062Maximum length subsequence with difference between adjacent elements as either 0 or 1128
1063Maximum Sum of 3 Non-Overlapping Subarrays128
1064Find whether a subarray is in form of a mountain or not128
1065Find a Peak Element II LeetCode Solution128
1066Number of palindromic paths in a matrix128
1067Increasing Triplet Subsequence LeetCode Solution128
1068Defanging an IP Address LeetCode Solution128
1069Find Peak Element128
1070Longest Bitonic Subsequence128
1071Populating Next Right Pointers in Each Node Leetcode Solution128
1072Combination Sum IV LeetCode Solution128
1073Binary Tree Right Side View LeetCode Solution128
1074Maximize Distance to Closest Person LeetCode Solution128
1075Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution128
1076Search in Sorted Rotated Array127
1077Clone a Binary Tree with Random Pointers127
1078Constant time range add operation on an array127
1079Regular Expression Matching Regular Expression Matching LeetCode Solution127
1080Maximum weight transformation of a given string127
1081Number of Students Doing Homework at a Given Time Leetcode Solution127
1082Lowest Common Ancestor127
1083Iterative Depth First Traversal of Graph127
1084Remove Palindromic Subsequences Leetcode Solution127
1085Smallest Common Region Leetcode Solution126
1086Find Three Element From Different Three Arrays Such That a + b + c = sum126
1087Divisible Pairs Counting126
1088Number of Closed Islands Leetcode Solution126
1089Custom Sort String Leetcode Solution126
1090Remove Duplicates from Sorted Array II Leetcode Solution126
1091Day of the Year Leetcode Solution126
1092Find the minimum distance between two numbers126
1093Rearrange array such that even index elements are smaller and odd index elements are greater125
1094Kth Smallest Product of Two Sorted Arrays LeetCode Solution125
1095Find maximum difference between nearest left and right smaller elements125
1096Print all triplets in sorted array that form AP125
1097Largest BST Subtree LeetCode Solution125
1098Write Code to Determine if Two Trees are Identical125
1099Distinct Subsequences125
1100Find Smallest Range Containing Elements from k Lists125
1101Path Sum125
1102Serialize and Deserialize Binary Tree LeetCode Solution125
1103Binary Tree Data Structure125
1104Number of siblings of a given Node in n-ary Tree125
1105Types of Binary Tree125
1106Next Permutation Leetcode Solution125
1107Print Next Greater Number of Q queries125
1108Bottom View of a Binary Tree124
1109Consecutive Characters LeetCode Solution124
1110Level of Each node in a Tree from source node124
1111Minimum Absolute Difference in BST Leetcode Solution124
1112Subarrays with K Different Integers Leetcode Solution124
1113Root to Leaf path with target sum Leetcode Solutions124
1114Minimum Score Triangulation of Polygon Leetcode Solution123
1115Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution123
1116Print Right View of a Binary Tree123
1117Products of ranges in an array123
1118Subset Sum Problem in O(sum) space123
1119Cutting a Rod123
1120Maximum Product Subarray123
1121Longest Subarray of 1’s After Deleting One Element LeetCode Solution123
1122Topological Sorting123
1123Cells with Odd Values in a Matrix LeetCode Solution123
1124Remove duplicates from sorted array123
1125Third Maximum Number Leetcode Solution123
1126Queries for Number of Distinct Elements in a Subarray122
1127Reformat The String Leetcode Solution122
1128Maximum Binary Tree122
1129Closest Binary Search Tree Value Leetcode Solution122
1130Convert BST into a Min-Heap without using array122
1131K maximum sums of overlapping contiguous sub-arrays122
1132Palindrome Permutation LeetCode Solution122
1133Prime Palindrome LeetCode Solution121
1134Mean of Array After Removing Some Elements Leetcode Solution121
1135Iterative method to find ancestors of a given binary tree121
1136Find a sorted subsequence of size 3 in linear time121
1137Print modified array after executing the commands of addition and subtraction121
1138Count Largest Group Leetcode Solution121
1139Valid Tic-Tac-Toe State LeetCode Solution121
1140Diameter of N-Ary Tree LeetCode Solution121
1141Search an Element in Sorted Rotated Array121
1142Search Insert Position120
1143Construct K Palindrome Strings LeetCode Solution120
1144Minimum sum of squares of character counts in a given string after removing k characters120
1145Moser-de Bruijn Sequence120
1146Thousand Separator Leetcode Solution120
1147Sum of Even Numbers After Queries120
1148Kth Smallest Number in Multiplication Table Leetcode Solution120
1149Golomb sequence120
1150Longest Increasing Consecutive Subsequence119
1151Bus Routes Leetcode Solution119
1152Possible Bipartition LeetCode Solution119
1153Factorial Trailing Zeroes LeetCode Solution119
1154Merge two BSTs with limited extra space119
1155Find maximum length Snake sequence119
1156Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution119
1157Red-Black Tree Introduction119
1158Check Array Formation Through Concatenation Leetcode Solution119
1159Palindromic Substrings Leetcode Solution118
1160Compare Strings by Frequency of the Smallest Character Leetcode Solution118
1161Delete Nodes and Return Forest Leetcode Solution118
1162Transform a BST to Greater sum Tree118
1163Decrease Elements To Make Array Zigzag LeetCode Solution118
1164Maximum Product of Splitted Binary Tree LeetCode Solution118
1165Binary Tree to Binary Search Tree Conversion118
1166Minimum Sideway Jumps LeetCode Solution118
1167Find the smallest binary digit multiple of given number118
1168Swapping Nodes in a Linked List Leetcode Solution118
1169Count Pairs Whose Products Exist in Array117
1170Count even length binary sequences with same sum of first and second half bits117
1171Swap Nodes In Pairs117
1172Longest Repeated Subsequence117
1173Minimum Cost to Move Chips to The Same Position LeetCode Solution117
1174Priority Queue117
1175Matchsticks to Square Leetcode Solution117
1176Number of Orders in the Backlog Leetcode Solution117
1177Find Largest Value in Each Tree Row LeetCode Solution117
1178Minimum Moves to Equal Array Elements LeetCode Solution117
1179Decision Tree117
1180Rotate Array117
1181K’th Largest element in BST using constant extra space117
1182Maximize sum of consecutive differences in a circular array117
1183Web Crawler LeetCode Solution116
1184Search Suggestions System LeetCode Solution115
1185Maximum sum bitonic subarray115
1186Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution115
1187Given a binary tree, how do you remove all the half nodes?115
1188Closest Leaf in a Binary Tree LeetCode Solution115
1189Moving Stones Until Consecutive Leetcode Solution115
1190Contiguous Array LeetCode Solution115
1191First Bad Version115
1192Integer Break LeetCode Solution114
1193Array Queries for multiply replacements and product114
1194Divide Two Integers Leetcode Solution114
1195Kth Smallest Element in a BST114
1196Maximum number of segments of lengths a, b and c114
1197Queue Reconstruction by Height114
1198Valid Triangle Number113
1199Lowest Common Ancestor of a Binary Tree Leetcode Solution113
1200Reverse a Path in BST using Queue113
1201Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution113
1202How to print maximum number of A’s using given four keys113
1203Champagne Tower LeetCode Solution113
1204Maximum Depth Of Binary Tree113
1205Convert Sorted Array to Binary Search Tree LeetCode Solutions113
1206Sum of Left Leaves LeetCode Solution113
1207Reformat Date LeetCode Solution113
1208Maximum sum of pairs with specific difference113
1209Lowest Common Ancestor in Binary Search Tree113
1210Replace two consecutive equal values with one greater112
1211Longest Common Prefix Using Word by Word Matching112
1212Range Sum Query using Sparse Table112
1213Write a function to get the intersection point of two Linked Lists112
1214Guess The Word112
1215Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution111
1216New 21 Game111
1217Concatenation of Array LeetCode Solution111
1218Largest Plus Sign Leetcode Solution111
1219Graph and its representation111
1220Arithmetic Slices II – Subsequence LeetCode Solution111
1221Flatten 2D Vector LeetCode Solution111
1222LRU Cache Leetcode Solution111
1223Check Completeness of a Binary Tree LeetCode Solution111
1224Print n terms of Newman-Conway Sequence111
1225Maximize Elements Using Another Array111
1226Range Queries for Longest Correct Bracket Subsequence111
1227Symmetric Tree LeetCode Solution Leetcode Solution111
1228Print modified array after multiple array range increment operations111
1229Queries on Probability of Even or Odd Number in given Ranges110
1230Check if each internal node of a BST has exactly one child110
1231Design Skiplist LeetCode Solution110
1232Valid Perfect Square LeetCode Solution110
1233Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1234Path Crossing Leetcode Solution110
1235The kth Factor of n Leetcode Solution109
1236Sliding Window Median Leetcode Solution109
1237Check if all levels of two Binary Tree are anagrams or not109
1238Maximum Array from Two given Arrays Keeping Order Same109
1239Graph Cloning109
1240Check for Identical BSTs without building the trees109
1241Merge Sort109
1242Maximum sum of a path in a Right Number Triangle109
1243Find Minimum in Rotated Sorted Array II LeetCode Solution109
1244Minimum Swaps To Make Sequences Increasing LeetCode Solution109
1245Missing Number109
1246Perfect Squares LeetCode Solution109
1247BST to a Tree with Sum of all Smaller Keys109
1248Count and Toggle Queries on a Binary Array108
1249Power of Two108
1250Count Subsets Having Distinct Even Numbers108
1251Bold Words in String LeetCode Solution108
1252Smallest Range II Leetcode Solution108
1253Mean of range in array108
1254Parallel Courses II LeetCode Solution108
1255Contiguous Array107
1256Image Overlap LeetCode Solution107
1257Find minimum number of merge operations to make an array palindrome107
1258Min Cost Climbing Stairs LeetCode Solution107
1259Maximum Product Subarray107
1260Excel Sheet Column Title LeetCode Solution106
1261Check If a String Can Break Another String Leetcode Solution106
1262Minimum Remove to Make Valid Parentheses LeetCode Solution106
1263Find k-th smallest element in BST (Order Statistics in BST)105
1264Next greater element105
1265Verify Preorder Serialization of a Binary Tree105
1266Print Ancestors of a Given Binary Tree Node Without Recursion104
1267Merge k Sorted Lists Leetcode Solution104
1268Number of elements less than or equal to a given number in a given subarray104
1269Peeking Iterator LeetCode Solution104
1270Palindrome Partitioning104
1271Orderly Queue LeetCode Solution103
1272Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1273Check in binary array the number represented by a subarray is odd or even102
1274Merge Sorted Array102
1275Check if two nodes are on the same path in a Tree102
1276Newman–Shanks–Williams prime102
1277Koko Eating Bananas LeetCode Solution100
1278Largest Submatrix With Rearrangements LeetCode Solution100
1279Check if X can give change to every person in the Queue100
1280Different Ways to Add Parentheses Leetcode Solution100
1281Arranging Coins Leetcode Solution99
1282Find maximum average subarray of k length98
1283Longest Substring Without Repeating Characters Leetcode Solution98
1284Maximum Sum Increasing Subsequence98
1285Range Minimum Query (Square Root Decomposition and Sparse Table)97
1286Minimum Total Space Wasted With K Resizing Operations LeetCode Solution97
1287Queries for Decimal Values of Subarrays of a Binary Array96
1288Minimum Number of People to Teach LeetCode Solution96
1289Array Nesting Leetcode Solution96
1290Number of indexes with equal elements in given range96
1291Maximum product of an increasing subsequence95
1292Binary Tree to Binary Search Tree Conversion using STL set94
1293Check given array of size n can represent BST of n levels or not94
1294Convert to Base -2 LeetCode Solution94
1295Find the Winner of the Circular Game LeetCode Solution93
1296Jump Game IV LeetCode Solution93
1297Random Pick Index LeetCode Solution93
1298Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution93
1299Convert a BST to a Binary Tree such that sum of all greater keys is added to every key93
1300Queries on XOR of greatest odd divisor of the range92
1301Encoded String With Shortest Length LeetCode Solution92
1302Reach a Number LeetCode Solution92
1303Add Two Numbers II Leetcode Solution92
1304Continuous Subarray Sum LeetCode Solution91
1305Insert Delete GetRandom O(1) Leetcode Solution91
1306Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution91
1307Palindrome Number LeetCode Solution89
1308Vertical Order Traversal of Binary Tree LeetCode Solution89
1309Design Underground System Leetcode Solution88
1310Print Maximum Length Chain of Pairs86
1311Design A Leaderboard Leetcode Solution83
1312Detect Capital Leetcode Solution83
1313Substring with Concatenation of All Words Leetcode Solution80
1314Top K Frequent Elements LeetCode Solution79
1315Minimum Swaps to Group All 1’s Together Leetcode Solution78
1316Count Sub Islands LeetCode Solution76
1317Minimum Path Sum Leetcode Solution76
1318Longest Common Subsequence LeetCode Solution74
1319Decode String Leetcode Solution74
1320Odd Even Linked List Leetcode Solution73
1321Binary Tree Inorder Traversal LeetCode Solution72
1322Shifting Letters LeetCode Solution72
1323Maximum Population Year LeetCode Solution71
1324Shortest Unsorted Continuous Subarray LeetCode Solution71
1325Best Meeting Point LeetCode Solution71
1326Sum Root to Leaf Numbers LeetCode Solution70
1327Find the Town Judge LeetCode Solution70
1328Find the Town Judge LeetCode Solution70
1329Design Add and Search Words Data Structure LeetCode Solution68
1330Rectangle Overlap LeetCode Solution67
1331Maximum Population Year LeetCode Solution66
1332Score of Parenthesis LeetCode Solution65
1333Range Sum Query 2D – Immutable LeetCode Solution64
1334Flatten Binary Tree to Linked List LeetCode Solution63
1335Insert into a Sorted Circular Linked List LeetCode Solution63
1336Stone Game IV LeetCode Solution62
1337Is Graph Bipartite? LeetCode Solution60
1338Valid Triangle Number LeetCode Solution59
1339Reveal Cards In Increasing Order Leetcode Solution59
1340Divide Chocolate LeetCode Solution51
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution46
1342Range Sum of BST LeetCode Solution44
1343Reverse Integer Leetcode Solution41
1344Sort Colors LeetCode Solution40
1345Find K Closest Elements LeetCode Solution38
1346Excel Sheet Column Number LeetCode Solution36
1347Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution35
1348Rotate String LeetCode Solution34
1349Maximum Size Subarray Sum Equals k Leetcode Solution12
1350High Five LeetCode Solution11
1351H-Index Leetcode Solution10
Translate »