Maximum Size Subarray Sum Equals k Leetcode Solution

Difficulty Level Medium
Frequently asked in Amazon Apple Facebook Goldman Sachs Microsoft Palantir Technologies
Array Hash MapViews 2

Problem Statement:

The Maximum Size Subarray Sum Equals k Leetcode Solution – Given an integer array nums and integer k, return the maximum length of a subarray that sums to k. If there is not one, return 0 instead.


nums = [1,-1,5,-2,3], k = 3
Output: 4


Maximum Size Subarray Sum Equals k Leetcode SolutionPin


The subarray [1, -1, 5, -2] sums to 3 and is the longest.

Example 2:

nums = [-2,-1,2,1], k = 1
Output: 2


 The subarray [-1, 2] sums to 1 and is the longest.



We are using prefix sum and hash map to solve this problem.

  1. Initialize three variables: “curr”, “len”, and a hash map “mpp”. “curr” variable is used to store the prefix sum, “len” that will keep track of the longest subarray with sum k as 0 and a hash map “mpp” that has keys of prefix sums seen so far and values of the first index that each key was seen.
  2. Iterate through the given array and calculate the curr variable but add the current value of the array element.
  3. Now in the loop, we check that if the curr variable is equal to the given target k, means the sum of the array up to this index is equal to k. Update len = i+1.
  4. If curr-k exists in mpp, that means there is a subarray with sum k ending at the current i. The length will be  i-mpp[curr-k]. If this length is greater than len, update len.
  5. If the current curr does not yet exist in mpp, then set mpp[curr]=i.
  6. Return maximum value of len.



C++ Program of  Maximum Size Subarray Sum Equals k Leetcode Solution:

class Solution {
    int maxSubArrayLen(vector<int>& nums, int k) {
        long long curr=0;
        int len=0;
        unordered_map<long long, int> mpp;
        for(int i=0;i<nums.size();i++){
            else if(mpp.find(curr-k)!=mpp.end()){
                len=max(len, i-mpp[curr-k]);
        return len;

Java Program of  Maximum Size Subarray Sum Equals k Leetcode Solution:

class Solution {
    public int maxSubArrayLen(int[] nums, int k) {
        long curr=0;
        int len=0;
        HashMap<Long, Integer> mpp = new HashMap<>();
        for(int i=0;i<nums.length;i++){
            else if(mpp.containsKey(curr-k)){
                len=Math.max(len, i-mpp.get(curr-k));
                mpp.put(curr, i);
        return len;

Complexity Analysis:

Time Complexity:

Time Complexity will be O(N) as we iterate over the given array nums (of length N) once, where N is the size of the input array.

Space Complexity:

Space Complexity will be O(N) as we need another hash map to solve this problem, where N is the size of the input array.

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