Valid Triangle Number LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Apple Bloomberg ByteDance Expedia LinkedIn Robinhood UberViews 63

Problem Statement:

Valid Triangle Number LeetCode Solution says – Given an integer array nums, return the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.

Valid Triangle Number LeetCode Solution

Example 1:

Input: nums = [2,2,3,4]
Output: 3
Explanation: Valid combinations are: 
2,3,4 (using the first 2)
2,3,4 (using the second 2)

Example 2:

Input: nums = [4,2,3,4]
Output: 4


The approach is similar to any binary search problem where you want to find value in an array without traversing(in our case third valid side calls it ‘c’).
So there are 2 ways to do this

  1. Hashmap get required value in O(1)
  2. Binary search O(log n)

Case 1 does not work for us as we don’t want an exact sum but elements less than a certain threshold(a+b).
So to conclude for every side we need to find b,c such that it forms a valid triangle that’s where 2 pointer comes into the picture.


Valid Triangle Number C++ Solution:

class Solution {
    int triangleNumber(vector<int>& nums) {
        int n=size(nums),count=0;
        sort(nums.begin(), nums.end());
        //basically we will be finding valid pair for ith value
        for(int i=2;i<n;i++){
            int left=0,right=i-1;
            while(left < right){
                if(nums[left]+nums[right] > nums[i]){
                    count += right-left;
                    right--; // imp to note check explanation
        return count;

Valid Triangle Number Java Solution:

class Solution 
    public int triangleNumber(int[] nums) 
        int ans=0;
        for(int i=0;i<nums.length;i++)
            for(int j=i+1;j<nums.length;j++)
                int pos=binarySearch(nums,j+1,nums.length-1,nums[i]+nums[j]-1);
        return ans;
    public int binarySearch(int nums[],int start,int end,int target)
        int ans=-1;
            int mid=start+(end-start)/2;
        return ans;

Complexity Analysis of Valid Triangle Number Leetcode Solution:

Time complexity- O(n): Due to binary search
Space complexity- O(1)

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2831
2Java program to find the number of Nodes in a Binary Tree2508
3Reverse a string without affecting special characters2470
4Delete a node of a linked list at given position1983
5Palindrome using Recursion1884
6Insert nodes in a linked list in a sorted way (Ascending Order)1668
7Find elements pair from array whose sum equal to number1655
8Sort Elements by Frequency of Occurrences1641
9Write a program to print all permutations of a given string1614
10Quick Sort1546
11Find Minimum Distance Between Two Numbers in an Array1479
12Create a Doubly Linked List1454
13Reverse an Array1417
14Smallest window in a string containing all characters of another string1402
15Find a Triplet That Sum to a Given Value1365
16Recursively remove all adjacent duplicates1363
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1327
19Sum of numbers in String1324
20Smallest Positive Number Missing in an Unsorted Array1292
21Check if the Elements of an Array are Consecutive1261
22Detect a loop in the Linked List1247
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1224
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1209
27Recursive function to do substring search1206
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1131
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1112
32Maximum Subarray Sum using Divide and Conquer1109
33Remove characters from first string which are in second1077
34Find Leaders in an Array1065
35Swap nodes in the linked list1044
36Find the Number Occurring Odd Number of Times in an Array1009
37Arrange given Numbers to Form the Biggest Number II997
38Find the second most frequent character995
39Given a string find its first non-repeating character976
40Find Triplet in Array With a Given Sum968
41Total number of occurrences of a given item in the linked list960
42Given a sorted array and a number x, find the pair in array whose sum is closest to x959
43A Program to check if strings are rotations of each other or not955
44Print all possible words from phone digits940
45Find the Missing Number931
46Rearrange Positive and Negative Numbers Alternatively in Array926
47Longest Palindromic Substring910
48Segregate even and odd nodes in a linked list893
49Print Longest common subsequence888
50Union and Intersection of Two Linked Lists879
51Transform one string to another using minimum number of given operations873
52Check rearranged string can form a palindrome855
53Rearrange given Array in Maximum Minimum Form851
54Iterative Implementation of Quick Sort841
55Count Possible Triangles827
56Multiplication of Two Matrices809
57Check if the linked list is palindrome801
58Count of Triplets With Sum Less than Given Value801
59Rotate a Linked List801
60Stock Buy Sell to Maximize Profit797
61Insertion Sort770
62Concatenation of two strings768
63Tug of War766
64Count Number of Substrings with K Distinct Character’s762
65Print all duplicates in the input string762
66Find Nearest Greater and Smaller Element751
67The Celebrity Problem744
68Find Pythagorean Triplets from Array743
69Reverse String Without Temporary Variable738
70Remove ‘b’ and ‘ac’ from a given string737
71Find all Common Elements in Given Three Sorted Arrays735
72Remove all duplicates in an unsorted linked list715
73Find the Row with Maximum Number of 1’s712
74Find the Peak Element from an Array704
75Find the subarray whose sum is equal to a given number X702
76Remove Minimum Characters so that Two Strings Become Anagrams697
77Addition of Two Matrices692
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s684
81Implement Two Stacks in an Array682
82Maximum Sum of Non Consecutive Elements677
83Lexicographic rank of string662
84Maximum Product Subarray II662
85Check if Two given Matrices are Identical653
86Multiplication of Previous and Next653
87Subtraction of Two Matrices642
88Merge K Sorted Arrays and Print Sorted Output639
89Move All the Zeros to the End of the Given Array637
90Divide a string in N equal parts633
91Online Algorithm for Checking Palindrome in a Stream629
92Form Minimum Number from Given Sequence of D’s and I’s628
93Check whether two strings are anagram of each other622
94Remove recurring digits in a given number622
95Sort a linked list that is sorted alternating ascending and descending617
96Maximum Circular Subarray Sum616
97Sort a stack using a temporary stack613
98Find the Minimum Element in a Sorted and Rotated Array610
99Move last element of the Linked List at first place610
100Subarray and Subsequence606
101First Circular Tour to Visit all the Petrol Bunks604
102Largest Subarray with Equal Number of 0’s and 1’s602
103Compare two strings(linked lists)600
104Flattening a linked list599
105Maximum Element in an Array which is Increasing and then Decreasing597
106Palindrome Permutations of a String591
107Elements Appear more than N/K times in Array586
108Palindromes in a given range585
109Print all permutations with repetition583
110Majority Element582
111Run length encoding582
112Pangram Checking580
113Minimum insertions to form a shortest palindrome579
114Minimum Characters to be Added at Front to Make String Palindrome572
115Remove all duplicates in a sorted linked list570
116Merge a linked list into another at alternate positions570
117Most repeating character in a string569
118Rearrange a given linked list in-place569
119Minimum number of Merge Operations to make an Array Palindrome567
120Rotate string to get lexicographically minimum string565
121Repeated Subsequence of Length Two or More562
122Print all anagrams together in a sequence of words559
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem548
125Two Sum Leetcode Solution545
126Merge Overlapping Intervals II543
127Clone a Linked List with next and random pointer542
1283Sum Leetcode Solution540
129Size of The Subarray With Maximum Sum533
130Transpose of a Matrix533
131Remove Extra Spaces from a String530
132Removing Spaces from a String using stringstream528
133Remove duplicates from a string526
134Check if a given string is a rotation of a palindrome525
135Longest Palindrome can be Formed by Removing or Rearranging Characters524
136Partition Problem524
137Smallest Palindrome after Replacement523
138Maximum Sum Increasing Subsequence523
139Check whether Strings are K Distance Apart or Not514
140Generate all Binary Strings from Given Pattern512
141Length of Longest valid Substring510
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized507
143Insert Node in the Sorted Linked List506
144Delete Last Occurrence504
145Check if Two given Strings are Isomorphic to each other501
146Maximum difference between two elements such as larger element comes after smaller494
147Program to Toggle all Characters in a String492
148Given string is interleaving of two other strings or not489
149Count Minimum Steps to Get the given Array485
150Merge sort better than quick sort for linked lists483
151Number of Smaller Elements on Right Side482
152Check length of a String is Equal to the Number Appended at its Last481
153Find Pair with Given Difference480
154Check if all Rows of a Matrix are Circular Rotations of Each Other479
155Find nth node of the Linked list from the end476
156Longest Common Prefix using Divide and Conquer475
157Print all interleavings of given two strings467
158Find a Fixed Point in a Given Array467
159Sort 0s 1s and 2s in an Array466
160Compare Two Version Numbers465
161Reverse words in a given string462
162Find the Subarray of given length with Least Average461
163Reorder Array Using Given Indexes459
164Print Reverse of a string (Recursion)459
165Merge two sorted linked lists such that merged list is in reverse order459
166Split linked list using alternate nodes458
167Median of Two Sorted Arrays LeetCode Solution457
168Print string of odd length in ‘X’ format445
169Find K Length Subarray of Maximum Average440
170Print all Palindromic Partitions of a String440
171Swap Kth Node from beginning with Kth Node from End440
172Find Element Using Binary Search in Sorted Array439
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions426
175Flatten a multilevel linked list424
176Shortest Superstring Problem421
177Maximum Length of Chain Pairs420
178Check if String Follows Order of Characters by a Pattern or not419
179Sorting a K Sorted Array415
180Sort a String According to Another String412
181Longest Span with same Sum in two Binary Arrays II404
182Reverse a Linked List in groups402
183Find a Sorted Subsequence of size 3401
184Recursively print all the sentences that can be formed from list of word lists398
185Program to add two binary digits397
186Find the two Numbers with Odd Occurrences in an Unsorted Array394
187Longest Common Prefix Using Binary Search II392
188Reverse a Singly Linked List (Iterative/Non-Recursive)392
189Kth Non-repeating Character388
190Caesar Cipher388
191Rearrange a linked list in Zig-Zag386
192Check if String can Become Empty by Recursively Deleting given Substring384
193Longest Common Prefix Word by Word Matching381
194Rotate Image by 90 degrees380
195Pancake Sorting380
196Permutations of a Given String Using STL373
197Perfect Reversible String372
198Increasing Subsequence of Length three with Maximum Product368
199Merging Two Sorted Arrays368
200Sort a linked list with 0s, 1s and 2s366
201Find the point where a monotonically increasing function becomes positive first time366
202Find First non-repeating character in a string366
2031`s and 2`s complement of binary number366
204Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes363
205Four Elements that Sum to Given362
206List items containing all characters of a given word360
207Delete N nodes after M357
208Longest Common Prefix using Character by Character Matching353
209Count Number of Occurrences in a Sorted Array351
210Palindrome string (number)350
211Split a string347
212Minimum Characters to be Removed to Make a Binary String Alternate343
213Check if a Linked list of Strings form a Palindrome341
214Recursive Implementation of atoi()341
215Print All Distinct Elements of the Array339
216Sorting the array of strings337
217Even Substring Count336
218Maximum occurring character in a string335
219Convert a String that is Repetition of a Substring of Length K335
220Find the first Repeating Number in a Given Array333
221Reverse a singly linked list recursively333
222Valid Parentheses LeetCode Solution333
223Print Shortest Path to Print a String on Screen330
224Can we reverse a linked list in less than O(n) time ?329
225Convert string1 to string2 in one edit327
226Binary Tree to Doubly linked list327
227Reverse a String using Stack326
228wildcard character matching325
229Nth Character in Concatenated Decimal String323
230Sort Elements by Frequency II323
231Maximum Subarray Leetcode Solution322
232Lower Case To Upper Case318
233Count the number of words318
234Merge Two Sorted Arrays316
235Split Four Distinct Strings316
236Find the Lost Element From a Duplicated Array314
237Find middle of the Linked List312
238Longest Common Subsequence with Permutations309
239Count the Pairs at Same Distance as in English Alphabets307
240Matrix Chain Multiplication using Dynamic Programming306
241Next Greater Element in an Array303
242Palindrome Permutation298
243Roman to Integer Leetcode Solution292
244Find Nth Node291
245Searching a node in a Binary Search Tree290
246Find All Pairs With a Given Difference290
247Triplet from three linked lists with given sum286
248Delete a Tree286
249Reverse a String283
250String(represents an integer) to value283
251Word Search Leetcode Solution283
252Reverse Bits282
253Print all Possible Ways to Break a String in Bracket Form281
254Delete a node under given conditions280
255Binary Tree278
256Change Gender of a given String278
257How to Efficiently Implement k Stacks in a Single Array?276
258Sort an array of strings276
259First non Repeating Element274
260Count Pairs With Given Sum274
261Toeplitz Matrix272
262Number of sub-strings which recursively add up to 9272
263Meeting Rooms II LeetCode Solution271
264Longest Common Extension271
265Remove middle points in a linked list of line segments270
266Move all negative elements to one side of array270
267Repeated Substring Pattern269
268N queen problem269
269Remove spaces from a string266
270Longest Palindromic Substring LeetCode Solution266
271Shuffle a given Array264
272Min Stack262
273Number of Islands LeetCode Solution260
274Cuckoo sequence program259
275Dijkstra Algorithm258
276House Robber Leetcode Solution257
277Max stack256
278Find, second, frequent, character256
279Most Frequent Element in an Array254
280Minimize the maximum difference between the heights254
281Fibonacci numbers253
282Clone a linked list with next and random pointer (Hashing)252
283Search Insert Position Leetcode Solution251
284Expression Evaluation250
285Subset Leetcode249
286Sort linked which is sorted on absolute values249
287Valid Palindrome Leetcode Solution248
288Sudoku Solver248
289Plus One Leetcode Solution247
290Word Search246
291Number Of 1 bits246
292KMP Algorithm246
293Evaluation of Postfix Expression246
294Combination Sum Leetcode Solution245
295How to Delete a Linked List244
296Reverse words in a string244
297Min Stack Leetcode Solution244
298Backspace String Compare241
299Set Matrix Zeroes238
300Rabin Karp Algorithm237
301Merge Sorted Arrays Leetcode Solution236
302Sqrt(x) Leetcode Solution236
303Pair of Positive Negative Values in an Array235
304Reversing a Queue235
305Common elements in all rows of a given matrix233
306Subarray with 0 sum233
307Tower Of Hanoi233
308Product of array except self230
309Integer to Roman Leetcode Solution230
310Contains Duplicate II Leetcode Solution230
311Delete middle element of a stack230
312Combination Sum229
313String Compression228
314Intersection of Two Arrays II Leetcode Solution228
315Pascal Triangle Leetcode227
316Reverse individual words226
317Minimum swaps required to bring all elements less than or equal to k together225
318Count subarrays with equal number of 1’s and 0’s225
319Bellman Ford Algorithm224
320Construct Binary Tree from Given Inorder and Preorder Traversals224
321Implementation of Deque using Doubly Linked List224
322Add Binary Leetcode Solution224
323Count of index pairs with equal elements in an array224
324Sliding Window Technique223
325Find Top K (or Most Frequent) Numbers in a Stream223
326Single Number Leetcode Solution223
327Minimum Value to Get Positive Step by Step Sum Leetcode Solution222
328Segregate even and odd numbers221
329Arithmetic Expression Evaluation221
330Sort elements by frequency221
331Contains Duplicate220
332Palindrome Linked List Leetcode Solution220
333Second Most Repeated Word in a Sequence220
334Count Odd Numbers in an Interval Range Leetcode Solution219
335Pow(x, n) Leetcode Solution219
336Page Replacement Algorithms in Operating Systems219
337Find sum of non-repeating elements (distinct) elements in an array219
338Postfix to Infix Conversion218
339Group Words With Same Set of Characters218
340Next Permutation217
341Kruskal Algorithm217
342Design a stack that supports getMin() in O(1) time and O(1) extra space217
343Maximum Number of Balloons Leetcode Solution217
344Smallest Subarray with k Distinct Numbers216
345Sum of minimum and maximum elements of all subarrays of size k215
346Third Maximum Number Leetcode Solution215
347Scramble String215
348Longest Common Prefix Leetcode Solution214
349Longest Substring Without Repeating Characters LeetCode Solution214
350Maximum Subarray214
351Permutations Leetcode Solution214
352Convex Hull Algorithm214
353Find Lucky Integer in an Array Leetcode Solution213
354Top K Frequent Words213
355K-th Smallest Element in a Sorted Matrix213
356Minimum operation to make all elements equal in array212
357Find the Town Judge Leetcode Solution212
358Sorting array using Stacks211
359Find Numbers with Even Number of Digits Leetcode Solution211
360Evaluate Division210
361Count subarrays having total distinct elements same as original array210
362Special Number210
363Majority Element Leetcode Solution210
364Given two unsorted arrays find all pairs whose sum is x209
365First element occurring k times in an array209
366Number of Good Pairs Leetcode Solution209
367Spiral Matrix LeetCode Solution209
368Swap Nodes in Pairs Leetcode Solutions208
369Merge Two Sorted Lists Leetcode Solutions207
370Minimum Path Sum207
371Prefix to Infix Conversion207
372Huffman Coding207
373Check if two arrays are equal or not206
374Reverse a Number Using Stack206
375Best Time to Buy and Sell Stock  II Leetcode Solution206
376Count Primes Leetcode Solutions206
377Single Number206
378Missing Number Leetcode Solution206
379Pascal’s Triangle II Leetcode Solution206
380Reversing the First K elements of a Queue205
381Minimum Steps to reach target by a Knight205
382Search in Rotated Sorted Array Leetcode Solution205
383Minimum Absolute Difference Leetcode Solution204
384Group Anagrams204
385Find duplicates in a given array when elements are not limited to a range204
386Sort Array by Increasing Frequency Leetcode Solution204
387House Robber II Leetcode Solution204
388Maximal Square204
389Power of Two Leetcode Solution203
390Find All Numbers Disappeared in an Array Leetcode Solution202
391Top K Frequent Elements202
392Convert String To Int202
393Maximum Distance Between two Occurrences of Same Element in Array202
394Matrix Diagonal Sum Leetcode Solution202
395Palindrome Substring Queries201
396Unique Paths Leetcode Solution201
397Maximum possible difference of two subsets of an array201
398Expression Contains Redundant Bracket or Not201
399Running Sum of 1d Array Leetcode Solution201
400Fizz Buzz Leetcode201
401Check if Array Contains Contiguous Integers With Duplicates Allowed201
402Sorting using trivial hash function201
403Find the first repeating element in an array of integers201
404Unique Paths200
405Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
406Zigzag Conversion200
407Subarray Sum Equals k200
408Find Minimum In Rotated Sorted Array200
409How to Implement Stack Using Priority Queue or Heap?200
410Sort Integers by The Number of 1 Bit Leetcode Solution200
411Smallest Element Repeated Exactly K Times199
412How Many Numbers Are Smaller Than the Current Number Leetcode Solution199
413Cumulative Frequency of Count of Each Element in an Unsorted Array199
414Range Sum Query 2D – Immutable Leetcode Solution199
415Max Consecutive Ones Leetcode Solution199
416Find the Closest Palindrome number199
417Subset sum problem198
418Leetcode Permutations198
419Happy Number Leetcode Solution198
420Find Number of Employees Under every Employee198
421Coin Change 2 Leetcode Solution198
422Length of the largest subarray with contiguous elements198
423Decode String197
424Subarray Sum Equals K LeetCode Solution197
425Find Winner on a Tic Tac Toe Game Leetcode Solution197
426Letter Case Permutation197
427Print All Distinct Elements of a Given Integer Array197
428Difference between highest and least frequencies in an array197
429Reverse Integer196
430Nth Catalan Number196
431Remove Duplicates from Sorted Array Leetcode Solution196
432Monotonic Array LeetCode Solution196
433Best Time to Buy and Sell Stock III Leetcode Solution196
434Sort a stack using recursion196
435Implement Stack and Queue using Deque196
436LRU Cache Implementation195
437Fibonacci Number LeetCode Solution195
438Find top three repeated in array195
439Sum of Subarray Ranges Leetcode Solution194
440Count Substrings with equal number of 0s, 1s and 2s194
441Capacity To Ship Packages Within D Days Leetcode Solution194
442Generate a String With Characters That Have Odd Counts Leetcode Solution194
443Reverse Vowels of a String Leetcode Solution194
444Reverse a Stack Using Recursion194
445Subarrays with distinct elements194
446Find The Duplicate Number193
447Merge Two Sorted Linked Lists193
448Check If N and Its Double Exist Leetcode Solution193
449Reverse Words in a String III LeetCode Solution193
450Print all subarrays with 0 sum193
451Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
452Maximum Depth of Binary Tree Leetcode Solution193
453Find Median from data Stream193
454Shuffle the Array Leetcode Solution192
455Trapping Rain Water Leetcode Solution192
456Prim’s Algorithm192
457Integer to English words192
458Bipartite Graph192
459Delete a Node from linked list without head pointer192
460Target Sum191
461Find the Difference Leetcode Solution191
462Find the Duplicate Element191
463Priority Queue Using Singly Linked List190
464Excel Sheet Column Number Leetcode Solution190
465Longest Common Subsequence190
466Sorting a Queue without Extra Space190
467Find all pairs (a, b) in an array such that a % b = k190
468Kth largest element in an Array Leetcode Solutions190
469Iterative Tower of Hanoi190
470Count and Say190
471Find Common Characters Leetcode Solution190
472Edit Distance190
473Balanced Binary Tree Leetcode Solution190
474Reverse a String190
475Text Justification LeetCode Solution189
476Fizz Buzz189
477Longest Common Prefix using Trie189
478Concatenation of Array LeetCode Solution189
479Kids With the Greatest Number of Candies Leetcode Solution188
480Minimum Moves to Equal Array Elements Leetcode Solution188
481Next Greater Element I Leetcode Solution188
482Reverse a linked list188
483Degree of an array188
484Count pairs from two linked lists whose sum is equal to a given value188
485Remove Minimum Number of Elements Such That no Common Element Exist in both Array188
486The K Weakest Rows in a Matrix Leetcode Solution188
487Design Parking System Leetcode Solution187
488Floyd Warshall Algorithm187
489Find elements which are present in first array and not in second187
490Kth Largest Element in a Stream Leetcode Solution187
491Word Ladder LeetCode Solution187
492Number of Steps to Reduce a Number to Zero Leetcode Solution187
493Find First and Last Position of Element in Sorted Array Leetcode Solution187
494Find four elements that sum to a given value (Hashmap)186
495Prefix to Postfix Conversion186
496Merge Overlapping Intervals186
497Find subarray with given sum (Handles Negative Numbers)186
498Longest subarray not having more than K distinct elements186
499Shortest Palindrome186
500Slowest Key Leetcode Solution186
501Valid Parenthesis String186
502Top View of Binary Tree186
503Zigzag Conversion LeetCode Solution185
504MiniMax Algorithm185
505Count and Say Leetcode Solution185
506The Stock Span Problem185
507Multiply Strings Leetcode Solution185
508Flood Fill LeetCode185
509Find N Unique Integers Sum up to Zero Leetcode Solution185
510Priority Queue in C++185
511Find Index of Closing Bracket for a Given Opening Bracket in an Expression184
512Move Zeroes LeetCode Solution184
513Substring With Concatenation Of All Words184
514Max Area of Island184
515Jump Game Leetcode Solution184
516Postfix to Prefix Conversion184
517Convert array into Zig-Zag fashion184
518Length of Last Word Leetcode Solution184
519Find any one of the multiple repeating elements in read only array184
521Mobile Numeric Keypad Problem183
522Find distinct elements common to all rows of a matrix183
523Check if a given array contains duplicate elements within k distance from each other183
524Shuffle String Leetcode Solution183
525Pair with given product183
526Peak Index in a Mountain Array183
527Next Greater Frequency Element183
528Longest Common Prefix using Sorting182
529Intersection of Two Arrays182
530Implement a stack using single queue182
531Count number of triplets with product equal to given number182
532Iterative Inorder Traversal of a Binary Tree182
533Excel Sheet Column Title Leetcode Solution181
534Largest Sum Contiguous Subarray181
535Implement Stack using Queues181
536Delete Node in a Linked List Leetcode Solution181
537Last Stone Weight181
538Find missing elements of a range181
539Relative Sort Array Leetcode Solution181
540Contiguous Array Leetcode181
541Koko Eating Bananas Leetcode Solution180
542Rearrange a binary string as alternate x and y occurrences180
543Smallest Subarray With all Occurrences of a Most Frequent Element180
544Valid Sudoku179
545Distribute Candies to People Leetcode Solution179
546N-th Tribonacci Number Leetcode Solution179
547Convert a normal BST to Balanced BST179
548Linked List Cycle II LeetCode Solution179
549Best Time to Buy and Sell Stock179
550Minimum Bracket Reversals179
551Is Subsequence Leetcode Solution179
552Change the Array into Permutation of Numbers From 1 to N179
553Implementation of Deque using circular array178
554Group Multiple Occurrence of Array Elements Ordered by first Occurrence178
555Container with Most Water178
556Jewels and Stones Leetcode Solution178
557K-th Distinct Element in an Array178
558Minimum Operations to convert X to Y178
559Isomorphic Strings Leetcode Solution178
560Check for Balanced Parentheses in an Expression177
561Arrange given numbers to form the biggest number177
562Shuffle an Array177
563First negative integer in every window of size k177
564Gold Mine Problem177
565Assign Cookies Leetcode Solution177
566Valid Anagrams177
567Unique Binary Search Trees177
568Build Array From Permutation Leetcode Solution177
569Sum of Left Leaves Leetcode Solutions177
570Integer to Roman177
571Minimum Knight Moves LeetCode Solution177
572Convert Sorted Array to Binary Search Tree Leetcode Solution177
573Find Words That Can Be Formed by Characters Leetcode Solution177
574Island Perimeter Leetcode Solution177
575Largest Perimeter Triangle Leetcode Solution177
576Remove Linked List Elements Leetcode Solution176
577Minimum Delete Operations to make all Elements of Array Same176
578Combinations Leetcode Solution176
579Hamming Distance176
580Trapping Rain Water LeetCode Solution176
58101 Matrix LeetCode Solution176
582Summary Ranges Leetcode Solution175
583Find the smallest positive integer value that cannot be represented as sum of any subset of a given array175
584LRU Cache LeetCode Solution175
585Rotate List Leetcode Solution175
586Count all subsequences having product less than K175
587The Knapsack Problem175
5883Sum Closest LeetCode Solution175
589Maximum sum rectangle in a 2D matrix175
590Decode Ways174
591Count the number of nodes at given level in a tree using BFS174
592Shortest Path in a Grid with Obstacles Elimination LeetCode Solution174
593Maximum Distance in Array173
594Distance Between Bus Stops Leetcode Solution173
595Insert Interval Leetcode Solution173
596Maximum Number of Chocolates to be Distributed Equally Among k Students173
597Maximum path sum in a triangle173
598Minimum number of distinct elements after removing m items173
599Find minimum difference between any two elements173
600Bubble sort using two Stacks172
601Same Tree LeetCode Solution172
602Minimum insertions to form a palindrome with permutations allowed172
603Minimum number of subsets with distinct elements172
604Replace Elements with Greatest Element on Right Side Leetcode Solution171
605Find if an Expression has Duplicate Parenthesis or Not171
606Painting Fence Algorithm171
607Sort Characters By Frequency LeetCode Solution171
608Frog Jump Leetcode Solution171
609Rotate Image LeetCode Solution171
610Applications of Breadth First Search and Depth First Search171
611Permutation in String Leetcode Solution171
612Reverse a stack without using extra space in O(n)171
613Sieve of Eratosthenes171
614How to check if two given sets are disjoint?171
615Stone Game LeetCode171
616Find the Duplicate Number LeetCode Solution170
617K Empty Slots LeetCode170
618Smallest Good Base170
619Word Pattern170
620Longest Increasing Subsequence170
621Remove All Occurrences of a Substring LeetCode Solution170
622Sort Array By Parity LeetCode Solution170
623XOR Operation in an Array Leetcode Solution170
624Minimum Cost to Hire K Workers170
625Word Wrap Problem170
626Best Time to Buy and Sell Stock LeetCode Solution169
627License Key Formatting Leetcode Solution169
628Defanging an IP Address Leetcode Solution169
629Maximum Consecutive Numbers Present in an Array169
630Minimum Depth of Binary Tree Leetcode Solution169
631Distance of nearest cell having 1 in a binary matrix169
632Number of Provinces Leetcode Solution169
633Non-overlapping sum of two sets169
634Tracking current Maximum Element in a Stack169
635Isomorphic Strings169
636House Robber169
637Printing brackets in Matrix Chain Multiplication Problem169
638Longest Substring with At Most K Distinct Characters LeetCode Solution168
639Optimal Account Balancing LeetCode Solution168
640Segregate 0s and 1s in an Array168
641Valid Palindrome II Leetcode Solution168
642Coin Change Problem168
643Find Sum of all unique sub-array sum for a given array168
644Wiggle Sort168
645Check If It Is a Straight Line Leetcode Solution167
646Find Maximum Level sum in Binary Tree167
647Count Good Nodes in Binary Tree Leetcode Solution167
648How to Create Mergable Stack?167
649Iterative Method to find Height of Binary Tree167
650Maximum difference between first and last indexes of an element in array167
651Queries for counts of array elements with values in given range167
652Moving Average from Data Stream Leetcode Solution167
653Sum of All Odd Length Subarrays Leetcode Solution167
654Path With Maximum Minimum Value LeetCode Solution167
655Binary Tree Zigzag Level Order Traversal LeetCode Solution167
656Kth Missing Positive Number Leetcode Solution167
657Strobogrammatic Number LeetCode Solution166
658Employee Free Time LeetCode Solution166
659GCD Of Two Numbers166
660Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions166
661Maximum Number of Occurrences of a Substring Leetcode Solution166
662Best Time to Buy and Sell Stock with Cooldown Leetcode Solution166
663Merge Two Balanced Binary Search Trees166
664Find the Distance Value Between Two Arrays Leetcode Solution166
665Reorganize String166
666Valid Palindrome165
667Letter Combinations of a Phone Number165
668Longest Substring with At Least K Repeating Characters LeetCode Solution165
669Flipping an Image LeetCode Solution165
670Reducing Dishes LeetCode Solution165
671Delete consecutive same words in a sequence165
672Find Largest d in Array such that a + b + c = d165
673Convert an array to reduced form165
674Print the Fibonacci numbers in reverse order165
675Remove Invalid Parentheses Leetcode Solution164
676Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest164
677K Empty Slots164
678Maximum Number of Coins You Can Get Leetcode Solution164
679Factorial Trailing Zeroes Leetcode Solution164
680Partition Labels LeetCode Solution164
681Find pairs with given sum such that elements of pair are in different rows164
682Check If Two String Arrays are Equivalent Leetcode Solution164
683Longest Increasing Path in a Matrix LeetCode Solution163
684Permutation Sequence LeetCode Solution163
685Recover Binary Search Tree163
686Populating Next Right Pointers in Each Node163
687Valid Perfect Square Leetcode Solution163
688Inorder Successor of a node in Binary Tree163
689Number of Dice Rolls With Target Sum LeetCode Solution163
690Power of Four Leetcode Solution163
691Form minimum number from given sequence163
692Edit Distance LeetCode Solution163
693Delete Nth node from the end of the given linked list163
694Partition Array Into Three Parts With Equal Sum Leetcode Solution163
695Increasing Decreasing String Leetcode Solution163
696Lucky Numbers in a Matrix Leetcode Solution163
697To Lower Case Leetcode Solution163
698BFS vs DFS for Binary Tree163
699Unique Paths II Leetcode Solution162
700Check if a queue can be sorted into another queue using a stack162
701Merge Two Binary Trees LeetCode Solution162
702Ugly Number Leetcode Solution162
703String to Integer (atoi) LeetCode Solution162
704Find the Smallest Divisor given a Threshold Leetcode Solution162
705Dynamic Programming Basics162
706Maximum Product of Two Elements in an Array Leetcode Solution162
707Construct BST from given Preorder Traversal162
708Reversing a Queue using Recursion162
709Sort Array by Increasing Frequency Leetcode Solution162
710Reverse Only Letters LeetCode Solution161
711Convert a Number to Hexadecimal Leetcode Solution161
712Find Leaves of Binary Tree LeetCode Solution161
713Find whether an array is subset of another array161
714Binary Tree zigzag level order Traversal161
715Subset Sum Leetcode161
716Robot Room Cleaner Leetcode Solution161
717Reservoir Sampling161
718Majority Element II Leetcode Solution160
719Keyboard Row Leetcode Solution160
720Binomial Coefficient160
721Perform String Shifts Leetcode160
722Add and Search Word – Data structure design LeetCode160
723Finding K closest element160
724Restore IP Addresses Leetcode Solution160
725Decompress Run-Length Encoded List Leetcode Solution160
726Find the node with minimum value in a Binary Search Tree159
727Bulb Switcher LeetCode Solution159
728Check if Two Expressions With Brackets are Same159
729Find the largest multiple of 3159
730Numbers with prime frequencies greater than or equal to k159
731Race Car LeetCode Solution159
732Morris Traversal158
733Maximum Product of Three Numbers LeetCode Solution158
734Merge K Sorted Linked Lists158
735Minimum Cost For Tickets Leetcode Solution158
736Word Pattern LeetCode Solution158
737Hamming Distance Leetcode Solution158
738Rank Transform of an Array Leetcode Solution158
739Number of Islands II LeetCode Solution158
740Generate all possible sorted arrays from alternate elements of two given sorted arrays158
741Find Pair with Greatest Product in Array158
742Minimum Height Trees158
743Minimum Distance Between BST Nodes Leetcode Solution158
744Sum of f(a[i], a[j]) over all pairs in an array of n integers158
745Minimum time required to rot all oranges158
746Maximum 69 Number Leetcode Solution158
747Maximum Depth of N-ary Tree Leetcode Solution157
748Longest Span with same Sum in two Binary arrays157
749Snakes and Ladders LeetCode Solution157
750Find unique character in a string157
751Invert Binary Tree LeetCode Solution157
752Sorted Linked List to Balanced BST157
753Tiling Problem157
754First Unique Character in a String LeetCode Solution157
755Student Attendance Record I Leetcode Solution157
756Find if Path Exists in Graph Leetcode Solution157
757String Compression LeetCode Solution157
758Best Meeting Point LeetCode Solution157
759Non-decreasing Array LeetCode Solution157
760Diagonal Traversal of Binary Tree157
761Queue based approach for first non-repeating character in a stream157
762Find Maximum Depth of Nested Parenthesis in a String157
763Binary Tree Maximum Path Sum LeetCode Solution156
764Remove brackets from an algebraic string containing + and – operators156
765Remove Nth Node From End of List Leetcode Solution156
766Total Numbers With no Repeated Digits in a Range156
767Minimize Maximum Pair Sum in Array LeetCode Solution156
768Largest Rectangle in Histogram LeetCode Solution156
769Find All Duplicates in an Array LeetCode Solution156
770Check If Array Pairs Are Divisible by k LeetCode Solution156
771Kth ancestor of a node in binary tree156
772Special Array With X Elements Greater Than or Equal X Leetcode Solution156
773Largest subarray with equal number of 0s and 1s156
774Stack Permutations (Check if an array is stack permutation of other)156
775Symmetric Tree Leetcode Solution156
776Elements to be added so that all elements of a range are present in array156
777Evaluate Reverse Polish Notation LeetCode Solution155
778Final Prices With a Special Discount in a Shop Leetcode Solution155
779Largest rectangular sub-matrix whose sum is 0155
780Jump Game155
781Linked List Cycle155
782Maximum Length of a Concatenated String with Unique Characters Leetcode Solution155
783Search a 2D Matrix II Leetcode Solution155
784Find Median from Data Stream LeetCode Solution155
785Partition to K Equal Sum Subsets Leetcode Solution155
786Base 7 Leetcode Solution154
787Interval Tree154
788Count items common to both the lists but with different prices154
789Deletion in a Binary Tree154
790Search in a Binary Search Tree Leetcode Solution154
791Maximum Difference Between Increasing Elements LeetCode Solution154
792Valid Number154
793Number of NGEs to the Right154
794Sort an array according to the order defined by another array154
795Program for Bridge and Torch problem154
796Split a String in Balanced Strings Leetcode Solution154
797Growable array based stack154
798Check for Palindrome after every character replacement Query154
799Transpose Graph154
800Print a Binary Tree in Vertical Order154
801k-th missing element in increasing sequence which is not present in a given sequence154
802N-Queens LeetCode Solution154
803Count quadruples from four sorted arrays whose sum is equal to a given value x153
804Minimum Time Visiting All Points Leetcode Solution153
805Get Maximum in Generated Array Leetcode Solution153
806Nearest Exit from Entrance in Maze LeetCode Solution153
807String comparison containing wildcards153
808Minimum Jumps to Reach Home LeetCode Solution153
809Last Stone Weight II LeetCode Solution153
810Circular Queue153
811Minimum number of jumps to reach end153
812One Edit Distance LeetCode Solution153
813A Space Optimized DP solution for 0-1 Knapsack Problem152
814Maximum size subarray sum equals k152
815Number Complement Leetcode Solution152
816Relative Ranks Leetcode Solution152
817Crawler Log Folder Leetcode Solution152
818Reorder Data in Log Files LeetCode Solution152
819Course Schedule II – LeetCode152
820Longest Subarray Having Count of 1s One More than Count of 0s152
821Merge Sorted Array LeetCode Solution152
822Remove Duplicates from Sorted List LeetCode Solution152
823Priority Queue using doubly linked list152
824Nested List Weight Sum II LeetCode Solution152
825Iterative Preorder Traversal152
826Remove Duplicates from Sorted List II152
827Maximum Profit in Job Scheduling Leetcode Solution152
828Subarray Product Less Than K LeetCode Solution152
829Minimum swaps to make sequences increasing152
830Find all triplets with zero sum152
831Spiral Matrix II Leetcode Solution151
832Form Minimum Number From Given Sequence151
833Sort Array By Parity II Leetcode Solution151
834Sort Colors150
835Sum of nearest smaller and greater number150
836Minimum Number of Taps to Open to Water a Garden LeetCode Solution150
837Alien Dictionary LeetCode Solution150
838Path with maximum average value150
839Top K Frequent Words LeetCode Solution150
840Given an Array of Pairs Find all Symmetric Pairs in it150
841Check if a given array can represent Preorder Traversal of Binary Search Tree150
842Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution150
843Brick Wall LeetCode Solution150
844Find the subarray with least average150
845Insert into a Binary Search Tree Leetcode Solution150
846Regular Expression Matching150
847Maximum Nesting Depth of the Parentheses Leetcode Solution150
848Valid Parentheses Leetcode Solution150
849Can Place Flowers LeetCode Solution150
850Convert BST to Min Heap150
851Subset with sum divisible by m150
852Find Maximum Sum Possible Equal Sum of Three Stacks149
853Matrix Chain Multiplication149
854Binary Search Tree Search and Insertion149
855Clone Graph LeetCode Solution149
856Brightest Position on Street LeetCode Solution149
857Check whether a given Binary Tree is Complete or not149
858Tree Traversal (Preorder, Inorder & Postorder)149
859Find All Possible Recipes from Given Supplies LeetCode Solution149
860Balanced Expression with Replacement149
861Permutation Coefficient149
862Identify and Mark Unmatched Parenthesis in an Expression149
863Friends Pairing Problem149
864Subsequence of Size K With the Largest Even Sum LeetCode Solution149
865Count Negative Numbers in a Sorted Matrix LeetCode Solution149
866Level order Traversal in Spiral Form149
867Guess Number Higher or Lower LeetCode Solution149
868Design a Stack With Increment Operation Leetcode Solution149
869Minimum Sum Path in a Triangle149
870Partition List Leetcode Solution149
871Count Distinct Elements in Every Window of Size K149
872An Interesting Method to generate Binary Numbers from 1 to n148
873Missing Element in Sorted Array LeetCode Solution148
874Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution148
875Range LCM Queries148
876LCS (Longest Common Subsequence) of three strings148
877Diagonal Traverse LeetCode Solution148
878Minimum Swaps to Make Strings Equal Leetcode Solution148
879Sorted Array to Balanced BST148
880Sequences of given length where every element is more than or equal to twice of previous148
881Find the Only Repetitive Element Between 1 to N-1148
882Check if stack elements are pairwise consecutive148
883Diagonal Traversal LeetCode Solution147
884Distinct adjacent elements in an array147
885Water Bottles Leetcode Solution147
886Repeated Substring Pattern LeetCode Solution147
887Convert Sorted List to Binary Search Tree147
888Number of Days Between Two Dates LeetCode Solution147
889Design Browser History LeetCode Solution147
890Insert Delete GetRandom147
891K’th Largest Element in BST when modification to BST is not allowed147
892Union and Intersection of two Linked Lists147
893Destination City Leetcode Solution147
894Time Based Key-Value Store LeetCode Solution147
895Three way partitioning of an array around a given range147
896Delete And Earn146
897Check if an Array is Stack Sortable146
898Rearrange an Array Such that arr[i] is equal to i146
899Find Common Characters Leetcode Solution146
900Special Positions in a Binary Matrix Leetcode Solution146
901Daily Temperatures Leetcode Solution146
902Spiral Matrix III LeetCode Solution146
903Shortest Word Distance Leetcode Solution146
904Maximum Score After Splitting a String Leetcode Solution146
905Count ways to reach the nth stair using step 1, 2 or 3146
906Robot Bounded In Circle LeetCode Solution146
907Minimum sum of multiplications of n numbers146
908GCDs of given index ranges in an array146
909Lemonade Change Leetcode Solution146
910BFS for Disconnected Graph146
911Guess Number Higher or Lower II146
912Construct Complete Binary Tree from its Linked List Representation145
913Find distance between two nodes of a Binary Tree145
914Check if the given array can represent Level Order Traversal of Binary Search Tree145
915Least Number of Unique Integers after K Removals Leetcode Solution145
916Number of Distinct Islands Leetcode Solution145
917Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i145
918Range sum queries without updates145
919Queue using Stacks145
920Construct the Rectangle Leetcode Solution144
921Rearrange Spaces Between Words Leetcode Solution144
922Print Fibonacci sequence using 2 variables144
923Construct BST from its given Level Order Traversal144
924Merge Two Sorted Lists Leetcode144
925Set Matrix Zeroes Leetcode Solution144
926Find all permuted rows of a given row in a matrix144
927Palindrome Partitioning Leetcode Solution144
928Alien Dictionary144
929Vertical sum in a given binary tree144
931Minimum Height Trees LeetCode Solution143
932Maximum Subarray Sum Excluding Certain Elements143
933Stone Game II Leetcode143
934Difference Array | Range update query in O(1)143
935Count Subarrays with Same Even and Odd Elements143
936Queries for GCD of all numbers of an array except elements in a given range143
937Create Maximum Number143
938Averages of Levels in Binary Tree143
939Check if any two intervals overlap among a given set of intervals143
9403 Sum143
941A program to check if a binary tree is BST or not143
942Iterative Postorder Traversal Using Two Stacks143
943Maximum Frequency Stack Leetcode Solution143
944Split Array Into Consecutive Subsequences143
945Binary Tree Longest Consecutive Sequence LeetCode Solution143
946Lexicographical Numbers Leetcode Solution143
947All Unique Triplets that Sum up to a Given Value142
948Number of Equivalent Domino Pairs Leetcode Solution142
949Infix to Postfix142
950Strongly Connected Component142
951Trim a Binary Search Tree142
952Analyze User Website Visit Pattern LeetCode Solution142
953Largest area rectangular sub-matrix with equal number of 1’s and 0’s142
954Remove Duplicates from Sorted List II LeetCode Solution142
955Longest Palindromic Subsequence142
956Dividing Array into Pairs With Sum Divisible by K141
957Count Submatrices With All Ones LeetCode Solution141
958Sliding Window Maximum141
959Can Make Arithmetic Progression From Sequence Leetcode Solution141
960Merging Intervals141
961Find postorder traversal of BST from preorder traversal141
962Unique Paths II141
963Median of Two Sorted Arrays141
964Three Consecutive Odds Leetcode Solution141
965Shuffle 2n integers as without using extra space141
966My Calendar I LeetCode Solution141
967Minesweeper LeetCode Solution141
968Binary array after M range toggle operations141
969Collect maximum points in a grid using two traversals141
970Maximize Sum of Array after K Negations Leetcode Solution140
971Kth Smallest Element in a BST Leetcode Solution140
972Length of Longest Fibonacci Subsequence140
973Count pair with Given Sum140
974Word Break140
975Count Primes in Ranges140
976Sign of the Product of an Array LeetCode Solution140
977Maximum Product Subarray140
978Pattern Occurrences using Stack140
979Height of a generic tree from parent array140
980Count subarrays where second highest lie before highest140
981Intersection of Two Linked Lists LeetCode Solution140
982The Painter’s Partition Problem140
983Reverse Nodes in K-Group140
984K Closest Points to Origin Leetcode Solution140
985Symmetric Tree139
986Longest Nice Substring LeetCode Solution139
987Binary Search Tree Delete Operation139
988Find Maximum of Minimum for Every Window Size in a Given Array139
989Level Order Traversal of Binary Tree139
990Palindrome Partitioning139
991Product of Array Except Self LeetCode Solution139
992Climbing stairs139
993Find the Difference Leetcode Solution139
994Newman-Conway Sequence139
995Friends Of Appropriate Ages LeetCode Solution139
996Asteroid Collision LeetCode Solution138
997Valid Boomerang Leetcode Solution138
998Find number of pairs in an array such that their XOR is 0138
999Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution138
1000Largest divisible pairs subset138
1001Number Of Longest Increasing Subsequence138
1002Largest Number Leetcode Solution138
1003Boundary Traversal of binary tree138
1004Largest Substring Between Two Equal Characters Leetcode Solution138
1005Minimum Index Sum of Two Lists138
1006Segment Tree138
1007Merge Sort137
1008Number of palindromic paths in a matrix137
1009Maximum subsequence sum such that no three are consecutive137
1010Find Duplicate Subtrees137
1011Boolean Parenthesization Problem137
1012String Matching in an Array Leetcode Solution137
1013Double the first element and move zero to end137
1014Find the First Circular Tour that visits all the Petrol Pumps137
1015Compute nCr % p137
1016Maximum Product of Indexes of Next Greater on Left and Right137
1017Shortest Completing Word Leetcode Solution137
1018Breadth First Search (BFS) for a Graph137
1019Depth First Search (DFS) for a Graph137
1020Insertion in a Binary Tree137
1021Construct Binary Tree from given Parent Array representation137
1022Construction of Longest Increasing Subsequence (N log N)137
1023Graph Valid Tree LeetCode Solution137
1024The Maze III LeetCode Solution137
1025Maximum Length of Repeated Subarray137
1026Next Greater Element III LeetCode Solution136
1027Scramble String LeetCode Solution136
1028Maximum Number of Ways to Partition an Array LeetCode Solution136
1029Kill Process LeetCode Solution136
1030Partition Equal Subset Sum136
1031Serialize and Deserialize Binary Tree136
1032Decrypt String from Alphabet to Integer Mapping Leetcode Solution136
1033Build an Array With Stack Operations Leetcode Solution136
1034Morris Inorder Traversal136
1035Make The String Great Leetcode Solution136
1036Iterative Depth First Traversal of Graph136
1037Maximum weight transformation of a given string136
1038Level order traversal using two Queues136
1039First missing positive136
1040Binary Search Tree136
1041Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’136
1042Count minimum steps to get the given desired array136
1043Ugly Numbers135
1044Invalid Transactions LeetCode Solution135
1045Advantages of BST over Hash Table135
1046Design Hit Counter LeetCode Solution135
1047Rearrange array such that even positioned are greater than odd135
1048Maximum Sum of 3 Non-Overlapping Subarrays135
1049K maximum sums of overlapping contiguous sub-arrays135
1050Longest subsequence such that difference between adjacents is one135
1051Add two numbers135
1052Maximum difference between frequency of two elements such that element having greater frequency is also greater134
1053Path Sum II LeetCode Solution134
1054Employee Importance LeetCode Solution134
1055Available Captures for Rook Leetcode Solution134
1056Balanced Binary Tree134
1057Count pairs from two sorted arrays whose sum is equal to a given value x134
1058Custom Sort String Leetcode Solution134
1059Validate Binary Search Tree134
1060Super Ugly Number133
1061Maximum length subsequence with difference between adjacent elements as either 0 or 1133
1062Kth Smallest Element in a Sorted Matrix LeetCode Solution133
1063Ugly Number II LeetCode Solution133
1064Recover Binary Search Tree Leetcode Solution133
1065Implement Trie (Prefix Tree) Leetcode Solution133
1066Generate Parentheses Leetcode Solution133
1067Bitwise AND of Numbers Range LeetCode Solution133
1068Defanging an IP Address LeetCode Solution133
1069Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution132
1070Regular Expression Matching Regular Expression Matching LeetCode Solution132
1071Lowest Common Ancestor132
1072Largest BST Subtree LeetCode Solution132
1073Search in Sorted Rotated Array132
1074Populating Next Right Pointers in Each Node Leetcode Solution132
1075Remove Duplicates from Sorted Array II Leetcode Solution132
1076Find Peak Element132
1077Move all negative elements to end in order with extra space allowed132
1078Root to Leaf path with target sum Leetcode Solutions132
1079Remove Palindromic Subsequences Leetcode Solution131
1080Types of Binary Tree131
1081Number of Students Doing Homework at a Given Time Leetcode Solution131
1082Longest Bitonic Subsequence131
1083Rearrange array such that even index elements are smaller and odd index elements are greater131
1084Find a Peak Element II LeetCode Solution131
1085Number of Closed Islands Leetcode Solution131
1086Subarrays with K Different Integers Leetcode Solution131
1087Minimum Size Subarray Sum131
1088Binary Tree Right Side View LeetCode Solution131
1089Day of the Year Leetcode Solution130
1090Find Smallest Range Containing Elements from k Lists130
1091Minimum Absolute Difference in BST Leetcode Solution130
1092Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1093Combination Sum IV LeetCode Solution130
1094Number of siblings of a given Node in n-ary Tree130
1095Maximize Distance to Closest Person LeetCode Solution130
1096Find whether a subarray is in form of a mountain or not130
1097Clone a Binary Tree with Random Pointers130
1098Smallest Common Region Leetcode Solution130
1099Construct K Palindrome Strings LeetCode Solution129
1100Convert BST into a Min-Heap without using array129
1101Increasing Triplet Subsequence LeetCode Solution129
1102Consecutive Characters LeetCode Solution129
1103Find maximum difference between nearest left and right smaller elements129
1104Palindrome Permutation LeetCode Solution129
1105Count Largest Group Leetcode Solution129
1106Path Sum129
1107Find the minimum distance between two numbers129
1108Distinct Subsequences129
1109Level of Each node in a Tree from source node129
1110Serialize and Deserialize Binary Tree LeetCode Solution129
1111Binary Tree Data Structure129
1112Next Permutation Leetcode Solution129
1113Bottom View of a Binary Tree128
1114Print all triplets in sorted array that form AP128
1115Maximum Product Subarray128
1116Constant time range add operation on an array128
1117Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution128
1118Find Three Element From Different Three Arrays Such That a + b + c = sum128
1119Third Maximum Number Leetcode Solution128
1120Divisible Pairs Counting128
1121Valid Tic-Tac-Toe State LeetCode Solution128
1122Remove duplicates from sorted array128
1123Iterative method to find ancestors of a given binary tree128
1124Cutting a Rod128
1125Sum of Even Numbers After Queries127
1126Mean of Array After Removing Some Elements Leetcode Solution127
1127Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1128Delete Nodes and Return Forest Leetcode Solution127
1129Products of ranges in an array127
1130Prime Palindrome LeetCode Solution127
1131Print Next Greater Number of Q queries127
1132Reformat The String Leetcode Solution127
1133Find maximum length Snake sequence126
1134Search Insert Position126
1135Write Code to Determine if Two Trees are Identical126
1136Minimum sum of squares of character counts in a given string after removing k characters126
1137Cells with Odd Values in a Matrix LeetCode Solution126
1138Minimum Score Triangulation of Polygon Leetcode Solution126
1139Moser-de Bruijn Sequence126
1140Print Right View of a Binary Tree126
1141Thousand Separator Leetcode Solution126
1142Longest Increasing Consecutive Subsequence126
1143Palindromic Substrings Leetcode Solution125
1144Swap Nodes In Pairs125
1145Merge two BSTs with limited extra space125
1146Topological Sorting125
1147Maximum Product of Splitted Binary Tree LeetCode Solution125
1148Search an Element in Sorted Rotated Array125
1149Red-Black Tree Introduction125
1150Subset Sum Problem in O(sum) space124
1151Closest Binary Search Tree Value Leetcode Solution124
1152Priority Queue124
1153Maximum Binary Tree124
1154Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution124
1155Diameter of N-Ary Tree LeetCode Solution124
1156Check Array Formation Through Concatenation Leetcode Solution124
1157Possible Bipartition LeetCode Solution123
1158Minimum Sideway Jumps LeetCode Solution123
1159Transform a BST to Greater sum Tree123
1160Find Largest Value in Each Tree Row LeetCode Solution123
1161Bus Routes Leetcode Solution123
1162Queries for Number of Distinct Elements in a Subarray123
1163Kth Smallest Number in Multiplication Table Leetcode Solution123
1164Golomb sequence123
1165Print modified array after executing the commands of addition and subtraction123
1166Count even length binary sequences with same sum of first and second half bits122
1167Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution122
1168Binary Tree to Binary Search Tree Conversion122
1169Maximize sum of consecutive differences in a circular array122
1170Find a sorted subsequence of size 3 in linear time122
1171Longest Repeated Subsequence122
1172Web Crawler LeetCode Solution122
1173Search Suggestions System LeetCode Solution122
1174Rotate Array122
1175Minimum Cost to Move Chips to The Same Position LeetCode Solution122
1176Graph and its representation121
1177Compare Strings by Frequency of the Smallest Character Leetcode Solution121
1178Find the smallest binary digit multiple of given number121
1179Decision Tree121
1180Swapping Nodes in a Linked List Leetcode Solution121
1181Matchsticks to Square Leetcode Solution121
1182Reverse a Path in BST using Queue120
1183Decrease Elements To Make Array Zigzag LeetCode Solution120
1184Reformat Date LeetCode Solution120
1185Lowest Common Ancestor in Binary Search Tree120
1186Count Pairs Whose Products Exist in Array120
1187Contiguous Array LeetCode Solution120
1188K’th Largest element in BST using constant extra space120
1189First Bad Version120
1190Number of Orders in the Backlog Leetcode Solution120
1191Factorial Trailing Zeroes LeetCode Solution120
1192Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1193Minimum Moves to Equal Array Elements LeetCode Solution120
1194Valid Triangle Number119
1195Closest Leaf in a Binary Tree LeetCode Solution119
1196Sum of Left Leaves LeetCode Solution119
1197Given a binary tree, how do you remove all the half nodes?119
1198Maximum sum of pairs with specific difference119
1199How to print maximum number of A’s using given four keys119
1200Queue Reconstruction by Height119
1201Maximum sum bitonic subarray119
1202Maximum number of segments of lengths a, b and c118
1203Lowest Common Ancestor of a Binary Tree Leetcode Solution118
1204Moving Stones Until Consecutive Leetcode Solution118
1205Champagne Tower LeetCode Solution118
1206Path Crossing Leetcode Solution118
1207Range Queries for Longest Correct Bracket Subsequence118
1208BST to a Tree with Sum of all Smaller Keys117
1209Concatenation of Array LeetCode Solution117
1210Array Queries for multiply replacements and product117
1211Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution117
1212Maximum Depth Of Binary Tree117
1213Minimum Swaps To Make Sequences Increasing LeetCode Solution117
1214Kth Smallest Element in a BST117
1215Guess The Word117
1216Write a function to get the intersection point of two Linked Lists116
1217Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution116
1218Integer Break LeetCode Solution116
1219Replace two consecutive equal values with one greater116
1220LRU Cache Leetcode Solution116
1221Divide Two Integers Leetcode Solution116
1222Valid Perfect Square LeetCode Solution115
1223Sliding Window Median Leetcode Solution115
1224Arithmetic Slices II – Subsequence LeetCode Solution115
1225Flatten 2D Vector LeetCode Solution115
1226New 21 Game115
1227Check if all levels of two Binary Tree are anagrams or not115
1228Maximum Array from Two given Arrays Keeping Order Same115
1229Range Sum Query using Sparse Table115
1230Power of Two115
1231Maximum sum of a path in a Right Number Triangle115
1232Perfect Squares LeetCode Solution115
1233Queries on Probability of Even or Odd Number in given Ranges115
1234Maximum Value at a Given Index in a Bounded Array LeetCode Solution115
1235The kth Factor of n Leetcode Solution114
1236Design Skiplist LeetCode Solution114
1237Maximize Elements Using Another Array114
1238Mean of range in array114
1239Check if each internal node of a BST has exactly one child114
1240Check Completeness of a Binary Tree LeetCode Solution114
1241Largest Plus Sign Leetcode Solution113
1242Graph Cloning113
1243Check for Identical BSTs without building the trees113
1244Bold Words in String LeetCode Solution113
1245Contiguous Array113
1246Print modified array after multiple array range increment operations113
1247Longest Common Prefix Using Word by Word Matching113
1248Find Minimum in Rotated Sorted Array II LeetCode Solution113
1249Find k-th smallest element in BST (Order Statistics in BST)112
1250Print Ancestors of a Given Binary Tree Node Without Recursion112
1251Count Subsets Having Distinct Even Numbers112
1252Parallel Courses II LeetCode Solution112
1253Find minimum number of merge operations to make an array palindrome112
1254Print n terms of Newman-Conway Sequence112
1255Missing Number111
1256Symmetric Tree LeetCode Solution Leetcode Solution111
1257Merge k Sorted Lists Leetcode Solution111
1258Maximum Product Subarray111
1259Count and Toggle Queries on a Binary Array110
1260Excel Sheet Column Title LeetCode Solution110
1261Check if two nodes are on the same path in a Tree110
1262Image Overlap LeetCode Solution110
1263Smallest Range II Leetcode Solution110
1264Verify Preorder Serialization of a Binary Tree110
1265Minimum Remove to Make Valid Parentheses LeetCode Solution110
1266Next greater element109
1267Number of elements less than or equal to a given number in a given subarray109
1268Minimum Time to Collect All Apples in a Tree LeetCode Solution108
1269Check If a String Can Break Another String Leetcode Solution108
1270Koko Eating Bananas LeetCode Solution107
1271Orderly Queue LeetCode Solution107
1272Palindrome Partitioning107
1273Min Cost Climbing Stairs LeetCode Solution107
1274Different Ways to Add Parentheses Leetcode Solution107
1275Longest Substring Without Repeating Characters Leetcode Solution105
1276Newman–Shanks–Williams prime105
1277Check if X can give change to every person in the Queue105
1278Largest Submatrix With Rearrangements LeetCode Solution105
1279Peeking Iterator LeetCode Solution105
1280Check in binary array the number represented by a subarray is odd or even104
1281Merge Sorted Array104
1282Range Minimum Query (Square Root Decomposition and Sparse Table)103
1283Queries for Decimal Values of Subarrays of a Binary Array102
1284Encoded String With Shortest Length LeetCode Solution102
1285Array Nesting Leetcode Solution102
1286Arranging Coins Leetcode Solution101
1287Maximum Sum Increasing Subsequence101
1288Maximum product of an increasing subsequence100
1289Find maximum average subarray of k length100
1290Number of indexes with equal elements in given range99
1291Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1292Minimum Number of People to Teach LeetCode Solution98
1293Convert to Base -2 LeetCode Solution98
1294Random Pick Index LeetCode Solution97
1295Continuous Subarray Sum LeetCode Solution97
1296Reach a Number LeetCode Solution97
1297Add Two Numbers II Leetcode Solution97
1298Convert a BST to a Binary Tree such that sum of all greater keys is added to every key97
1299Check given array of size n can represent BST of n levels or not96
1300Find the Winner of the Circular Game LeetCode Solution96
1301Vertical Order Traversal of Binary Tree LeetCode Solution96
1302Binary Tree to Binary Search Tree Conversion using STL set96
1303Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution95
1304Palindrome Number LeetCode Solution95
1305Jump Game IV LeetCode Solution95
1306Queries on XOR of greatest odd divisor of the range95
1307Insert Delete GetRandom O(1) Leetcode Solution94
1308Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1309Design Underground System Leetcode Solution90
1310Print Maximum Length Chain of Pairs89
1311Detect Capital Leetcode Solution87
1312Design A Leaderboard Leetcode Solution87
1313Top K Frequent Elements LeetCode Solution83
1314Minimum Swaps to Group All 1’s Together Leetcode Solution83
1315Substring with Concatenation of All Words Leetcode Solution83
1316Shifting Letters LeetCode Solution81
1317Count Sub Islands LeetCode Solution81
1318Binary Tree Inorder Traversal LeetCode Solution81
1319Minimum Path Sum Leetcode Solution80
1320Longest Common Subsequence LeetCode Solution77
1321Maximum Population Year LeetCode Solution77
1322Odd Even Linked List Leetcode Solution77
1323Decode String Leetcode Solution76
1324Find the Town Judge LeetCode Solution76
1325Best Meeting Point LeetCode Solution76
1326Find the Town Judge LeetCode Solution75
1327Sum Root to Leaf Numbers LeetCode Solution74
1328Shortest Unsorted Continuous Subarray LeetCode Solution73
1329Maximum Population Year LeetCode Solution71
1330Rectangle Overlap LeetCode Solution71
1331Design Add and Search Words Data Structure LeetCode Solution70
1332Flatten Binary Tree to Linked List LeetCode Solution69
1333Score of Parenthesis LeetCode Solution67
1334Stone Game IV LeetCode Solution67
1335Insert into a Sorted Circular Linked List LeetCode Solution67
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Valid Triangle Number LeetCode Solution63
1338Reveal Cards In Increasing Order Leetcode Solution63
1339Is Graph Bipartite? LeetCode Solution62
1340Divide Chocolate LeetCode Solution57
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution49
1342Range Sum of BST LeetCode Solution46
1343Reverse Integer Leetcode Solution46
1344Sort Colors LeetCode Solution42
1345Find K Closest Elements LeetCode Solution40
1346Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution38
1347Rotate String LeetCode Solution38
1348Excel Sheet Column Number LeetCode Solution37
1349H-Index Leetcode Solution20
1350Maximum Size Subarray Sum Equals k Leetcode Solution20
1351High Five LeetCode Solution19
1352Monotonic Array Leetcode Solution14
1353Camelcase Matching Leetcode Solution12
1354Unique Binary Search Trees LeetCode Solution11
1355Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution11
1356Peak Index in a Mountain Array LeetCode Solution11
1357Group Shifted Strings Leetcode Solution11
1358Valid Triangle Number LeetCode Solution9
1359Isomorphic Strings LeetCode Solution8
1360Swim in Rising Water LeetCode Solution7
Translate »