Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution

Difficulty Level Medium
Frequently asked in Amazon Facebook Google Snapchat Uber
Array Binary Search Sorting Two PointersViews 86

Problem Statement

Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution – says that Given an array of integers nums and an integer target.

Return the number of non-empty subsequences  nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.

 

Example 1:

Input:

 nums = [3,5,6,7], target = 9

Output:

 4

Explanation:

 There are 4 subsequences that satisfy the condition.
[3] -> Min value + max value <= target (3 + 3 <= 9)
[3,5] -> (3 + 5 <= 9)
[3,5,6] -> (3 + 6 <= 9)
[3,6] -> (3 + 6 <= 9)


Approach:

1. We will sort the array.

2. We will find the extreme right position for a fixed index such that our predicate (nums[i]+nums[mid]<=target)is true by performing a binary search

3. So, the length will be len=mid-i+1.

4.Number of subsequence will be (2^len-1)-(2^(len-1)-1)=(2^(len-1)). We will sum up this for every index i.

5. For calculating the power, we can use matrix exponentiation.

C++ Leetcode Solution:

class Solution {
public:
    #define ll long long
    ll mod=1e9+7;
    
    
    int pow(long long x, unsigned int y, int p)
{
    int res = 1;     
 
    x = x % p; 
  
    if (x == 0) 
    return 0;
    while (y > 0)
    {
       
        if (y & 1)
        res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;
    }
    return res;
}
    int numSubseq(vector<int>& nums, int target) {
        ll n=nums.size();
        ll i;
        ll sum=0;
        sort(nums.begin(),nums.end());
       for(i=0;i<n;i++)
       {
           ll l=i,r=n-1,mid,ans=-1;
           while(l<=r)
           {
               mid=l+(r-l)/2;
               if(nums[i]+nums[mid]<=target)
               {
                   l=mid+1;
                   ans=mid;
               }
               else
                   r=mid-1;
           }
           if(ans!=-1)
           {
               
               ll len=ans-i+1;
             
               ll yo=pow(2,len,mod);
             
               ll yo1=pow(2,len-1,mod);
               sum+=(yo-yo1);
               sum=sum%mod;
               if(sum<0)sum+=mod;
           }
       }
        return sum;
    }
};

Java Leetcode Solution:

class Solution {
    
     long pow(long x, long y, long p)
  {
    long res = 1; 
 
    x = x % p; 
   
    if (x == 0)
      return 0; 
 
    while (y > 0)
    {
        if ((y & 1) != 0)
        res = (res * x) % p;
 
      y = y >> 1; 
      x = (x * x) % p;
    }
    return res;
  }
 
    public int numSubseq(int[] nums, int target) {
        int n=nums.length,i;
        Arrays.sort(nums);
        long mod=(long)1e9+7;
        long sum=0;
         for(i=0;i<n;i++)
       {
           int l=i,r=n-1,mid,ans=-1;
           while(l<=r)
           {
               mid=l+(r-l)/2;
               if(nums[i]+nums[mid]<=target)
               {
                   l=mid+1;
                   ans=mid;
               }
               else
                   r=mid-1;
           }
           if(ans!=-1)
           {
               
               long len=ans-i+1;
             
               long yo=pow(2,len,mod);
             
               long yo1=pow(2,len-1,mod);
               sum+=(yo-yo1);
               sum=sum%mod;
               if(sum<0)sum+=mod;
           }
             
       }
        
        return (int)sum;
    }
}

Complexity Analysis of Number of Subsequences that satisfy the Given Sum Condition Leetcode Solution:

Time complexity:

O(nlog(n)) is the time complexity. log(n) factor is coming for binary search and we are performing it while traversing the length of the array.

Space complexity:

