High Five LeetCode Solution

Difficulty Level Easy
Frequently asked in Amazon Goldman Sachs
Array Hash Table Priority QueueViews 2

Problem Statement:

The High Five LeetCode Solution – Given a list of scores of different students named “item”, where the “item” has two fields item[0] represents the student’s id, and item[1] represents the student’s score eg. item[i]=[IDi, SCOREi]

Return the answer as an array of pairs result, where result[j] = [IDj, topFiveAveragej] represents the student with IDj and their top five average.

Note: A student’s top five average is calculated by taking the sum of their top five scores and dividing it by 5 using integer division.



items = [[1,91],[1,92],[2,93],[2,97],[1,60],[2,77],[1,65],[1,87],[1,100],[2,100],[2,76]]


For student id 1 : scores -> 91, 92, 60, 65, 87, 100

The top five scores for student 1: 100, 92, 91, 87, 65

So the average of top five scores for student 1 : (100 + 92 + 91 + 87 + 65 ) / 5 = 87

In the same way,

For student id 2 : scores -> 93, 97, 77, 100, 76

The top five scores for student 2: 100, 97, 93, 77, 76

So the average of top five scores for student 2: (100 + 97 + 93 + 77 + 76 ) / 5 = 88

Output:  [[1,87],[2,88]]



items = [[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100],[1,100],[7,100]]




For student id 1 : scores -> 100, 100, 100, 100, 100

The top five scores for student 1: 100, 100, 100, 100, 100

So the average of top five scores for student 1 : (100 + 100 + 100 + 100 + 100 ) / 5 = 100

In the same way,

For student id 7 : scores -> 100, 100, 100, 100, 100

The top five scores for student 7: 100, 100, 100, 100, 100

So the average of top five scores for student 7: (100 + 100 + 100 + 100 + 100 ) / 5 = 100

Output: [[1,100],[7,100]]




We maintain a max heap of all the scores for every id so that we can easily get the top five elements for each of the ids by obtaining the first 5 elements from the max heap. For storing the ids of the students as the key element we also need a map data structure.

High Five LeetCode SolutionPin

  1. First, create a map of type <integer type, priority_queue> and iterate through all the elements of the given list “item” and push the student’s id and the corresponding score of the student on the map.
  2. As we use a max heap to store the scores of a student, it ensures that we’ll always get the maximum score at the top of the priority_queue.
  3. Now we iterate through the map and take the id and the first five elements of the max heap and calculate their average value.
  4. Finally, we push the id and average value into the result.
  5. Return the result.


C++ Program of High Five

class Solution {
    vector<vector<int>> highFive(vector<vector<int>>& items) {
        vector<vector<int>> res;
        map<int, priority_queue<int>> mpp;
        for(auto i:items){
            int id=i[0];
            int score=i[1];
        for(auto i:mpp){
            int id = i.first;
            auto scores = i.second;
            int val=0, count=1;
            while(count <= 5){
                val += scores.top();
            res.push_back({id, val});
        return res;


Java Program of High Five

class Solution {
    public int[][] highFive(int[][] items) {
        Map<Integer,PriorityQueue<Integer>> mpp = new HashMap<>();
        for(int[] info : items){
            int id = info[0];
            int score = info[1];
            PriorityQueue<Integer> pq = mpp.getOrDefault(id,new PriorityQueue<>());
        int [][] res = new int[mpp.size()][2];
        int index=0;
        for(Map.Entry<Integer,PriorityQueue<Integer>> entry : mpp.entrySet()){
            int val=0;
            int id = entry.getKey();
            PriorityQueue<Integer> pq = entry.getValue();
            res[index][0] = id;
            res[index++][1] = val/5;
        return res;


Complexity Analysis for High Five LeetCode Solution:

Time Complexity:

The time complexity of the code is O(NlogN) as LogN for putting the scores of the given “item” into the priority queue and we need to traverse all N elements so the overall time complexity will be O(NlogN).

Space Complexity:

The space complexity will be O(N) as we need a hash map to store the ids of the students and their corresponding scores.


Top Interview Questions

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