We are not taking any extra space. So space complexity is O(1).

 

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2817
2Java program to find the number of Nodes in a Binary Tree2500
3Reverse a string without affecting special characters2458
4Delete a node of a linked list at given position1973
5Palindrome using Recursion1778
6Insert nodes in a linked list in a sorted way (Ascending Order)1659
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1631
9Write a program to print all permutations of a given string1604
10Find Minimum Distance Between Two Numbers in an Array1471
11Create a Doubly Linked List1444
12Quick Sort1416
13Reverse an Array1412
14Smallest window in a string containing all characters of another string1394
15Find a Triplet That Sum to a Given Value1356
16Recursively remove all adjacent duplicates1353
17First Repeating Element1337
18Arrange Even and Odd number such that Odd comes after Even1320
19Sum of numbers in String1315
20Smallest Positive Number Missing in an Unsorted Array1280
21Check if the Elements of an Array are Consecutive1252
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1214
25Subarray with Given Sum1211
26Print all Possible Combinations of R Elements in a given Array of size N1203
27Recursive function to do substring search1196
28Find the Maximum Repeating Number in Array1154
29Binary Tree Level order traversal in Java1123
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1102
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1067
34Find Leaders in an Array1060
35Swap nodes in the linked list1034
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II993
38Find the second most frequent character984
39Given a string find its first non-repeating character966
40Find Triplet in Array With a Given Sum964
41Total number of occurrences of a given item in the linked list951
42Given a sorted array and a number x, find the pair in array whose sum is closest to x951
43A Program to check if strings are rotations of each other or not943
44Print all possible words from phone digits932
45Find the Missing Number924
46Rearrange Positive and Negative Numbers Alternatively in Array917
47Longest Palindromic Substring904
48Segregate even and odd nodes in a linked list882
49Print Longest common subsequence881
50Union and Intersection of Two Linked Lists870
51Transform one string to another using minimum number of given operations867
52Rearrange given Array in Maximum Minimum Form844
53Check rearranged string can form a palindrome842
54Count Possible Triangles819
55Iterative Implementation of Quick Sort814
56Multiplication of Two Matrices800
57Check if the linked list is palindrome795
58Count of Triplets With Sum Less than Given Value789
59Rotate a Linked List789
60Stock Buy Sell to Maximize Profit786
61Concatenation of two strings758
62Count Number of Substrings with K Distinct Character’s758
63Tug of War758
64Print all duplicates in the input string753
65Find Nearest Greater and Smaller Element744
66The Celebrity Problem736
67Find Pythagorean Triplets from Array736
68Reverse String Without Temporary Variable733
69Remove ‘b’ and ‘ac’ from a given string728
70Find all Common Elements in Given Three Sorted Arrays727
71Remove all duplicates in an unsorted linked list708
72Find the Row with Maximum Number of 1’s703
73Find the Peak Element from an Array697
74Find the subarray whose sum is equal to a given number X695
75Remove Minimum Characters so that Two Strings Become Anagrams689
76Insertion Sort686
77Find Smallest Missing Number in a Sorted Array686
78A Product Array Puzzle684
79Addition of Two Matrices682
80Implement Two Stacks in an Array675
81Generate all Binary Strings Without Consecutive 1’s671
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II658
84Lexicographic rank of string652
85Multiplication of Previous and Next643
86Check if Two given Matrices are Identical641
87Subtraction of Two Matrices631
88Merge K Sorted Arrays and Print Sorted Output631
89Move All the Zeros to the End of the Given Array627
90Divide a string in N equal parts622
91Online Algorithm for Checking Palindrome in a Stream622
92Form Minimum Number from Given Sequence of D’s and I’s621
93Check whether two strings are anagram of each other614
94Maximum Circular Subarray Sum612
95Remove recurring digits in a given number608
96Sort a linked list that is sorted alternating ascending and descending607
97Sort a stack using a temporary stack605
98Find the Minimum Element in a Sorted and Rotated Array604
99Move last element of the Linked List at first place601
100Subarray and Subsequence599
101Largest Subarray with Equal Number of 0’s and 1’s596
102First Circular Tour to Visit all the Petrol Bunks596
103Compare two strings(linked lists)591
104Flattening a linked list590
105Maximum Element in an Array which is Increasing and then Decreasing589
106Palindrome Permutations of a String583
107Elements Appear more than N/K times in Array581
108Majority Element575
109Run length encoding574
110Minimum insertions to form a shortest palindrome573
111Print all permutations with repetition572
112Palindromes in a given range570
113Pangram Checking568
114Merge a linked list into another at alternate positions567
115Minimum Characters to be Added at Front to Make String Palindrome563
116Rearrange a given linked list in-place562
117Remove all duplicates in a sorted linked list562
118Minimum number of Merge Operations to make an Array Palindrome558
119Most repeating character in a string558
120Rotate string to get lexicographically minimum string557
121Repeated Subsequence of Length Two or More554
122Print all anagrams together in a sequence of words551
123Reorder an Array According to the Given Indexes550
124Pancake Sorting Problem540
125Merge Overlapping Intervals II538
126Two Sum Leetcode Solution536
127Clone a Linked List with next and random pointer536
128Size of The Subarray With Maximum Sum527
129Transpose of a Matrix524
130Removing Spaces from a String using stringstream520
131Remove Extra Spaces from a String520
132Smallest Palindrome after Replacement518
133Remove duplicates from a string517
134Check if a given string is a rotation of a palindrome517
135Partition Problem516
136Longest Palindrome can be Formed by Removing or Rearranging Characters513
137Maximum Sum Increasing Subsequence512
138Check whether Strings are K Distance Apart or Not502
139Generate all Binary Strings from Given Pattern501
140Delete Last Occurrence500
141Length of Longest valid Substring499
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized499
143Insert Node in the Sorted Linked List498
1443Sum Leetcode Solution497
145Check if Two given Strings are Isomorphic to each other494
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String482
148Given string is interleaving of two other strings or not481
149Count Minimum Steps to Get the given Array478
150Number of Smaller Elements on Right Side477
151Merge sort better than quick sort for linked lists477
152Find Pair with Given Difference472
153Check if all Rows of a Matrix are Circular Rotations of Each Other470
154Check length of a String is Equal to the Number Appended at its Last469
155Longest Common Prefix using Divide and Conquer467
156Find nth node of the Linked list from the end466
157Find a Fixed Point in a Given Array463
158Sort 0s 1s and 2s in an Array457
159Print all interleavings of given two strings457
160Compare Two Version Numbers454
161Merge two sorted linked lists such that merged list is in reverse order453
162Reverse words in a given string453
163Find the Subarray of given length with Least Average452
164Reorder Array Using Given Indexes450
165Median of Two Sorted Arrays LeetCode Solution449
166Split linked list using alternate nodes449
167Print Reverse of a string (Recursion)448
168Find K Length Subarray of Maximum Average438
169Print string of odd length in ‘X’ format435
170Find Element Using Binary Search in Sorted Array432
171Swap Kth Node from beginning with Kth Node from End430
172Print all Palindromic Partitions of a String429
173Find Duplicates in an Array in Most Efficient Way427
174print all palindromic partitions420
175Maximum Length of Chain Pairs416
176Flatten a multilevel linked list415
177Shortest Superstring Problem414
178Check if String Follows Order of Characters by a Pattern or not411
179Sorting a K Sorted Array408
180Sort a String According to Another String404
181Longest Span with same Sum in two Binary Arrays II398
182Reverse a Linked List in groups395
183Find a Sorted Subsequence of size 3393
184Program to add two binary digits390
185Recursively print all the sentences that can be formed from list of word lists388
186Find the two Numbers with Odd Occurrences in an Unsorted Array386
187Longest Common Prefix Using Binary Search II385
188Reverse a Singly Linked List (Iterative/Non-Recursive)381
189Rearrange a linked list in Zig-Zag377
190Check if String can Become Empty by Recursively Deleting given Substring377
191Kth Non-repeating Character377
192Caesar Cipher376
193Pancake Sorting373
194Rotate Image by 90 degrees371
195Longest Common Prefix Word by Word Matching369
196Perfect Reversible String365
197Permutations of a Given String Using STL364
198Merging Two Sorted Arrays362
199Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes361
200Increasing Subsequence of Length three with Maximum Product361
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
2031`s and 2`s complement of binary number357
204Find First non-repeating character in a string356
205Four Elements that Sum to Given353
206List items containing all characters of a given word351
207Delete N nodes after M351
208Longest Common Prefix using Character by Character Matching348
209Count Number of Occurrences in a Sorted Array344
210Palindrome string (number)342
211Split a string340
212Minimum Characters to be Removed to Make a Binary String Alternate339
213Check if a Linked list of Strings form a Palindrome333
214Recursive Implementation of atoi()332
215Convert a String that is Repetition of a Substring of Length K330
216Sorting the array of strings330
217Print All Distinct Elements of the Array330
218Maximum occurring character in a string326
219Find the first Repeating Number in a Given Array325
220Even Substring Count325
221Valid Parentheses LeetCode Solution325
222Reverse a singly linked list recursively324
223Can we reverse a linked list in less than O(n) time ?323
224Print Shortest Path to Print a String on Screen322
225Binary Tree to Doubly linked list322
226Convert string1 to string2 in one edit318
227Nth Character in Concatenated Decimal String318
228Maximum Subarray Leetcode Solution317
229Sort Elements by Frequency II317
230Reverse a String using Stack316
231Lower Case To Upper Case314
232wildcard character matching314
233Count the number of words311
234Merge Two Sorted Arrays310
235Find the Lost Element From a Duplicated Array310
236Split Four Distinct Strings308
237Find middle of the Linked List305
238Longest Common Subsequence with Permutations303
239Count the Pairs at Same Distance as in English Alphabets301
240Matrix Chain Multiplication using Dynamic Programming295
241Next Greater Element in an Array294
242Palindrome Permutation287
243Find Nth Node285
244Searching a node in a Binary Search Tree283
245Roman to Integer Leetcode Solution281
246Find All Pairs With a Given Difference281
247Triplet from three linked lists with given sum280
248Delete a Tree279
249Print all Possible Ways to Break a String in Bracket Form277
250String(represents an integer) to value276
251Reverse a String276
252Reverse Bits274
253Binary Tree272
254Delete a node under given conditions272
255Word Search Leetcode Solution271
256Change Gender of a given String271
257Sort an array of strings270
258Number of sub-strings which recursively add up to 9267
259Count Pairs With Given Sum267
260Longest Common Extension266
261How to Efficiently Implement k Stacks in a Single Array?266
262First non Repeating Element265
263Remove middle points in a linked list of line segments265
264Meeting Rooms II LeetCode Solution264
265Repeated Substring Pattern263
266Longest Palindromic Substring LeetCode Solution262
267Toeplitz Matrix262
268Remove spaces from a string262
269Move all negative elements to one side of array260
270Shuffle a given Array258
271N queen problem255
272Min Stack255
273Find, second, frequent, character251
274Number of Islands LeetCode Solution250
275House Robber Leetcode Solution250
276Dijkstra Algorithm250
277Cuckoo sequence program248
278Max stack247
279Most Frequent Element in an Array247
280Clone a linked list with next and random pointer (Hashing)246
281Minimize the maximum difference between the heights245
282Search Insert Position Leetcode Solution244
283Sort linked which is sorted on absolute values244
284Expression Evaluation244
285Plus One Leetcode Solution241
286Subset Leetcode240
287Fibonacci numbers240
288Valid Palindrome Leetcode Solution240
289KMP Algorithm239
290Word Search238
291Evaluation of Postfix Expression238
292Sudoku Solver238
293How to Delete a Linked List238
294Reverse words in a string237
295Min Stack Leetcode Solution237
296Combination Sum Leetcode Solution233
297Number Of 1 bits232
298Merge Sorted Arrays Leetcode Solution230
299Sqrt(x) Leetcode Solution230
300Subarray with 0 sum229
301Rabin Karp Algorithm228
302Set Matrix Zeroes228
303Pair of Positive Negative Values in an Array227
304Reversing a Queue227
305Backspace String Compare227
306Contains Duplicate II Leetcode Solution225
307Combination Sum224
308Integer to Roman Leetcode Solution223
309Tower Of Hanoi223
310Common elements in all rows of a given matrix222
311Product of array except self221
312Intersection of Two Arrays II Leetcode Solution220
313Delete middle element of a stack220
314Minimum swaps required to bring all elements less than or equal to k together218
315Pascal Triangle Leetcode218
316Reverse individual words218
317Add Binary Leetcode Solution217
318Count subarrays with equal number of 1’s and 0’s217
319Segregate even and odd numbers216
320String Compression216
321Single Number Leetcode Solution215
322Construct Binary Tree from Given Inorder and Preorder Traversals215
323Find Top K (or Most Frequent) Numbers in a Stream215
324Second Most Repeated Word in a Sequence215
325Palindrome Linked List Leetcode Solution214
326Bellman Ford Algorithm214
327Arithmetic Expression Evaluation213
328Sliding Window Technique213
329Pow(x, n) Leetcode Solution213
330Count Odd Numbers in an Interval Range Leetcode Solution213
331Next Permutation213
332Count of index pairs with equal elements in an array212
333Design a stack that supports getMin() in O(1) time and O(1) extra space212
334Maximum Number of Balloons Leetcode Solution212
335Implementation of Deque using Doubly Linked List211
336Kruskal Algorithm210
337Page Replacement Algorithms in Operating Systems210
338Minimum Value to Get Positive Step by Step Sum Leetcode Solution210
339Sort elements by frequency210
340Contains Duplicate210
341Find sum of non-repeating elements (distinct) elements in an array209
342Postfix to Infix Conversion209
343K-th Smallest Element in a Sorted Matrix208
344Longest Common Prefix Leetcode Solution207
345Find Lucky Integer in an Array Leetcode Solution207
346Third Maximum Number Leetcode Solution207
347Find Numbers with Even Number of Digits Leetcode Solution206
348Permutations Leetcode Solution206
349Maximum Subarray206
350Convex Hull Algorithm206
351Sum of minimum and maximum elements of all subarrays of size k206
352Group Words With Same Set of Characters206
353Longest Substring Without Repeating Characters LeetCode Solution205
354Majority Element Leetcode Solution205
355Find the Town Judge Leetcode Solution204
356Minimum operation to make all elements equal in array204
357Sorting array using Stacks203
358Scramble String203
359Count Primes Leetcode Solutions203
360Spiral Matrix LeetCode Solution203
361First element occurring k times in an array203
362Top K Frequent Words203
363Swap Nodes in Pairs Leetcode Solutions202
364Smallest Subarray with k Distinct Numbers202
365Count subarrays having total distinct elements same as original array202
366Check if two arrays are equal or not201
367Evaluate Division201
368Power of Two Leetcode Solution200
369Given two unsorted arrays find all pairs whose sum is x200
370Merge Two Sorted Lists Leetcode Solutions200
371Minimum Path Sum199
372Fizz Buzz Leetcode199
373Special Number199
374Best Time to Buy and Sell Stock  II Leetcode Solution198
375Reverse a Number Using Stack198
376Prefix to Infix Conversion198
377Search in Rotated Sorted Array Leetcode Solution198
378Group Anagrams197
379Find duplicates in a given array when elements are not limited to a range197
380Number of Good Pairs Leetcode Solution197
381Pascal’s Triangle II Leetcode Solution196
382Leetcode Permutations196
383Reversing the First K elements of a Queue196
384Maximum possible difference of two subsets of an array196
385Missing Number Leetcode Solution196
386Minimum Absolute Difference Leetcode Solution196
387Find All Numbers Disappeared in an Array Leetcode Solution195
388Huffman Coding195
389Minimum Steps to reach target by a Knight195
390Maximum Distance Between two Occurrences of Same Element in Array195
391Running Sum of 1d Array Leetcode Solution195
392House Robber II Leetcode Solution194
393Coin Change 2 Leetcode Solution194
394Unique Paths Leetcode Solution193
395Matrix Diagonal Sum Leetcode Solution193
396How to Implement Stack Using Priority Queue or Heap?193
397Maximal Square193
398Single Number193
399Top K Frequent Elements193
400Check if Array Contains Contiguous Integers With Duplicates Allowed193
401Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution192
402Sort Array by Increasing Frequency Leetcode Solution192
403Find The Duplicate Number192
404Sorting using trivial hash function192
405Range Sum Query 2D – Immutable Leetcode Solution192
406How Many Numbers Are Smaller Than the Current Number Leetcode Solution191
407Happy Number Leetcode Solution191
408Find Number of Employees Under every Employee190
409Expression Contains Redundant Bracket or Not190
410Reverse Vowels of a String Leetcode Solution190
411Smallest Element Repeated Exactly K Times190
412Max Consecutive Ones Leetcode Solution190
413Find the Closest Palindrome number190
414Remove Duplicates from Sorted Array Leetcode Solution190
415Unique Paths190
416Subarray Sum Equals K LeetCode Solution190
417Subarray Sum Equals k190
418Sort Integers by The Number of 1 Bit Leetcode Solution189
419Decode String189
420Fibonacci Number LeetCode Solution189
421Subset sum problem189
422Zigzag Conversion189
423Nth Catalan Number188
424Length of the largest subarray with contiguous elements188
425Palindrome Substring Queries188
426Find Median from data Stream188
427Reverse Integer188
428Find Winner on a Tic Tac Toe Game Leetcode Solution188
429Difference between highest and least frequencies in an array188
430Cumulative Frequency of Count of Each Element in an Unsorted Array188
431Subtract the Product and Sum of Digits of an Integer Leetcode Solution187
432Implement Stack and Queue using Deque187
433Count Substrings with equal number of 0s, 1s and 2s187
434Check If N and Its Double Exist Leetcode Solution187
435Monotonic Array LeetCode Solution187
436Convert String To Int187
437Letter Case Permutation187
438Subarrays with distinct elements186
439Shuffle the Array Leetcode Solution186
440Trapping Rain Water Leetcode Solution186
441Print All Distinct Elements of a Given Integer Array186
442LRU Cache Implementation186
443Find top three repeated in array186
444Delete a Node from linked list without head pointer186
445Integer to English words185
446Minimum Moves to Equal Array Elements Leetcode Solution185
447Find all pairs (a, b) in an array such that a % b = k185
448Sort a stack using recursion185
449Bipartite Graph185
450Reverse Words in a String III LeetCode Solution185
451Capacity To Ship Packages Within D Days Leetcode Solution185
452Best Time to Buy and Sell Stock III Leetcode Solution185
453Maximum Depth of Binary Tree Leetcode Solution185
454Find the Duplicate Element184
455Find Minimum In Rotated Sorted Array184
456Find the first repeating element in an array of integers184
457The K Weakest Rows in a Matrix Leetcode Solution184
458Reverse a Stack Using Recursion184
459Generate a String With Characters That Have Odd Counts Leetcode Solution183
460Prim’s Algorithm183
461Excel Sheet Column Number Leetcode Solution183
462Merge Two Sorted Linked Lists183
463Count pairs from two linked lists whose sum is equal to a given value183
464Kth largest element in an Array Leetcode Solutions183
465Flood Fill LeetCode182
466Longest Common Subsequence182
467Iterative Tower of Hanoi182
468Sum of Subarray Ranges Leetcode Solution182
469Priority Queue Using Singly Linked List182
470Sorting a Queue without Extra Space182
471Floyd Warshall Algorithm182
472Find the Difference Leetcode Solution182
473Reverse a String182
474Concatenation of Array LeetCode Solution181
475Find Common Characters Leetcode Solution181
476Find First and Last Position of Element in Sorted Array Leetcode Solution181
477Remove Minimum Number of Elements Such That no Common Element Exist in both Array181
478Edit Distance181
479Find elements which are present in first array and not in second181
480MiniMax Algorithm180
481Next Greater Element I Leetcode Solution180
482Count and Say180
483Word Ladder LeetCode Solution180
484Fizz Buzz180
485Kth Largest Element in a Stream Leetcode Solution180
486Multiply Strings Leetcode Solution180
487Print all subarrays with 0 sum180
488Text Justification LeetCode Solution180
489Longest Common Prefix using Trie180
490Move Zeroes LeetCode Solution179
491Degree of an array179
492Kids With the Greatest Number of Candies Leetcode Solution179
493Top View of Binary Tree179
494Target Sum179
495Slowest Key Leetcode Solution179
496Number of Steps to Reduce a Number to Zero Leetcode Solution179
497Reverse a linked list178
498Merge Overlapping Intervals178
499Balanced Binary Tree Leetcode Solution178
500Zigzag Conversion LeetCode Solution177
501Longest subarray not having more than K distinct elements177
502Valid Parenthesis String177
503Design Parking System Leetcode Solution177
504Priority Queue in C++177
505The Stock Span Problem176
506Find four elements that sum to a given value (Hashmap)176
507Pair with given product176
508Max Area of Island176
509Count and Say Leetcode Solution176
510Shortest Palindrome176
511Koko Eating Bananas Leetcode Solution176
512Peak Index in a Mountain Array176
513Intersection of Two Arrays176
514Length of Last Word Leetcode Solution175
515Find missing elements of a range175
516Jump Game Leetcode Solution175
517Prefix to Postfix Conversion175
518Postfix to Prefix Conversion175
519Mobile Numeric Keypad Problem175
520Convert array into Zig-Zag fashion175
521Last Stone Weight175
522Shuffle String Leetcode Solution175
523Check if a given array contains duplicate elements within k distance from each other175
524Relative Sort Array Leetcode Solution174
525Find subarray with given sum (Handles Negative Numbers)174
526Smallest Subarray With all Occurrences of a Most Frequent Element174
527K-th Distinct Element in an Array174
528Find N Unique Integers Sum up to Zero Leetcode Solution174
529Find any one of the multiple repeating elements in read only array174
530Substring With Concatenation Of All Words174
531Find distinct elements common to all rows of a matrix174
532Implementation of Deque using circular array173
533Count number of triplets with product equal to given number173
534Implement a stack using single queue173
535Find Index of Closing Bracket for a Given Opening Bracket in an Expression173
536Iterative Inorder Traversal of a Binary Tree173
537Implement Stack using Queues173
538Longest Common Prefix using Sorting173
539Excel Sheet Column Title Leetcode Solution173
540Recursion173
541N-th Tribonacci Number Leetcode Solution173
542Container with Most Water173
543Next Greater Frequency Element172
544Contiguous Array Leetcode172
545Maximum sum rectangle in a 2D matrix172
546Best Time to Buy and Sell Stock172
547First negative integer in every window of size k172
548Delete Node in a Linked List Leetcode Solution172
549Largest Perimeter Triangle Leetcode Solution172
550Build Array From Permutation Leetcode Solution172
551Valid Anagrams171
552Find Words That Can Be Formed by Characters Leetcode Solution171
553Trapping Rain Water LeetCode Solution171
55401 Matrix LeetCode Solution171
555Valid Sudoku171
556Isomorphic Strings Leetcode Solution171
557Remove Linked List Elements Leetcode Solution170
558Minimum Bracket Reversals170
559Is Subsequence Leetcode Solution170
560Distribute Candies to People Leetcode Solution170
561Count the number of nodes at given level in a tree using BFS170
562Sum of Left Leaves Leetcode Solutions170
563Convert a normal BST to Balanced BST170
564Arrange given numbers to form the biggest number170
565Minimum Delete Operations to make all Elements of Array Same170
566Linked List Cycle II LeetCode Solution170
567Minimum Operations to convert X to Y170
568Jewels and Stones Leetcode Solution170
569Assign Cookies Leetcode Solution169
570Count all subsequences having product less than K169
571Integer to Roman169
572Rearrange a binary string as alternate x and y occurrences169
573Shuffle an Array169
574Gold Mine Problem169
575Hamming Distance168
576Shortest Path in a Grid with Obstacles Elimination LeetCode Solution168
577Island Perimeter Leetcode Solution168
578Group Multiple Occurrence of Array Elements Ordered by first Occurrence168
579Check for Balanced Parentheses in an Expression168
580The Knapsack Problem168
581Convert Sorted Array to Binary Search Tree Leetcode Solution168
582Insert Interval Leetcode Solution168
583Change the Array into Permutation of Numbers From 1 to N168
5843Sum Closest LeetCode Solution167
585Minimum number of distinct elements after removing m items167
586K Empty Slots LeetCode167
587Unique Binary Search Trees167
588Rotate List Leetcode Solution167
589Maximum path sum in a triangle167
590Same Tree LeetCode Solution166
591Sieve of Eratosthenes166
592How to check if two given sets are disjoint?166
593Combinations Leetcode Solution166
594Decode Ways166
595Find the smallest positive integer value that cannot be represented as sum of any subset of a given array166
596Minimum Knight Moves LeetCode Solution165
597Summary Ranges Leetcode Solution165
598Rotate Image LeetCode Solution165
599LRU Cache LeetCode Solution165
600Distance Between Bus Stops Leetcode Solution165
601Maximum difference between first and last indexes of an element in array165
602Find minimum difference between any two elements165
603Minimum number of subsets with distinct elements164
604Segregate 0s and 1s in an Array164
605Permutation in String Leetcode Solution164
606Maximum Distance in Array164
607Frog Jump Leetcode Solution164
608Remove All Occurrences of a Substring LeetCode Solution164
609Word Pattern164
610Painting Fence Algorithm163
611XOR Operation in an Array Leetcode Solution163
612Smallest Good Base163
613Sort Characters By Frequency LeetCode Solution163
614Find Sum of all unique sub-array sum for a given array163
615Sort Array By Parity LeetCode Solution163
616Minimum insertions to form a palindrome with permutations allowed163
617Word Wrap Problem163
618Minimum Depth of Binary Tree Leetcode Solution162
619Maximum Number of Chocolates to be Distributed Equally Among k Students162
620Replace Elements with Greatest Element on Right Side Leetcode Solution162
621Find if an Expression has Duplicate Parenthesis or Not162
622Printing brackets in Matrix Chain Multiplication Problem162
623Distance of nearest cell having 1 in a binary matrix162
624Coin Change Problem162
625Applications of Breadth First Search and Depth First Search162
626Best Time to Buy and Sell Stock LeetCode Solution162
627Kth Missing Positive Number Leetcode Solution161
628Minimum Cost to Hire K Workers161
629Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
630Stone Game LeetCode161
631Find the Duplicate Number LeetCode Solution161
632Defanging an IP Address Leetcode Solution161
633Find Maximum Level sum in Binary Tree160
634Optimal Account Balancing LeetCode Solution160
635Count Good Nodes in Binary Tree Leetcode Solution160
636Iterative Method to find Height of Binary Tree160
637Longest Substring with At Most K Distinct Characters LeetCode Solution160
638Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions160
639Tracking current Maximum Element in a Stack160
640Longest Increasing Subsequence160
641House Robber160
642Power of Four Leetcode Solution160
643Sum of All Odd Length Subarrays Leetcode Solution160
644Maximum Consecutive Numbers Present in an Array160
645License Key Formatting Leetcode Solution160
646Reverse a stack without using extra space in O(n)159
647Isomorphic Strings159
648Delete consecutive same words in a sequence159
649Valid Palindrome II Leetcode Solution159
650Binary Tree Zigzag Level Order Traversal LeetCode Solution159
651Check If It Is a Straight Line Leetcode Solution159
652Non-overlapping sum of two sets159
653K Empty Slots158
654Check If Two String Arrays are Equivalent Leetcode Solution158
655Best Time to Buy and Sell Stock with Cooldown Leetcode Solution158
656Number of Provinces Leetcode Solution158
657Maximum Number of Coins You Can Get Leetcode Solution158
658Letter Combinations of a Phone Number158
659Convert an array to reduced form158
660GCD Of Two Numbers158
661Queries for counts of array elements with values in given range158
662Strobogrammatic Number LeetCode Solution158
663Wiggle Sort157
664Number of Dice Rolls With Target Sum LeetCode Solution157
665Lucky Numbers in a Matrix Leetcode Solution157
666Find Largest d in Array such that a + b + c = d157
667Longest Increasing Path in a Matrix LeetCode Solution157
668Subset Sum Leetcode157
669Employee Free Time LeetCode Solution157
670Reorganize String157
671Ugly Number Leetcode Solution157
672Reducing Dishes LeetCode Solution157
673Merge Two Balanced Binary Search Trees157
674String to Integer (atoi) LeetCode Solution157
675Flipping an Image LeetCode Solution157
676Partition Labels LeetCode Solution157
677Print the Fibonacci numbers in reverse order156
678Maximum Number of Occurrences of a Substring Leetcode Solution156
679Find the Distance Value Between Two Arrays Leetcode Solution156
680Moving Average from Data Stream Leetcode Solution156
681Largest Sum Contiguous Subarray156
682Check if a queue can be sorted into another queue using a stack156
683Longest Substring with At Least K Repeating Characters LeetCode Solution156
684Reverse Only Letters LeetCode Solution156
685Find whether an array is subset of another array156
686Increasing Decreasing String Leetcode Solution156
687Form minimum number from given sequence156
688Path With Maximum Minimum Value LeetCode Solution156
689How to Create Mergable Stack?156
690Sum of f(a[i], a[j]) over all pairs in an array of n integers156
691Reversing a Queue using Recursion155
692Find Leaves of Binary Tree LeetCode Solution155
693Inorder Successor of a node in Binary Tree155
694BFS vs DFS for Binary Tree155
695Populating Next Right Pointers in Each Node155
696To Lower Case Leetcode Solution155
697Recover Binary Search Tree155
698Reservoir Sampling155
699Permutation Sequence LeetCode Solution155
700Valid Palindrome155
701Merge Two Binary Trees LeetCode Solution154
702Find pairs with given sum such that elements of pair are in different rows154
703Unique Paths II Leetcode Solution154
704Hamming Distance Leetcode Solution154
705Binary Tree zigzag level order Traversal154
706Sort Array by Increasing Frequency Leetcode Solution154
707Edit Distance LeetCode Solution154
708Dynamic Programming Basics154
709Find the Smallest Divisor given a Threshold Leetcode Solution154
710Delete Nth node from the end of the given linked list154
711Add and Search Word – Data structure design LeetCode153
712Robot Room Cleaner Leetcode Solution153
713Partition Array Into Three Parts With Equal Sum Leetcode Solution153
714Construct BST from given Preorder Traversal153
715Numbers with prime frequencies greater than or equal to k153
716Find the node with minimum value in a Binary Search Tree153
717Valid Perfect Square Leetcode Solution153
718Remove Invalid Parentheses Leetcode Solution153
719Keyboard Row Leetcode Solution153
720Majority Element II Leetcode Solution153
721Decompress Run-Length Encoded List Leetcode Solution153
722Maximum Product of Three Numbers LeetCode Solution153
723Convert a Number to Hexadecimal Leetcode Solution153
724Factorial Trailing Zeroes Leetcode Solution152
725Longest Span with same Sum in two Binary arrays152
726Rank Transform of an Array Leetcode Solution152
727Stack Permutations (Check if an array is stack permutation of other)152
728String Compression LeetCode Solution152
729Non-decreasing Array LeetCode Solution151
730Bulb Switcher LeetCode Solution151
731Largest subarray with equal number of 0s and 1s151
732Race Car LeetCode Solution151
733Find the largest multiple of 3151
734Find Maximum Depth of Nested Parenthesis in a String151
735Queue based approach for first non-repeating character in a stream151
736Deletion in a Binary Tree151
737Symmetric Tree Leetcode Solution150
738Linked List Cycle150
739Minimum Cost For Tickets Leetcode Solution150
740Bubble sort using two Stacks150
741First Unique Character in a String LeetCode Solution150
742Invert Binary Tree LeetCode Solution150
743Minimize Maximum Pair Sum in Array LeetCode Solution150
744Maximum 69 Number Leetcode Solution150
745Binomial Coefficient150
746Find Pair with Greatest Product in Array150
747Maximum Product of Two Elements in an Array Leetcode Solution150
748Minimum Height Trees150
749Restore IP Addresses Leetcode Solution150
750Remove Nth Node From End of List Leetcode Solution150
751Word Pattern LeetCode Solution150
752Find unique character in a string150
753Binary Tree Maximum Path Sum LeetCode Solution150
754Sorted Linked List to Balanced BST150
755Find if Path Exists in Graph Leetcode Solution150
756Number of Islands II LeetCode Solution149
757Count quadruples from four sorted arrays whose sum is equal to a given value x149
758Finding K closest element149
759Morris Traversal149
760Diagonal Traversal of Binary Tree149
761Search in a Binary Search Tree Leetcode Solution149
762Remove Duplicates from Sorted List LeetCode Solution149
763Generate all possible sorted arrays from alternate elements of two given sorted arrays149
764Best Meeting Point LeetCode Solution149
765Minimum Distance Between BST Nodes Leetcode Solution149
766Merge K Sorted Linked Lists149
767Perform String Shifts Leetcode149
768Find All Duplicates in an Array LeetCode Solution149
769Growable array based stack149
770Maximum Length of a Concatenated String with Unique Characters Leetcode Solution149
771Student Attendance Record I Leetcode Solution149
772k-th missing element in increasing sequence which is not present in a given sequence149
773Evaluate Reverse Polish Notation LeetCode Solution149
774Find Median from Data Stream LeetCode Solution149
775Jump Game149
776Elements to be added so that all elements of a range are present in array149
777Valid Number148
778Largest rectangular sub-matrix whose sum is 0148
779Kth ancestor of a node in binary tree148
780Remove brackets from an algebraic string containing + and – operators148
781Program for Bridge and Torch problem148
782Split a String in Balanced Strings Leetcode Solution148
783Maximum Difference Between Increasing Elements LeetCode Solution148
784Snakes and Ladders LeetCode Solution148
785Minimum time required to rot all oranges148
786N-Queens LeetCode Solution148
787Check for Palindrome after every character replacement Query147
788Special Array With X Elements Greater Than or Equal X Leetcode Solution147
789Nearest Exit from Entrance in Maze LeetCode Solution147
790Maximum Depth of N-ary Tree Leetcode Solution147
791Nested List Weight Sum II LeetCode Solution147
792Minimum number of jumps to reach end147
793Sort an array according to the order defined by another array147
794Largest Rectangle in Histogram LeetCode Solution147
795Relative Ranks Leetcode Solution147
796Number of NGEs to the Right147
797Merge Sorted Array LeetCode Solution147
798Transpose Graph147
799Remove Duplicates from Sorted List II147
800Minimum Time Visiting All Points Leetcode Solution147
801Crawler Log Folder Leetcode Solution146
802Base 7 Leetcode Solution146
803A Space Optimized DP solution for 0-1 Knapsack Problem146
804Print a Binary Tree in Vertical Order146
805Sort Array By Parity II Leetcode Solution146
806Search a 2D Matrix II Leetcode Solution146
807Convert BST to Min Heap146
808Get Maximum in Generated Array Leetcode Solution146
809Friends Pairing Problem146
810Count items common to both the lists but with different prices146
811Check If Array Pairs Are Divisible by k LeetCode Solution146
812String comparison containing wildcards146
813Sort Colors146
814Tiling Problem146
815Partition to K Equal Sum Subsets Leetcode Solution146
816Path with maximum average value145
817Alien Dictionary LeetCode Solution145
818Clone Graph LeetCode Solution145
819Check if Two Expressions With Brackets are Same145
820Interval Tree145
821Minimum Number of Taps to Open to Water a Garden LeetCode Solution145
822Minimum swaps to make sequences increasing145
823Reorder Data in Log Files LeetCode Solution145
824Number Complement Leetcode Solution145
825Final Prices With a Special Discount in a Shop Leetcode Solution145
826Partition List Leetcode Solution144
827Circular Queue144
828Total Numbers With no Repeated Digits in a Range144
829One Edit Distance LeetCode Solution144
830Longest Subarray Having Count of 1s One More than Count of 0s144
831Iterative Preorder Traversal144
832Maximum size subarray sum equals k144
833Course Schedule II – LeetCode144
834Level order Traversal in Spiral Form144
835Sorted Array to Balanced BST144
836Regular Expression Matching144
837Design a Stack With Increment Operation Leetcode Solution144
838Priority Queue using doubly linked list143
839Can Place Flowers LeetCode Solution143
840Top K Frequent Words LeetCode Solution143
841Subarray Product Less Than K LeetCode Solution143
842Guess Number Higher or Lower LeetCode Solution143
843Brightest Position on Street LeetCode Solution143
844Minimum Swaps to Make Strings Equal Leetcode Solution143
845Minimum Jumps to Reach Home LeetCode Solution143
846Find all triplets with zero sum143
847Last Stone Weight II LeetCode Solution143
848Subset with sum divisible by m143
849Subsequence of Size K With the Largest Even Sum LeetCode Solution143
850Check if a given array can represent Preorder Traversal of Binary Search Tree143
851Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution143
852Permutation Coefficient143
853Count Distinct Elements in Every Window of Size K143
854Find the Only Repetitive Element Between 1 to N-1142
855Brick Wall LeetCode Solution142
856Valid Parentheses Leetcode Solution142
857Maximum Profit in Job Scheduling Leetcode Solution142
858Find the subarray with least average142
859Find All Possible Recipes from Given Supplies LeetCode Solution142
860Maximum Nesting Depth of the Parentheses Leetcode Solution142
861Form Minimum Number From Given Sequence141
862Matrix Chain Multiplication141
863Given an Array of Pairs Find all Symmetric Pairs in it141
864Design Browser History LeetCode Solution141
865Binary Search Tree Search and Insertion141
866Check if an Array is Stack Sortable141
867Count ways to reach the nth stair using step 1, 2 or 3141
868Insert into a Binary Search Tree Leetcode Solution141
869Sum of nearest smaller and greater number141
870Repeated Substring Pattern LeetCode Solution141
871Range sum queries without updates141
872Water Bottles Leetcode Solution141
873Spiral Matrix II Leetcode Solution141
874Check whether a given Binary Tree is Complete or not141
875Least Number of Unique Integers after K Removals Leetcode Solution141
876LCS (Longest Common Subsequence) of three strings141
877Daily Temperatures Leetcode Solution140
878Union and Intersection of two Linked Lists140
879GCDs of given index ranges in an array140
880Construct Complete Binary Tree from its Linked List Representation140
881Delete And Earn140
882Count Negative Numbers in a Sorted Matrix LeetCode Solution140
883Maximum Score After Splitting a String Leetcode Solution140
884Guess Number Higher or Lower II140
885Three way partitioning of an array around a given range140
886Insert Delete GetRandom140
887Minimum Sum Path in a Triangle140
8884Sum140
889Tree Traversal (Preorder, Inorder & Postorder)140
890Destination City Leetcode Solution140
891Count Subarrays with Same Even and Odd Elements140
892Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution140
893Find all permuted rows of a given row in a matrix140
894Find Maximum Sum Possible Equal Sum of Three Stacks139
895Number of Days Between Two Dates LeetCode Solution139
896Shortest Word Distance Leetcode Solution139
897Diagonal Traversal LeetCode Solution139
898Missing Element in Sorted Array LeetCode Solution139
899Convert Sorted List to Binary Search Tree139
900Queries for GCD of all numbers of an array except elements in a given range139
901Check if stack elements are pairwise consecutive139
902Sequences of given length where every element is more than or equal to twice of previous139
903A program to check if a binary tree is BST or not139
904Lemonade Change Leetcode Solution139
905Rearrange an Array Such that arr[i] is equal to i139
906Distinct adjacent elements in an array139
907Identify and Mark Unmatched Parenthesis in an Expression139
908Find Common Characters Leetcode Solution138
909Check if the given array can represent Level Order Traversal of Binary Search Tree138
910Minimum sum of multiplications of n numbers138
911An Interesting Method to generate Binary Numbers from 1 to n138
912Set Matrix Zeroes Leetcode Solution138
913Robot Bounded In Circle LeetCode Solution138
914Alien Dictionary138
915Range LCM Queries138
916Rearrange Spaces Between Words Leetcode Solution138
917BFS for Disconnected Graph138
918Find distance between two nodes of a Binary Tree138
919Time Based Key-Value Store LeetCode Solution138
920Balanced Expression with Replacement138
921Special Positions in a Binary Matrix Leetcode Solution138
922Diagonal Traverse LeetCode Solution137
923Spiral Matrix III LeetCode Solution137
924Merge Two Sorted Lists Leetcode137
925Number of Distinct Islands Leetcode Solution137
926Longest Palindromic Subsequence137
927Vertical sum in a given binary tree137
928Maximum Frequency Stack Leetcode Solution136
929Maximum Subarray Sum Excluding Certain Elements136
930Can Make Arithmetic Progression From Sequence Leetcode Solution136
931Stone Game II Leetcode136
932K’th Largest Element in BST when modification to BST is not allowed136
933Infix to Postfix136
934Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i136
935Palindrome Partitioning Leetcode Solution136
936Print Fibonacci sequence using 2 variables136
937Averages of Levels in Binary Tree136
938Queue using Stacks136
939Number of Equivalent Domino Pairs Leetcode Solution136
940Lexicographical Numbers Leetcode Solution136
941Difference Array | Range update query in O(1)135
942Median of Two Sorted Arrays135
9433 Sum135
944Binary array after M range toggle operations135
945Construct the Rectangle Leetcode Solution135
946Construct BST from its given Level Order Traversal135
947Largest area rectangular sub-matrix with equal number of 1’s and 0’s135
948Dividing Array into Pairs With Sum Divisible by K135
949Three Consecutive Odds Leetcode Solution135
950Trim a Binary Search Tree135
951Remove Duplicates from Sorted List II LeetCode Solution135
952Largest Substring Between Two Equal Characters Leetcode Solution134
953Maximize Sum of Array after K Negations Leetcode Solution134
954Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution134
955Intersection of Two Linked Lists LeetCode Solution134
956Check if any two intervals overlap among a given set of intervals134
957All Unique Triplets that Sum up to a Given Value134
958Pattern Occurrences using Stack134
959Sliding Window Maximum134
960Minimum Height Trees LeetCode Solution134
961Analyze User Website Visit Pattern LeetCode Solution134
962Height of a generic tree from parent array134
963Largest divisible pairs subset134
964Binary Tree Longest Consecutive Sequence LeetCode Solution134
965Word Break134
966Merging Intervals134
967Strongly Connected Component134
968Newman-Conway Sequence134
969Symmetric Tree133
970First missing positive133
971Product of Array Except Self LeetCode Solution133
972Split Array Into Consecutive Subsequences133
973Count Submatrices With All Ones LeetCode Solution133
974Palindrome Partitioning133
975Create Maximum Number133
976Maximum Product Subarray133
977Segment Tree133
978Iterative Postorder Traversal Using Two Stacks133
979Find Maximum of Minimum for Every Window Size in a Given Array133
980Depth First Search (DFS) for a Graph133
981Reverse Nodes in K-Group132
982Find postorder traversal of BST from preorder traversal132
983Count Primes in Ranges132
984Length of Longest Fibonacci Subsequence132
985Breadth First Search (BFS) for a Graph132
986My Calendar I LeetCode Solution132
987Sign of the Product of an Array LeetCode Solution132
988Level Order Traversal of Binary Tree132
989Maximum subsequence sum such that no three are consecutive132
990Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space132
991Asteroid Collision LeetCode Solution132
992Climbing stairs132
993Binary Search Tree Delete Operation132
994Minesweeper LeetCode Solution132
995Partition Equal Subset Sum131
996Count pair with Given Sum131
997Maximum Number of Ways to Partition an Array LeetCode Solution131
998Boundary Traversal of binary tree131
999Find Duplicate Subtrees131
1000Find the Difference Leetcode Solution131
1001Kill Process LeetCode Solution131
1002Kth Smallest Element in a BST Leetcode Solution131
1003Rearrange array such that even positioned are greater than odd131
1004Find the First Circular Tour that visits all the Petrol Pumps131
1005Largest Number Leetcode Solution130
1006Super Ugly Number130
1007Find number of pairs in an array such that their XOR is 0130
1008Serialize and Deserialize Binary Tree130
1009Decrypt String from Alphabet to Integer Mapping Leetcode Solution130
1010Double the first element and move zero to end130
1011The Painter’s Partition Problem130
1012Insertion in a Binary Tree130
1013Graph Valid Tree LeetCode Solution130
1014Make The String Great Leetcode Solution130
1015Longest Nice Substring LeetCode Solution130
1016Level order traversal using two Queues130
1017Shortest Completing Word Leetcode Solution130
1018Maximum Length of Repeated Subarray130
1019Unique Paths II130
1020Longest subsequence such that difference between adjacents is one129
1021Collect maximum points in a grid using two traversals129
1022Friends Of Appropriate Ages LeetCode Solution129
1023K Closest Points to Origin Leetcode Solution129
1024Number Of Longest Increasing Subsequence129
1025Compute nCr % p129
1026Valid Boomerang Leetcode Solution129
1027Count subarrays where second highest lie before highest129
1028Advantages of BST over Hash Table129
1029Ugly Number II LeetCode Solution129
1030Binary Search Tree129
1031Construction of Longest Increasing Subsequence (N log N)128
1032Next Greater Element III LeetCode Solution128
1033Available Captures for Rook Leetcode Solution128
1034Employee Importance LeetCode Solution128
1035Maximum Product of Indexes of Next Greater on Left and Right128
1036Minimum Size Subarray Sum128
1037The Maze III LeetCode Solution128
1038Design Hit Counter LeetCode Solution128
1039Boolean Parenthesization Problem128
1040Construct Binary Tree from given Parent Array representation128
1041Defanging an IP Address LeetCode Solution128
1042Balanced Binary Tree128
1043String Matching in an Array Leetcode Solution128
1044Number of palindromic paths in a matrix128
1045Invalid Transactions LeetCode Solution128
1046Build an Array With Stack Operations Leetcode Solution128
1047Scramble String LeetCode Solution128
1048Count minimum steps to get the given desired array127
1049Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1050Maximum Sum of 3 Non-Overlapping Subarrays127
1051Maximum difference between frequency of two elements such that element having greater frequency is also greater127
1052Longest Bitonic Subsequence127
1053Maximum weight transformation of a given string127
1054Morris Inorder Traversal127
1055Regular Expression Matching Regular Expression Matching LeetCode Solution127
1056Find whether a subarray is in form of a mountain or not127
1057Populating Next Right Pointers in Each Node Leetcode Solution127
1058Add two numbers127
1059Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’127
1060Ugly Numbers127
1061Find Peak Element127
1062Bitwise AND of Numbers Range LeetCode Solution126
1063Find the minimum distance between two numbers126
1064Recover Binary Search Tree Leetcode Solution126
1065Implement Trie (Prefix Tree) Leetcode Solution126
1066Iterative Depth First Traversal of Graph126
1067Lowest Common Ancestor126
1068Minimum Index Sum of Two Lists126
1069Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1070Validate Binary Search Tree126
1071Maximize Distance to Closest Person LeetCode Solution125
1072Find a Peak Element II LeetCode Solution125
1073Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution125
1074Remove Duplicates from Sorted Array II Leetcode Solution125
1075Number of Closed Islands Leetcode Solution125
1076Combination Sum IV LeetCode Solution125
1077Path Sum II LeetCode Solution125
1078Move all negative elements to end in order with extra space allowed125
1079Binary Tree Right Side View LeetCode Solution125
1080Divisible Pairs Counting125
1081Custom Sort String Leetcode Solution125
1082Largest BST Subtree LeetCode Solution125
1083Smallest Common Region Leetcode Solution125
1084Search in Sorted Rotated Array124
1085Number of Students Doing Homework at a Given Time Leetcode Solution124
1086Clone a Binary Tree with Random Pointers124
1087Types of Binary Tree124
1088Subarrays with K Different Integers Leetcode Solution124
1089Rearrange array such that even index elements are smaller and odd index elements are greater124
1090Binary Tree Data Structure124
1091Day of the Year Leetcode Solution124
1092Find Smallest Range Containing Elements from k Lists123
1093Number of siblings of a given Node in n-ary Tree123
1094Print Next Greater Number of Q queries123
1095Kth Smallest Product of Two Sorted Arrays LeetCode Solution123
1096Consecutive Characters LeetCode Solution123
1097Next Permutation Leetcode Solution123
1098Serialize and Deserialize Binary Tree LeetCode Solution123
1099Generate Parentheses Leetcode Solution123
1100Path Sum123
1101Print all triplets in sorted array that form AP123
1102Level of Each node in a Tree from source node123
1103Count pairs from two sorted arrays whose sum is equal to a given value x123
1104Find maximum difference between nearest left and right smaller elements122
1105Remove Palindromic Subsequences Leetcode Solution122
1106Root to Leaf path with target sum Leetcode Solutions122
1107Maximum Product Subarray122
1108Topological Sorting122
1109Distinct Subsequences122
1110Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution121
1111Valid Tic-Tac-Toe State LeetCode Solution121
1112Cutting a Rod121
1113Convert BST into a Min-Heap without using array121
1114Third Maximum Number Leetcode Solution121
1115Print Right View of a Binary Tree121
1116Write Code to Determine if Two Trees are Identical121
1117Find Three Element From Different Three Arrays Such That a + b + c = sum121
1118Bottom View of a Binary Tree121
1119Maximum Binary Tree121
1120Constant time range add operation on an array121
1121Count Largest Group Leetcode Solution121
1122Remove duplicates from sorted array121
1123Increasing Triplet Subsequence LeetCode Solution120
1124Cells with Odd Values in a Matrix LeetCode Solution120
1125Golomb sequence120
1126Mean of Array After Removing Some Elements Leetcode Solution120
1127Queries for Number of Distinct Elements in a Subarray120
1128Search Insert Position120
1129Products of ranges in an array120
1130Search an Element in Sorted Rotated Array120
1131Palindrome Permutation LeetCode Solution120
1132Minimum sum of squares of character counts in a given string after removing k characters120
1133Iterative method to find ancestors of a given binary tree120
1134Reformat The String Leetcode Solution120
1135Moser-de Bruijn Sequence119
1136Minimum Score Triangulation of Polygon Leetcode Solution119
1137Print modified array after executing the commands of addition and subtraction119
1138Prime Palindrome LeetCode Solution119
1139Longest Increasing Consecutive Subsequence119
1140Minimum Absolute Difference in BST Leetcode Solution119
1141Longest Subarray of 1’s After Deleting One Element LeetCode Solution119
1142Thousand Separator Leetcode Solution119
1143Red-Black Tree Introduction118
1144Delete Nodes and Return Forest Leetcode Solution118
1145Construct K Palindrome Strings LeetCode Solution118
1146Find maximum length Snake sequence118
1147Binary Tree to Binary Search Tree Conversion118
1148Sum of Even Numbers After Queries118
1149Possible Bipartition LeetCode Solution117
1150Count even length binary sequences with same sum of first and second half bits117
1151Maximum Product of Splitted Binary Tree LeetCode Solution117
1152Longest Repeated Subsequence117
1153Decision Tree117
1154Factorial Trailing Zeroes LeetCode Solution117
1155K maximum sums of overlapping contiguous sub-arrays117
1156Check Array Formation Through Concatenation Leetcode Solution117
1157Transform a BST to Greater sum Tree117
1158Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1159Kth Smallest Number in Multiplication Table Leetcode Solution117
1160Swap Nodes In Pairs117
1161Palindromic Substrings Leetcode Solution117
1162Maximize sum of consecutive differences in a circular array116
1163Minimum Cost to Move Chips to The Same Position LeetCode Solution116
1164Rotate Array116
1165Find the smallest binary digit multiple of given number116
1166Subset Sum Problem in O(sum) space116
1167Merge two BSTs with limited extra space116
1168Find a sorted subsequence of size 3 in linear time116
1169Minimum Sideway Jumps LeetCode Solution116
1170Compare Strings by Frequency of the Smallest Character Leetcode Solution116
1171Priority Queue116
1172Swapping Nodes in a Linked List Leetcode Solution116
1173Web Crawler LeetCode Solution116
1174K’th Largest element in BST using constant extra space116
1175Search Suggestions System LeetCode Solution115
1176Find Largest Value in Each Tree Row LeetCode Solution115
1177Bus Routes Leetcode Solution115
1178First Bad Version115
1179Closest Binary Search Tree Value Leetcode Solution115
1180Minimum Moves to Equal Array Elements LeetCode Solution114
1181Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1182Number of Orders in the Backlog Leetcode Solution114
1183Count Pairs Whose Products Exist in Array114
1184Diameter of N-Ary Tree LeetCode Solution114
1185Decrease Elements To Make Array Zigzag LeetCode Solution114
1186Given a binary tree, how do you remove all the half nodes?113
1187Matchsticks to Square Leetcode Solution113
1188Queue Reconstruction by Height113
1189Contiguous Array LeetCode Solution113
1190Reverse a Path in BST using Queue113
1191Moving Stones Until Consecutive Leetcode Solution113
1192Maximum number of segments of lengths a, b and c113
1193Convert Sorted Array to Binary Search Tree LeetCode Solutions113
1194Array Queries for multiply replacements and product112
1195Reformat Date LeetCode Solution112
1196Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution112
1197Maximum sum bitonic subarray112
1198Write a function to get the intersection point of two Linked Lists112
1199Kth Smallest Element in a BST112
1200Champagne Tower LeetCode Solution112
1201Lowest Common Ancestor in Binary Search Tree112
1202Closest Leaf in a Binary Tree LeetCode Solution112
1203Range Sum Query using Sparse Table111
1204Maximum sum of pairs with specific difference111
1205Replace two consecutive equal values with one greater111
1206Valid Triangle Number111
1207How to print maximum number of A’s using given four keys111
1208New 21 Game111
1209Maximum Depth Of Binary Tree111
1210Valid Perfect Square LeetCode Solution110
1211Graph and its representation110
1212Concatenation of Array LeetCode Solution110
1213Range Queries for Longest Correct Bracket Subsequence110
1214Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution110
1215Divide Two Integers Leetcode Solution110
1216Sum of Left Leaves LeetCode Solution110
1217Integer Break LeetCode Solution110
1218Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1219Maximum sum of a path in a Right Number Triangle109
1220Path Crossing Leetcode Solution109
1221The kth Factor of n Leetcode Solution109
1222BST to a Tree with Sum of all Smaller Keys109
1223Guess The Word109
1224Arithmetic Slices II – Subsequence LeetCode Solution109
1225Flatten 2D Vector LeetCode Solution109
1226Lowest Common Ancestor of a Binary Tree Leetcode Solution109
1227Check if each internal node of a BST has exactly one child109
1228Design Skiplist LeetCode Solution109
1229Print modified array after multiple array range increment operations109
1230Merge Sort109
1231Symmetric Tree LeetCode Solution Leetcode Solution109
1232Count Subsets Having Distinct Even Numbers108
1233Perfect Squares LeetCode Solution108
1234Queries on Probability of Even or Odd Number in given Ranges108
1235Sliding Window Median Leetcode Solution108
1236Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1237Check Completeness of a Binary Tree LeetCode Solution108
1238Check if all levels of two Binary Tree are anagrams or not108
1239Check for Identical BSTs without building the trees108
1240Power of Two107
1241Count and Toggle Queries on a Binary Array107
1242Maximum Array from Two given Arrays Keeping Order Same107
1243Mean of range in array107
1244Longest Common Prefix Using Word by Word Matching107
1245Graph Cloning107
1246Parallel Courses II LeetCode Solution107
1247Largest Plus Sign Leetcode Solution107
1248Find Minimum in Rotated Sorted Array II LeetCode Solution107
1249Contiguous Array107
1250LRU Cache Leetcode Solution106
1251Bold Words in String LeetCode Solution106
1252Maximize Elements Using Another Array106
1253Find minimum number of merge operations to make an array palindrome106
1254Missing Number106
1255Print n terms of Newman-Conway Sequence106
1256Find k-th smallest element in BST (Order Statistics in BST)105
1257Verify Preorder Serialization of a Binary Tree105
1258Excel Sheet Column Title LeetCode Solution105
1259Minimum Remove to Make Valid Parentheses LeetCode Solution105
1260Check If a String Can Break Another String Leetcode Solution105
1261Image Overlap LeetCode Solution104
1262Print Ancestors of a Given Binary Tree Node Without Recursion104
1263Maximum Product Subarray104
1264Next greater element104
1265Palindrome Partitioning103
1266Merge k Sorted Lists Leetcode Solution103
1267Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1268Smallest Range II Leetcode Solution103
1269Check if two nodes are on the same path in a Tree102
1270Min Cost Climbing Stairs LeetCode Solution101
1271Check in binary array the number represented by a subarray is odd or even101
1272Orderly Queue LeetCode Solution101
1273Merge Sorted Array100
1274Koko Eating Bananas LeetCode Solution100
1275Peeking Iterator LeetCode Solution99
1276Newman–Shanks–Williams prime99
1277Check if X can give change to every person in the Queue99
1278Number of elements less than or equal to a given number in a given subarray98
1279Different Ways to Add Parentheses Leetcode Solution98
1280Maximum Sum Increasing Subsequence97
1281Largest Submatrix With Rearrangements LeetCode Solution97
1282Range Minimum Query (Square Root Decomposition and Sparse Table)97
1283Number of indexes with equal elements in given range96
1284Queries for Decimal Values of Subarrays of a Binary Array96
1285Find maximum average subarray of k length96
1286Longest Substring Without Repeating Characters Leetcode Solution95
1287Maximum product of an increasing subsequence95
1288Minimum Total Space Wasted With K Resizing Operations LeetCode Solution95
1289Array Nesting Leetcode Solution94
1290Check given array of size n can represent BST of n levels or not94
1291Arranging Coins Leetcode Solution93
1292Binary Tree to Binary Search Tree Conversion using STL set93
1293Encoded String With Shortest Length LeetCode Solution92
1294Reach a Number LeetCode Solution92
1295Minimum Number of People to Teach LeetCode Solution92
1296Random Pick Index LeetCode Solution92
1297Convert to Base -2 LeetCode Solution91
1298Queries on XOR of greatest odd divisor of the range91
1299Find the Winner of the Circular Game LeetCode Solution91
1300Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1301Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1302Jump Game IV LeetCode Solution90
1303Insert Delete GetRandom O(1) Leetcode Solution89
1304Palindrome Number LeetCode Solution88
1305Add Two Numbers II Leetcode Solution87
1306Vertical Order Traversal of Binary Tree LeetCode Solution87
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution86
1308Design Underground System Leetcode Solution85
1309Print Maximum Length Chain of Pairs84
1310Continuous Subarray Sum LeetCode Solution83
1311Detect Capital Leetcode Solution81
1312Design A Leaderboard Leetcode Solution79
1313Substring with Concatenation of All Words Leetcode Solution77
1314Top K Frequent Elements LeetCode Solution76
1315Minimum Swaps to Group All 1’s Together Leetcode Solution76
1316Minimum Path Sum Leetcode Solution73
1317Binary Tree Inorder Traversal LeetCode Solution72
1318Decode String Leetcode Solution72
1319Odd Even Linked List Leetcode Solution72
1320Shortest Unsorted Continuous Subarray LeetCode Solution71
1321Count Sub Islands LeetCode Solution71
1322Shifting Letters LeetCode Solution71
1323Sum Root to Leaf Numbers LeetCode Solution70
1324Maximum Population Year LeetCode Solution70
1325Find the Town Judge LeetCode Solution70
1326Best Meeting Point LeetCode Solution69
1327Longest Common Subsequence LeetCode Solution68
1328Find the Town Judge LeetCode Solution67
1329Design Add and Search Words Data Structure LeetCode Solution66
1330Score of Parenthesis LeetCode Solution64
1331Maximum Population Year LeetCode Solution63
1332Rectangle Overlap LeetCode Solution63
1333Insert into a Sorted Circular Linked List LeetCode Solution62
1334Stone Game IV LeetCode Solution61
1335Flatten Binary Tree to Linked List LeetCode Solution60
1336Range Sum Query 2D – Immutable LeetCode Solution59
1337Valid Triangle Number LeetCode Solution59
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution53
1340Divide Chocolate LeetCode Solution50
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution41
1342Range Sum of BST LeetCode Solution41
1343Reverse Integer Leetcode Solution39
1344Sort Colors LeetCode Solution36
1345Find K Closest Elements LeetCode Solution33
1346Excel Sheet Column Number LeetCode Solution31
1347Rotate String LeetCode Solution31
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »