Greatest Sum Divisible by Three LeetCode Solution


Frequently asked in Adobe Amazon Bloomberg Facebook
DeShaw ShopeeViews 30

Problem Statement:

Greatest Sum Divisible by Three LeetCode Solution:  Array nums of integers are given, we need to find the maximum possible sum of elements of the array such that it is divisible by three.

Example 1:

Input:

 nums = [3,6,5,1,8]

Output:

 18

Explanation:

 Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divisible by 3).

Example 2:

Input:

 nums = [4]

Output:

 0

Explanation:

 Since 4 is not divisible by 3, do not pick any number.

Example 3:

Input:

 nums = [1,2,3,4,4]

Output:

 12

Explanation:

 Pick numbers 1, 3, 4 and 4 their sum is 12 (maximum sum divisible by 3).

 

Constraints:

  • 1 <= nums.length <= 4 * 10^4
  • 1 <= nums[i] <= 10^4

Approach:

  1. This problem can be solved by using Dynamic Programming 
  2. Every number can be represented as a reminder of  3. So, num% 3 can be 0,1,2.
  3. Our dp state is represented by rec(ind, sum).
  4. rec(ind,0) = largest sum till index is divided by three.
  5. rec(ind,1)=  largest sum when divided by 3, remainder = 1.
  6. rec(ind,2)=  largest sum when divided by 3, remainder = 2.
  7. We will use include exclude principal to tackle this dp.
  8. rec(ind,sum)=max(a[ind]+rec(ind,(sum+a[ind])%3),rec(ind+1,sum)).
  9. Now discuss the base condition. If we reach the end of the array then (reminder of a sum) must be zero.
  10. We will discuss recursion with memoization.

Greatest Sum Divisible by Three LeetCode SolutionPin

Code of Greatest Sum Divisible by Three LeetCode Solution:

C++ Code:

class Solution {
public:
    int maxSumDivThree(vector<int>& nums) {
        vector<int> dp={0,INT_MIN,INT_MIN};
    
        for(auto i: nums){
            vector<int> tmp(3);

            for(int j=0;j<3;j++){
                tmp[(j+i)%3]=max(dp[(j+i)%3],dp[j]+i);
            }

            dp=tmp;
        }

        return dp[0];
    }
};

 

Java Code:

class Solution {
    int[][] dp = new int[100005][3];
    int n;
     int rec(int ind,int sum,int[] a)
     {
         if(ind>=n)
         {
             if(sum!=0)
                 return Integer.MIN_VALUE;
             return 0;
         }
         if(dp[ind][sum]!=-1)
             return dp[ind][sum];
         int k=(sum+a[ind])%3;
         int ans1=a[ind]+rec(ind+1,k,a);
         int ans2=rec(ind+1,sum,a);
         return dp[ind][sum]=Math.max(ans1,ans2);
     }
    
    public int maxSumDivThree(int[] nums) { 
        n=nums.length;
        int i,j;
        for(i=0;i<=n;i++)
            for(j=0;j<=2;j++)
                dp[i][j]=-1;
        return rec(0,0,nums);
    }
}

Complexity Analysis for Greatest Sum Divisible by Three LeetCode Solution:

Time complexity:

Time complexity is o(n*3) or we can simply say o(n).

Space complexity:

Space complexity is o(n*3) or we can simply say o(n). We are creating a dp table to store the values.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Palindrome using Recursion2632
3Java program to find the number of Nodes in a Binary Tree2545
4Reverse a string without affecting special characters2529
5Delete a node of a linked list at given position2024
6Quick Sort1773
7Insert nodes in a linked list in a sorted way (Ascending Order)1713
8Find elements pair from array whose sum equal to number1691
9Sort Elements by Frequency of Occurrences1674
10Write a program to print all permutations of a given string1661
11Find Minimum Distance Between Two Numbers in an Array1522
12Create a Doubly Linked List1484
13Reverse an Array1467
14Smallest window in a string containing all characters of another string1441
15Recursively remove all adjacent duplicates1412
16Find a Triplet That Sum to a Given Value1395
17First Repeating Element1387
18Sum of numbers in String1368
19Arrange Even and Odd number such that Odd comes after Even1358
20Smallest Positive Number Missing in an Unsorted Array1327
21Check if the Elements of an Array are Consecutive1294
22Detect a loop in the Linked List1274
23Largest Sum Contiguous Subarray1265
24Quick Sort on SIngly Linked List1261
25Recursive function to do substring search1253
26Print all Possible Combinations of R Elements in a given Array of size N1253
27Subarray with Given Sum1251
28Find the Maximum Repeating Number in Array1208
29Find the First and Second Smallest Elements1157
30Binary Tree Level order traversal in Java1157
31Check if two linked lists are identical1145
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1116
34Find Leaders in an Array1095
35Swap nodes in the linked list1088
36Find the Number Occurring Odd Number of Times in an Array1037
37Find the second most frequent character1036
38Arrange given Numbers to Form the Biggest Number II1028
39Given a string find its first non-repeating character1018
40Find Triplet in Array With a Given Sum1004
41Given a sorted array and a number x, find the pair in array whose sum is closest to x998
42A Program to check if strings are rotations of each other or not993
43Total number of occurrences of a given item in the linked list992
44Print all possible words from phone digits977
45Find the Missing Number968
46Rearrange Positive and Negative Numbers Alternatively in Array955
47Longest Palindromic Substring948
48Segregate even and odd nodes in a linked list939
49Print Longest common subsequence929
50Transform one string to another using minimum number of given operations917
51Union and Intersection of Two Linked Lists906
52Check rearranged string can form a palindrome900
53Rearrange given Array in Maximum Minimum Form879
54Iterative Implementation of Quick Sort871
55Count Possible Triangles860
56Insertion Sort858
57Multiplication of Two Matrices847
58Count of Triplets With Sum Less than Given Value833
59Stock Buy Sell to Maximize Profit831
60Check if the linked list is palindrome830
61Rotate a Linked List829
62Concatenation of two strings808
63Count Number of Substrings with K Distinct Character’s800
64Print all duplicates in the input string799
65Tug of War799
66Find Nearest Greater and Smaller Element788
67Reverse String Without Temporary Variable779
68The Celebrity Problem772
69Remove ‘b’ and ‘ac’ from a given string772
70Find Pythagorean Triplets from Array772
71Find all Common Elements in Given Three Sorted Arrays766
72Remove all duplicates in an unsorted linked list742
73Remove Minimum Characters so that Two Strings Become Anagrams740
74Find the Row with Maximum Number of 1’s739
75Find the subarray whose sum is equal to a given number X739
76Find the Peak Element from an Array737
77Addition of Two Matrices731
78Generate all Binary Strings Without Consecutive 1’s728
79Find Smallest Missing Number in a Sorted Array727
80A Product Array Puzzle725
81Maximum Sum of Non Consecutive Elements713
82Implement Two Stacks in an Array709
83Lexicographic rank of string703
84Check if Two given Matrices are Identical693
85Maximum Product Subarray II690
86Multiplication of Previous and Next684
87Subtraction of Two Matrices678
88Merge K Sorted Arrays and Print Sorted Output671
89Move All the Zeros to the End of the Given Array668
90Divide a string in N equal parts667
91Online Algorithm for Checking Palindrome in a Stream667
92Form Minimum Number from Given Sequence of D’s and I’s666
93Check whether two strings are anagram of each other661
94Remove recurring digits in a given number659
95Sort a stack using a temporary stack657
96Maximum Circular Subarray Sum652
97Sort a linked list that is sorted alternating ascending and descending647
98Subarray and Subsequence640
99Find the Minimum Element in a Sorted and Rotated Array639
100Move last element of the Linked List at first place637
1013Sum Leetcode Solution635
102First Circular Tour to Visit all the Petrol Bunks635
103Compare two strings(linked lists)631
104Palindrome Permutations of a String631
105Maximum Element in an Array which is Increasing and then Decreasing629
106Largest Subarray with Equal Number of 0’s and 1’s627
107Palindromes in a given range625
108Flattening a linked list624
109Run length encoding620
110Minimum insertions to form a shortest palindrome620
111Pangram Checking619
112Majority Element619
113Print all permutations with repetition617
114Minimum Characters to be Added at Front to Make String Palindrome612
115Elements Appear more than N/K times in Array612
116Most repeating character in a string609
117Repeated Subsequence of Length Two or More607
118Two Sum Leetcode Solution607
119Rotate string to get lexicographically minimum string604
120Merge a linked list into another at alternate positions597
121Rearrange a given linked list in-place597
122Remove all duplicates in a sorted linked list597
123Minimum number of Merge Operations to make an Array Palindrome595
124Print all anagrams together in a sequence of words595
125Reorder an Array According to the Given Indexes583
126Pancake Sorting Problem582
127Transpose of a Matrix571
128Merge Overlapping Intervals II570
129Smallest Palindrome after Replacement570
130Remove duplicates from a string568
131Clone a Linked List with next and random pointer568
132Longest Palindrome can be Formed by Removing or Rearranging Characters568
133Remove Extra Spaces from a String566
134Removing Spaces from a String using stringstream564
135Check if a given string is a rotation of a palindrome561
136Maximum Sum Increasing Subsequence560
137Size of The Subarray With Maximum Sum559
138Partition Problem556
139Check whether Strings are K Distance Apart or Not550
140Generate all Binary Strings from Given Pattern547
141Delete Last Occurrence546
142Length of Longest valid Substring543
143Check if Two given Strings are Isomorphic to each other541
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized539
145Insert Node in the Sorted Linked List533
146Program to Toggle all Characters in a String533
147Given string is interleaving of two other strings or not528
148Maximum difference between two elements such as larger element comes after smaller527
149Check length of a String is Equal to the Number Appended at its Last518
150Count Minimum Steps to Get the given Array516
151Check if all Rows of a Matrix are Circular Rotations of Each Other516
152Number of Smaller Elements on Right Side512
153Longest Common Prefix using Divide and Conquer510
154Find Pair with Given Difference509
155Merge sort better than quick sort for linked lists506
156Compare Two Version Numbers504
157Print all interleavings of given two strings502
158Find nth node of the Linked list from the end501
159Sort 0s 1s and 2s in an Array499
160Find a Fixed Point in a Given Array498
161Print Reverse of a string (Recursion)498
162Median of Two Sorted Arrays LeetCode Solution497
163Reorder Array Using Given Indexes495
164Reverse words in a given string494
165Merge two sorted linked lists such that merged list is in reverse order487
166Find the Subarray of given length with Least Average486
167Split linked list using alternate nodes485
168Print all Palindromic Partitions of a String479
169Print string of odd length in ‘X’ format478
170Find Element Using Binary Search in Sorted Array470
171Find K Length Subarray of Maximum Average468
172Swap Kth Node from beginning with Kth Node from End466
173Find Duplicates in an Array in Most Efficient Way464
174Check if String Follows Order of Characters by a Pattern or not459
175Shortest Superstring Problem459
176print all palindromic partitions458
177Maximum Length of Chain Pairs451
178Sort a String According to Another String450
179Flatten a multilevel linked list447
180Sorting a K Sorted Array443
181Program to add two binary digits439
182Recursively print all the sentences that can be formed from list of word lists435
183Caesar Cipher434
184Find a Sorted Subsequence of size 3430
185Longest Common Prefix Using Binary Search II429
186Longest Span with same Sum in two Binary Arrays II429
187Reverse a Linked List in groups429
188Find the two Numbers with Odd Occurrences in an Unsorted Array428
189Kth Non-repeating Character426
190Reverse a Singly Linked List (Iterative/Non-Recursive)424
191Check if String can Become Empty by Recursively Deleting given Substring421
192Longest Common Prefix Word by Word Matching416
193Rearrange a linked list in Zig-Zag412
194Rotate Image by 90 degrees410
195Pancake Sorting409
196Permutations of a Given String Using STL408
197Perfect Reversible String408
198Merging Two Sorted Arrays407
199Find First non-repeating character in a string406
200Maximum occurring character in a string402
2011`s and 2`s complement of binary number402
202Increasing Subsequence of Length three with Maximum Product399
203List items containing all characters of a given word397
204Find the point where a monotonically increasing function becomes positive first time396
205Four Elements that Sum to Given392
206Longest Common Prefix using Character by Character Matching390
207Sort a linked list with 0s, 1s and 2s390
208Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes389
209Palindrome string (number)387
210Count Number of Occurrences in a Sorted Array386
211Valid Parentheses LeetCode Solution386
212Delete N nodes after M382
213Minimum Characters to be Removed to Make a Binary String Alternate381
214Even Substring Count380
215Split a string379
216Recursive Implementation of atoi()377
217Sorting the array of strings375
218Print Shortest Path to Print a String on Screen371
219Convert a String that is Repetition of a Substring of Length K371
220Nth Character in Concatenated Decimal String368
221Check if a Linked list of Strings form a Palindrome367
222Maximum Subarray Leetcode Solution366
223Convert string1 to string2 in one edit364
224wildcard character matching362
225Count the number of words362
226Print All Distinct Elements of the Array362
227Reverse a String using Stack362
228Reverse a singly linked list recursively361
229Find the first Repeating Number in a Given Array360
230Matrix Chain Multiplication using Dynamic Programming360
231Lower Case To Upper Case356
232Can we reverse a linked list in less than O(n) time ?353
233Binary Tree to Doubly linked list350
234Sort Elements by Frequency II349
235Longest Common Subsequence with Permutations348
236Find the Lost Element From a Duplicated Array346
237Split Four Distinct Strings344
238Merge Two Sorted Arrays343
239Count the Pairs at Same Distance as in English Alphabets340
240Roman to Integer Leetcode Solution340
241Find middle of the Linked List339
242Move all negative elements to one side of array339
243Toeplitz Matrix335
244N queen problem332
245Palindrome Permutation330
246Word Search Leetcode Solution327
247Next Greater Element in an Array326
248Sudoku Solver325
249First non Repeating Element322
250Find All Pairs With a Given Difference320
251Reverse Bits319
252Count Pairs With Given Sum319
253Print all Possible Ways to Break a String in Bracket Form318
254String(represents an integer) to value318
255Searching a node in a Binary Search Tree318
256Number of Islands LeetCode Solution318
257Find Nth Node317
258Fibonacci numbers317
259Repeated Substring Pattern315
260Change Gender of a given String315
261Types of Binary Tree314
262Reverse a String314
263Sort an array of strings313
264Triplet from three linked lists with given sum313
265How to Efficiently Implement k Stacks in a Single Array?312
266Reverse a linked list312
267Number of sub-strings which recursively add up to 9311
268Delete a Tree311
269Min Stack311
270Meeting Rooms II LeetCode Solution310
271Most Frequent Element in an Array310
272Delete a node under given conditions309
273Cuckoo sequence program308
274Longest Palindromic Substring LeetCode Solution308
275Dijkstra Algorithm305
276Remove spaces from a string304
277Longest Common Extension303
278House Robber Leetcode Solution301
279Max stack301
280Binary Tree301
281Sliding Window Technique295
282Word Search295
283Subset Leetcode295
284Best Time to Buy and Sell Stock  II Leetcode Solution293
285Shuffle a given Array292
286Remove middle points in a linked list of line segments292
287Number Of 1 bits290
288Minimize the maximum difference between the heights290
289KMP Algorithm290
290Expression Evaluation289
291Find, second, frequent, character289
292Plus One Leetcode Solution288
293Search Insert Position Leetcode Solution287
294Pair of Positive Negative Values in an Array286
295Evaluation of Postfix Expression286
296Combination Sum Leetcode Solution286
297Reverse words in a string285
298Subarray with 0 sum280
299Min Stack Leetcode Solution280
300Set Matrix Zeroes279
301Valid Palindrome Leetcode Solution279
302Rabin Karp Algorithm279
303Backspace String Compare278
304Common elements in all rows of a given matrix276
305Sort linked which is sorted on absolute values276
306Merge Sorted Arrays Leetcode Solution272
307Clone a linked list with next and random pointer (Hashing)272
308Find Top K (or Most Frequent) Numbers in a Stream271
309Sqrt(x) Leetcode Solution271
310Implementation of Deque using Doubly Linked List271
311Reversing a Queue271
312Delete middle element of a stack270
313Contains Duplicate270
314Tower Of Hanoi269
315Count Odd Numbers in an Interval Range Leetcode Solution268
316String Compression268
317Count subarrays with equal number of 1’s and 0’s268
318Combination Sum267
319Intersection of Two Arrays II Leetcode Solution266
320Product of array except self266
321Page Replacement Algorithms in Operating Systems265
322Count of index pairs with equal elements in an array265
323Contains Duplicate II Leetcode Solution265
324Pascal Triangle Leetcode265
325How to Delete a Linked List265
326Reverse individual words265
327Minimum swaps required to bring all elements less than or equal to k together264
328Segregate even and odd numbers263
329Single Number Leetcode Solution262
330Group Words With Same Set of Characters262
331Second Most Repeated Word in a Sequence262
332Find sum of non-repeating elements (distinct) elements in an array262
333Integer to Roman Leetcode Solution261
334Count subarrays having total distinct elements same as original array261
335Bellman Ford Algorithm260
336Smallest Subarray with k Distinct Numbers260
337Postfix to Infix Conversion260
338Sum of minimum and maximum elements of all subarrays of size k260
339Given two unsorted arrays find all pairs whose sum is x260
340Sorting array using Stacks259
341Sort elements by frequency259
342Next Permutation259
343Minimum Value to Get Positive Step by Step Sum Leetcode Solution259
344K-th Smallest Element in a Sorted Matrix258
345Arithmetic Expression Evaluation258
346Add Binary Leetcode Solution257
347Convex Hull Algorithm256
348Construct Binary Tree from Given Inorder and Preorder Traversals256
349Top K Frequent Words256
350First element occurring k times in an array256
351Maximum Number of Balloons Leetcode Solution255
352Minimum operation to make all elements equal in array255
353Design a stack that supports getMin() in O(1) time and O(1) extra space254
354Longest Common Prefix Leetcode Solution254
355Pow(x, n) Leetcode Solution253
356Scramble String253
357Longest Substring Without Repeating Characters LeetCode Solution253
358Special Number252
359Palindrome Linked List Leetcode Solution252
360Majority Element Leetcode Solution250
361Kruskal Algorithm250
362Find Lucky Integer in an Array Leetcode Solution250
363Reversing the First K elements of a Queue250
364Evaluate Division250
365Check if two arrays are equal or not250
366Find duplicates in a given array when elements are not limited to a range250
367Running Sum of 1d Array Leetcode Solution248
368Maximum possible difference of two subsets of an array248
369Permutations Leetcode Solution248
370Third Maximum Number Leetcode Solution247
371Number of Good Pairs Leetcode Solution245
372Prefix to Infix Conversion245
373Maximum Distance Between two Occurrences of Same Element in Array245
374Smallest Element Repeated Exactly K Times245
375Huffman Coding245
376Spiral Matrix LeetCode Solution245
377Fizz Buzz Leetcode245
378Minimum Path Sum245
379Group Anagrams244
380Maximum Subarray244
381Find the Town Judge Leetcode Solution244
382Find the first repeating element in an array of integers244
383Convert String To Int244
384Maximal Square244
385Reverse a Number Using Stack243
386Find Numbers with Even Number of Digits Leetcode Solution243
387Find the Closest Palindrome number243
388Range Sum Query 2D – Immutable Leetcode Solution243
389Swap Nodes in Pairs Leetcode Solutions242
390Count Primes Leetcode Solutions242
391Minimum Steps to reach target by a Knight242
392Palindrome Substring Queries242
393Minimum Absolute Difference Leetcode Solution241
394Sorting using trivial hash function241
395Find top three repeated in array241
396Cumulative Frequency of Count of Each Element in an Unsorted Array241
397Single Number241
398Unique Paths241
399Zigzag Conversion240
400Find All Numbers Disappeared in an Array Leetcode Solution240
401Print all subarrays with 0 sum239
402Implement Stack and Queue using Deque239
403Find Number of Employees Under every Employee239
404Remove Minimum Number of Elements Such That no Common Element Exist in both Array239
405Pascal’s Triangle II Leetcode Solution238
406Sort Array by Increasing Frequency Leetcode Solution238
407Expression Contains Redundant Bracket or Not238
408Check if Array Contains Contiguous Integers With Duplicates Allowed238
409Fizz Buzz238
410Bipartite Graph237
411How to Implement Stack Using Priority Queue or Heap?237
412Count Substrings with equal number of 0s, 1s and 2s237
413Print All Distinct Elements of a Given Integer Array237
414Leetcode Permutations237
415Difference between highest and least frequencies in an array237
416Power of Two Leetcode Solution237
417Letter Case Permutation236
418Matrix Diagonal Sum Leetcode Solution236
419Subarray Sum Equals k236
420Length of the largest subarray with contiguous elements236
421Sort Integers by The Number of 1 Bit Leetcode Solution236
422Missing Number Leetcode Solution236
423Subset sum problem235
424Unique Paths Leetcode Solution235
425Sort a stack using recursion235
426Prim’s Algorithm235
427Merge Two Sorted Lists Leetcode Solutions235
428Decode String235
429LRU Cache Implementation235
430Maximum Depth of Binary Tree Leetcode Solution234
431Top K Frequent Elements234
432House Robber II Leetcode Solution234
433Find all pairs (a, b) in an array such that a % b = k233
434Subarrays with distinct elements233
435Happy Number Leetcode Solution233
436Reverse Integer233
437Find Median from data Stream233
438Search in Rotated Sorted Array Leetcode Solution232
439Nth Catalan Number232
440Find Winner on a Tic Tac Toe Game Leetcode Solution231
441Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution231
442Coin Change 2 Leetcode Solution231
443Count pairs from two linked lists whose sum is equal to a given value231
444Monotonic Array LeetCode Solution230
445Pair with given product230
446Max Consecutive Ones Leetcode Solution230
447Reverse a String229
448How Many Numbers Are Smaller Than the Current Number Leetcode Solution229
449Check If N and Its Double Exist Leetcode Solution229
450Edit Distance229
451Intersection of Two Arrays229
452Capacity To Ship Packages Within D Days Leetcode Solution229
453Find elements which are present in first array and not in second229
454Integer to English words228
455Find the Difference Leetcode Solution228
456Valid Parenthesis String228
457Priority Queue Using Singly Linked List228
458Find The Duplicate Number228
459Reverse a Stack Using Recursion228
460Longest subarray not having more than K distinct elements228
461Find any one of the multiple repeating elements in read only array227
462Find distinct elements common to all rows of a matrix227
463Find Minimum In Rotated Sorted Array227
464Find Index of Closing Bracket for a Given Opening Bracket in an Expression227
465Floyd Warshall Algorithm227
466Count and Say227
467Trapping Rain Water Leetcode Solution227
468Fibonacci Number LeetCode Solution227
469Subtract the Product and Sum of Digits of an Integer Leetcode Solution227
470Find Common Characters Leetcode Solution227
471Subarray Sum Equals K LeetCode Solution227
472Rearrange a binary string as alternate x and y occurrences226
473Find four elements that sum to a given value (Hashmap)226
474Text Justification LeetCode Solution226
475Sum of Subarray Ranges Leetcode Solution226
476Reverse Vowels of a String Leetcode Solution226
477Jump Game Leetcode Solution225
478Check if a given array contains duplicate elements within k distance from each other225
479Longest Common Prefix using Trie225
480Best Time to Buy and Sell Stock III Leetcode Solution225
481Generate a String With Characters That Have Odd Counts Leetcode Solution224
482Design Parking System Leetcode Solution224
483Target Sum224
484Remove Duplicates from Sorted Array Leetcode Solution224
485The K Weakest Rows in a Matrix Leetcode Solution224
486Kth largest element in an Array Leetcode Solutions224
487Delete a Node from linked list without head pointer223
488Check for Balanced Parentheses in an Expression223
489MiniMax Algorithm223
490Find subarray with given sum (Handles Negative Numbers)223
491Prefix to Postfix Conversion223
492The Stock Span Problem223
493Largest Sum Contiguous Subarray222
494Iterative Tower of Hanoi222
495Find missing elements of a range222
496Shortest Palindrome222
497Multiply Strings Leetcode Solution222
498K-th Distinct Element in an Array221
499Substring With Concatenation Of All Words221
500Count number of triplets with product equal to given number221
501Word Ladder LeetCode Solution220
502Top View of Binary Tree220
503Longest Common Prefix using Sorting220
504Shuffle the Array Leetcode Solution220
505Valid Sudoku220
506Shuffle String Leetcode Solution220
507Iterative Inorder Traversal of a Binary Tree220
508Sorting a Queue without Extra Space220
509Priority Queue in C++220
510Container with Most Water220
511Degree of an array220
512Implement Stack using Queues219
513Recursion219
514Number of Steps to Reduce a Number to Zero Leetcode Solution219
515Flood Fill LeetCode219
516Slowest Key Leetcode Solution219
517Peak Index in a Mountain Array219
518Minimum Knight Moves LeetCode Solution219
519Balanced Binary Tree Leetcode Solution219
520Max Area of Island219
521Merge Two Sorted Linked Lists218
522Minimum Delete Operations to make all Elements of Array Same218
523Best Time to Buy and Sell Stock LeetCode Solution218
524Next Greater Frequency Element218
525Kids With the Greatest Number of Candies Leetcode Solution218
526Implement a stack using single queue218
527Next Greater Element I Leetcode Solution218
528Excel Sheet Column Number Leetcode Solution218
529Maximum sum rectangle in a 2D matrix217
530Longest Common Subsequence217
531Postfix to Prefix Conversion217
532Concatenation of Array LeetCode Solution217
533Jewels and Stones Leetcode Solution217
534Move Zeroes LeetCode Solution217
535Count and Say Leetcode Solution217
536Find First and Last Position of Element in Sorted Array Leetcode Solution217
537Sum of Left Leaves Leetcode Solutions217
538Find the Duplicate Element217
539Arrange given numbers to form the biggest number217
540Reverse Words in a String III LeetCode Solution217
541Hamming Distance217
542Smallest Subarray With all Occurrences of a Most Frequent Element217
543Convert array into Zig-Zag fashion217
544Linked List Cycle II LeetCode Solution216
545Change the Array into Permutation of Numbers From 1 to N216
546How to check if two given sets are disjoint?216
547Find Sum of all unique sub-array sum for a given array216
548Shuffle an Array215
549Kth Largest Element in a Stream Leetcode Solution215
550Count the number of nodes at given level in a tree using BFS215
551Minimum Moves to Equal Array Elements Leetcode Solution215
552Check if a queue can be sorted into another queue using a stack215
553Group Multiple Occurrence of Array Elements Ordered by first Occurrence214
554Gold Mine Problem214
555N-th Tribonacci Number Leetcode Solution214
556Largest Perimeter Triangle Leetcode Solution214
557Zigzag Conversion LeetCode Solution214
558Valid Anagrams214
559Convert a normal BST to Balanced BST213
560Merge Overlapping Intervals213
561Contiguous Array Leetcode213
562Isomorphic Strings Leetcode Solution213
563Delete Node in a Linked List Leetcode Solution212
564Minimum number of subsets with distinct elements212
565Excel Sheet Column Title Leetcode Solution212
566Sieve of Eratosthenes212
567Minimum Bracket Reversals212
568Is Subsequence Leetcode Solution212
569Find N Unique Integers Sum up to Zero Leetcode Solution212
570Summary Ranges Leetcode Solution211
571Integer to Roman211
572Maximum Distance in Array211
573Last Stone Weight211
574Minimum Cost to Hire K Workers211
575Find if an Expression has Duplicate Parenthesis or Not211
576Maximum path sum in a triangle210
577Koko Eating Bananas Leetcode Solution210
578Mobile Numeric Keypad Problem210
579Word Pattern210
580Smallest Good Base210
581Non-overlapping sum of two sets209
582Best Time to Buy and Sell Stock209
583Number of Provinces Leetcode Solution209
584Find Words That Can Be Formed by Characters Leetcode Solution209
585Shortest Path in a Grid with Obstacles Elimination LeetCode Solution209
5863Sum Closest LeetCode Solution209
587Implementation of Deque using circular array209
588Longest Increasing Subsequence209
589Maximum difference between first and last indexes of an element in array209
590Length of Last Word Leetcode Solution209
591Build Array From Permutation Leetcode Solution209
592Frog Jump Leetcode Solution208
593Relative Sort Array Leetcode Solution208
594Maximum Number of Occurrences of a Substring Leetcode Solution208
595Combinations Leetcode Solution208
596Decode Ways208
597Delete consecutive same words in a sequence208
598Trapping Rain Water LeetCode Solution208
599Rotate Image LeetCode Solution208
600Distribute Candies to People Leetcode Solution208
601First negative integer in every window of size k207
602Minimum Operations to convert X to Y207
603Iterative Method to find Height of Binary Tree207
604Sort Characters By Frequency LeetCode Solution207
605Island Perimeter Leetcode Solution207
60601 Matrix LeetCode Solution207
607Remove All Occurrences of a Substring LeetCode Solution207
608Sum of f(a[i], a[j]) over all pairs in an array of n integers206
609Remove Linked List Elements Leetcode Solution206
610LRU Cache LeetCode Solution206
611The Knapsack Problem205
612Minimum number of distinct elements after removing m items205
613Find minimum difference between any two elements205
614Minimum insertions to form a palindrome with permutations allowed205
615GCD Of Two Numbers205
616Maximum Number of Chocolates to be Distributed Equally Among k Students205
617Reverse a stack without using extra space in O(n)205
618Bubble sort using two Stacks204
619Rotate List Leetcode Solution204
620Find the smallest positive integer value that cannot be represented as sum of any subset of a given array204
621Count all subsequences having product less than K204
622XOR Operation in an Array Leetcode Solution204
623Assign Cookies Leetcode Solution204
624Tracking current Maximum Element in a Stack203
625Insert Interval Leetcode Solution203
626Permutation in String Leetcode Solution203
627Reorganize String203
628Isomorphic Strings203
629Unique Binary Search Trees203
630How to Create Mergable Stack?203
631Convert an array to reduced form203
632Longest Increasing Path in a Matrix LeetCode Solution202
633Find the Duplicate Number LeetCode Solution202
634Convert Sorted Array to Binary Search Tree Leetcode Solution202
635Form minimum number from given sequence202
636K Empty Slots202
637Find Largest d in Array such that a + b + c = d202
638Stone Game LeetCode202
639Find Pair with Greatest Product in Array201
640Same Tree LeetCode Solution201
641Largest subarray with equal number of 0s and 1s201
642Defanging an IP Address Leetcode Solution201
643Distance Between Bus Stops Leetcode Solution201
644Employee Free Time LeetCode Solution201
645Applications of Breadth First Search and Depth First Search201
646First Unique Character in a String LeetCode Solution200
647Optimal Account Balancing LeetCode Solution200
648Valid Palindrome200
649Count Good Nodes in Binary Tree Leetcode Solution200
650Find the node with minimum value in a Binary Search Tree200
651License Key Formatting Leetcode Solution200
652Convert a Number to Hexadecimal Leetcode Solution199
653Word Wrap Problem199
654Merge Two Balanced Binary Search Trees199
655Printing brackets in Matrix Chain Multiplication Problem199
656Coin Change Problem199
657Minimum Depth of Binary Tree Leetcode Solution199
658Maximum Consecutive Numbers Present in an Array199
659Letter Combinations of a Phone Number199
660Robot Room Cleaner Leetcode Solution198
661Replace Elements with Greatest Element on Right Side Leetcode Solution198
662Find pairs with given sum such that elements of pair are in different rows198
663Longest Span with same Sum in two Binary arrays198
664K Empty Slots LeetCode197
665Numbers with prime frequencies greater than or equal to k197
666Check If It Is a Straight Line Leetcode Solution197
667Painting Fence Algorithm197
668Kth Missing Positive Number Leetcode Solution197
669Segregate 0s and 1s in an Array197
670Flipping an Image LeetCode Solution197
671Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions197
672Longest Substring with At Most K Distinct Characters LeetCode Solution197
673Sort Array By Parity LeetCode Solution197
674House Robber197
675Find the Distance Value Between Two Arrays Leetcode Solution197
676Number of Dice Rolls With Target Sum LeetCode Solution196
677Reducing Dishes LeetCode Solution196
678Strobogrammatic Number LeetCode Solution196
679Generate all possible sorted arrays from alternate elements of two given sorted arrays196
680String to Integer (atoi) LeetCode Solution196
681Count quadruples from four sorted arrays whose sum is equal to a given value x196
682Maximum Product of Two Elements in an Array Leetcode Solution196
683Reservoir Sampling196
684Moving Average from Data Stream Leetcode Solution196
685Partition Labels LeetCode Solution196
686k-th missing element in increasing sequence which is not present in a given sequence196
687Distance of nearest cell having 1 in a binary matrix196
688Print the Fibonacci numbers in reverse order195
689Partition Array Into Three Parts With Equal Sum Leetcode Solution195
690Power of Four Leetcode Solution195
691Longest Substring with At Least K Repeating Characters LeetCode Solution195
692Valid Palindrome II Leetcode Solution195
693String Compression LeetCode Solution195
694Find unique character in a string194
695Reverse Only Letters LeetCode Solution194
696Dynamic Programming Basics194
697Find Maximum Level sum in Binary Tree194
698Find Leaves of Binary Tree LeetCode Solution194
699Queries for counts of array elements with values in given range194
700Find the largest multiple of 3193
701Wiggle Sort193
702Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest193
703Remove Invalid Parentheses Leetcode Solution193
704Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
705Find whether an array is subset of another array193
706Snakes and Ladders LeetCode Solution193
707Increasing Decreasing String Leetcode Solution193
708Binary Tree Maximum Path Sum LeetCode Solution193
709Sum of All Odd Length Subarrays Leetcode Solution193
710Unique Paths II Leetcode Solution192
711Find the Smallest Divisor given a Threshold Leetcode Solution192
712Path With Maximum Minimum Value LeetCode Solution192
713Elements to be added so that all elements of a range are present in array192
714Stack Permutations (Check if an array is stack permutation of other)192
715Find Maximum Depth of Nested Parenthesis in a String192
716Remove brackets from an algebraic string containing + and – operators192
717Growable array based stack192
718To Lower Case Leetcode Solution192
719Check for Palindrome after every character replacement Query192
720Check If Two String Arrays are Equivalent Leetcode Solution192
721Sort Array by Increasing Frequency Leetcode Solution191
722Populating Next Right Pointers in Each Node191
723String comparison containing wildcards191
724Binary Tree zigzag level order Traversal191
725Bulb Switcher LeetCode Solution191
726Priority Queue using doubly linked list191
727Edit Distance LeetCode Solution191
728Keyboard Row Leetcode Solution191
729Valid Perfect Square Leetcode Solution191
730Maximum Profit in Job Scheduling Leetcode Solution191
731Inorder Successor of a node in Binary Tree191
732Lucky Numbers in a Matrix Leetcode Solution191
733Maximum Number of Coins You Can Get Leetcode Solution191
734Binary Tree Zigzag Level Order Traversal LeetCode Solution190
735Non-decreasing Array LeetCode Solution190
736Valid Number190
737Reversing a Queue using Recursion190
738Ugly Number Leetcode Solution190
739Merge Two Binary Trees LeetCode Solution190
740Factorial Trailing Zeroes Leetcode Solution190
741Number of NGEs to the Right190
742Base 7 Leetcode Solution190
743BFS vs DFS for Binary Tree190
744Minimum Cost For Tickets Leetcode Solution190
745Majority Element II Leetcode Solution190
746Race Car LeetCode Solution190
747Subset Sum Leetcode190
748Delete Nth node from the end of the given linked list190
749Merge Sorted Array LeetCode Solution190
750Recover Binary Search Tree190
751Permutation Sequence LeetCode Solution190
752Tiling Problem189
753Print a Binary Tree in Vertical Order189
754Maximum Length of a Concatenated String with Unique Characters Leetcode Solution189
755Perform String Shifts Leetcode189
756Find if Path Exists in Graph Leetcode Solution189
757Restore IP Addresses Leetcode Solution188
758Maximum 69 Number Leetcode Solution188
759Program for Bridge and Torch problem188
760Count items common to both the lists but with different prices188
761Morris Traversal188
762Check if Two Expressions With Brackets are Same188
763Student Attendance Record I Leetcode Solution188
764Minimum sum of multiplications of n numbers188
765Regular Expression Matching188
766Longest Subarray Having Count of 1s One More than Count of 0s188
767Best Meeting Point LeetCode Solution188
768Finding K closest element188
769Partition to K Equal Sum Subsets Leetcode Solution187
770Construct BST from given Preorder Traversal187
771Hamming Distance Leetcode Solution187
772Circular Queue187
773Maximum Product of Three Numbers LeetCode Solution187
774Split a String in Balanced Strings Leetcode Solution187
775Word Pattern LeetCode Solution187
776N-Queens LeetCode Solution187
777Add and Search Word – Data structure design LeetCode187
778Evaluate Reverse Polish Notation LeetCode Solution187
779Minimum Distance Between BST Nodes Leetcode Solution187
780Number of Days Between Two Dates LeetCode Solution187
781Check If Array Pairs Are Divisible by k LeetCode Solution187
782Find All Duplicates in an Array LeetCode Solution187
783Jump Game186
784Minimum Height Trees186
785Rank Transform of an Array Leetcode Solution186
786Decompress Run-Length Encoded List Leetcode Solution186
787Minimum Time Visiting All Points Leetcode Solution186
788Binomial Coefficient186
789Sort an array according to the order defined by another array186
790Largest Rectangle in Histogram LeetCode Solution186
791Find Median from Data Stream LeetCode Solution186
792Top K Frequent Words LeetCode Solution186
793Symmetric Tree Leetcode Solution186
794Form Minimum Number From Given Sequence186
795Maximum Depth of N-ary Tree Leetcode Solution185
796Nested List Weight Sum II LeetCode Solution185
797Minimize Maximum Pair Sum in Array LeetCode Solution185
798Brick Wall LeetCode Solution185
799Invert Binary Tree LeetCode Solution185
800Find All Possible Recipes from Given Supplies LeetCode Solution185
801Sorted Linked List to Balanced BST185
802Total Numbers With no Repeated Digits in a Range184
803Linked List Cycle184
804Merge K Sorted Linked Lists184
805Search in a Binary Search Tree Leetcode Solution184
806Identify and Mark Unmatched Parenthesis in an Expression184
807Queue based approach for first non-repeating character in a stream184
808Maximum Nesting Depth of the Parentheses Leetcode Solution184
809Find all permuted rows of a given row in a matrix184
810Special Array With X Elements Greater Than or Equal X Leetcode Solution184
811Crawler Log Folder Leetcode Solution183
812Nearest Exit from Entrance in Maze LeetCode Solution183
813Kth ancestor of a node in binary tree183
814Balanced Expression with Replacement183
815Largest rectangular sub-matrix whose sum is 0183
816Remove Nth Node From End of List Leetcode Solution183
817Number of Islands II LeetCode Solution183
818Maximum Difference Between Increasing Elements LeetCode Solution182
819Minimum time required to rot all oranges182
820Course Schedule II – LeetCode182
821Given an Array of Pairs Find all Symmetric Pairs in it182
822Minimum Swaps to Make Strings Equal Leetcode Solution182
823One Edit Distance LeetCode Solution182
824Diagonal Traversal of Binary Tree182
825Interval Tree182
826Split Array Into Consecutive Subsequences182
827Relative Ranks Leetcode Solution182
828Transpose Graph182
829Repeated Substring Pattern LeetCode Solution182
830Minimum Number of Taps to Open to Water a Garden LeetCode Solution181
831A Space Optimized DP solution for 0-1 Knapsack Problem181
832Find Maximum Sum Possible Equal Sum of Three Stacks181
833Subarray Product Less Than K LeetCode Solution181
834Permutation Coefficient181
835Final Prices With a Special Discount in a Shop Leetcode Solution181
836Insert Delete GetRandom181
837Check if stack elements are pairwise consecutive181
838Deletion in a Binary Tree181
839Brightest Position on Street LeetCode Solution181
840Lemonade Change Leetcode Solution180
841Reorder Data in Log Files LeetCode Solution180
842Subsequence of Size K With the Largest Even Sum LeetCode Solution180
843Design Browser History LeetCode Solution180
844Search a 2D Matrix II Leetcode Solution180
845Remove Duplicates from Sorted List II180
846Tree Traversal (Preorder, Inorder & Postorder)180
847Path with maximum average value180
848Last Stone Weight II LeetCode Solution180
849Check if an Array is Stack Sortable179
850Valid Parentheses Leetcode Solution179
851Clone Graph LeetCode Solution179
852Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
853Remove Duplicates from Sorted List LeetCode Solution179
854Number Complement Leetcode Solution179
855Find the Only Repetitive Element Between 1 to N-1179
856Daily Temperatures Leetcode Solution179
857Iterative Postorder Traversal Using Two Stacks179
858Sliding Window Maximum179
859LCS (Longest Common Subsequence) of three strings179
860Missing Element in Sorted Array LeetCode Solution179
861Binary Search Tree Search and Insertion179
862Minimum Jumps to Reach Home LeetCode Solution179
863Sort Array By Parity II Leetcode Solution179
864Iterative Preorder Traversal179
865Spiral Matrix II Leetcode Solution179
866Check if a given array can represent Preorder Traversal of Binary Search Tree179
867Distinct adjacent elements in an array179
868Least Number of Unique Integers after K Removals Leetcode Solution179
869Minimum Sum Path in a Triangle179
870Maximum Score After Splitting a String Leetcode Solution178
871Sort Colors178
872Matrix Chain Multiplication178
873Median of Two Sorted Arrays178
874Can Place Flowers LeetCode Solution178
875Alien Dictionary LeetCode Solution178
876Minimum number of jumps to reach end178
877Partition List Leetcode Solution178
878Range LCM Queries178
879Guess Number Higher or Lower LeetCode Solution178
880Sum of nearest smaller and greater number178
881Get Maximum in Generated Array Leetcode Solution177
882Minimum swaps to make sequences increasing177
883Count Negative Numbers in a Sorted Matrix LeetCode Solution177
884Dividing Array into Pairs With Sum Divisible by K177
885An Interesting Method to generate Binary Numbers from 1 to n177
886Convert BST to Min Heap177
887Find distance between two nodes of a Binary Tree177
888Maximum size subarray sum equals k177
889Union and Intersection of two Linked Lists177
890Find all triplets with zero sum177
891Friends Pairing Problem177
892Diagonal Traverse LeetCode Solution177
893Count Distinct Elements in Every Window of Size K177
894Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i176
895Water Bottles Leetcode Solution176
896Level order Traversal in Spiral Form176
897Check whether a given Binary Tree is Complete or not176
898GCDs of given index ranges in an array176
899Minesweeper LeetCode Solution176
900A program to check if a binary tree is BST or not176
901Binary array after M range toggle operations176
902Count Submatrices With All Ones LeetCode Solution176
903Diagonal Traversal LeetCode Solution176
904Infix to Postfix176
905Count ways to reach the nth stair using step 1, 2 or 3176
906Sequences of given length where every element is more than or equal to twice of previous176
907Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution176
908Find the subarray with least average176
909Design a Stack With Increment Operation Leetcode Solution176
910Sorted Array to Balanced BST176
911Subset with sum divisible by m176
912Pattern Occurrences using Stack176
913Insert into a Binary Search Tree Leetcode Solution175
914Check if any two intervals overlap among a given set of intervals175
915Time Based Key-Value Store LeetCode Solution175
916Number of Distinct Islands Leetcode Solution175
917Delete And Earn175
918Guess Number Higher or Lower II174
919Binary Tree Longest Consecutive Sequence LeetCode Solution174
920Rearrange an Array Such that arr[i] is equal to i174
921Construct the Rectangle Leetcode Solution174
922Destination City Leetcode Solution174
923Range sum queries without updates174
924All Unique Triplets that Sum up to a Given Value174
925Three way partitioning of an array around a given range174
926Convert Sorted List to Binary Search Tree174
927Averages of Levels in Binary Tree174
928Number of Equivalent Domino Pairs Leetcode Solution173
929Rearrange Spaces Between Words Leetcode Solution173
930Set Matrix Zeroes Leetcode Solution173
931Trim a Binary Search Tree173
932Lexicographical Numbers Leetcode Solution173
933K’th Largest Element in BST when modification to BST is not allowed173
934Shortest Word Distance Leetcode Solution173
935Queue using Stacks173
936Longest Palindromic Subsequence173
937Robot Bounded In Circle LeetCode Solution173
938Product of Array Except Self LeetCode Solution173
939Special Positions in a Binary Matrix Leetcode Solution173
940Check if the given array can represent Level Order Traversal of Binary Search Tree173
941Construct Complete Binary Tree from its Linked List Representation172
942Spiral Matrix III LeetCode Solution172
9433 Sum172
944Analyze User Website Visit Pattern LeetCode Solution172
945Find Common Characters Leetcode Solution172
946Palindrome Partitioning Leetcode Solution172
947Alien Dictionary172
948Queries for GCD of all numbers of an array except elements in a given range172
949Print Fibonacci sequence using 2 variables172
950Difference Array | Range update query in O(1)172
951Intersection of Two Linked Lists LeetCode Solution171
9524Sum171
953Maximum Frequency Stack Leetcode Solution171
954BFS for Disconnected Graph171
955Depth First Search (DFS) for a Graph171
956Count Subarrays with Same Even and Odd Elements171
957My Calendar I LeetCode Solution171
958Construct BST from its given Level Order Traversal170
959Remove Duplicates from Sorted List II LeetCode Solution170
960Largest area rectangular sub-matrix with equal number of 1’s and 0’s170
961Maximize Sum of Array after K Negations Leetcode Solution170
962Climbing stairs170
963Three Consecutive Odds Leetcode Solution170
964Minimum Height Trees LeetCode Solution170
965Create Maximum Number170
966Merge Two Sorted Lists Leetcode170
967Vertical sum in a given binary tree170
968Symmetric Tree170
969Count pair with Given Sum169
970Unique Paths II169
971Sign of the Product of an Array LeetCode Solution169
972K maximum sums of overlapping contiguous sub-arrays169
973Count subarrays where second highest lie before highest169
974Strongly Connected Component169
975Merging Intervals169
976Breadth First Search (BFS) for a Graph169
977Word Break169
978Count Primes in Ranges169
979Longest Nice Substring LeetCode Solution168
980Longest subsequence such that difference between adjacents is one168
981Design Hit Counter LeetCode Solution168
982Largest Number Leetcode Solution168
983Kth Smallest Element in a BST Leetcode Solution168
984Reverse Nodes in K-Group168
985Stone Game II Leetcode168
986Maximum Subarray Sum Excluding Certain Elements168
987Maximum length subsequence with difference between adjacent elements as either 0 or 1168
988Next Permutation Leetcode Solution168
989Find Maximum of Minimum for Every Window Size in a Given Array168
990Combination Sum IV LeetCode Solution168
991Count pairs from two sorted arrays whose sum is equal to a given value x167
992Maximum Product Subarray167
993Asteroid Collision LeetCode Solution167
994Serialize and Deserialize Binary Tree167
995Number of palindromic paths in a matrix167
996Largest Substring Between Two Equal Characters Leetcode Solution167
997Valid Boomerang Leetcode Solution167
998Can Make Arithmetic Progression From Sequence Leetcode Solution166
999Scramble String LeetCode Solution166
1000Height of a generic tree from parent array166
1001Find number of pairs in an array such that their XOR is 0166
1002Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space166
1003Length of Longest Fibonacci Subsequence166
1004Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution166
1005Find the Difference Leetcode Solution166
1006Maximum difference between frequency of two elements such that element having greater frequency is also greater166
1007Print Next Greater Number of Q queries166
1008Maximum Length of Repeated Subarray166
1009Balanced Binary Tree166
1010Graph Valid Tree LeetCode Solution166
1011K Closest Points to Origin Leetcode Solution166
1012String Matching in an Array Leetcode Solution166
1013Maximum Product of Indexes of Next Greater on Left and Right166
1014Segment Tree166
1015Friends Of Appropriate Ages LeetCode Solution165
1016Palindrome Partitioning165
1017Find the First Circular Tour that visits all the Petrol Pumps165
1018The Painter’s Partition Problem165
1019The Maze III LeetCode Solution165
1020Binary Search Tree Delete Operation165
1021Find postorder traversal of BST from preorder traversal165
1022Collect maximum points in a grid using two traversals165
1023Shortest Completing Word Leetcode Solution165
1024Remove Duplicates from Sorted Array II Leetcode Solution165
1025Generate Parentheses Leetcode Solution165
1026Kth Smallest Element in a Sorted Matrix LeetCode Solution165
1027Validate Binary Search Tree165
1028Invalid Transactions LeetCode Solution164
1029Largest divisible pairs subset164
1030Find a Peak Element II LeetCode Solution164
1031Minimum Index Sum of Two Lists164
1032Newman-Conway Sequence164
1033Find Duplicate Subtrees164
1034Maximum Number of Ways to Partition an Array LeetCode Solution164
1035Rearrange array such that even positioned are greater than odd164
1036Number Of Longest Increasing Subsequence164
1037Binary Search Tree164
1038Boundary Traversal of binary tree164
1039Build an Array With Stack Operations Leetcode Solution164
1040Level Order Traversal of Binary Tree164
1041Decrypt String from Alphabet to Integer Mapping Leetcode Solution164
1042Consecutive Characters LeetCode Solution164
1043Merge Sort163
1044Move all negative elements to end in order with extra space allowed163
1045Path Sum II LeetCode Solution163
1046Available Captures for Rook Leetcode Solution163
1047Construct Binary Tree from given Parent Array representation163
1048Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’163
1049Advantages of BST over Hash Table163
1050Double the first element and move zero to end163
1051Boolean Parenthesization Problem163
1052Kill Process LeetCode Solution163
1053Compute nCr % p162
1054Insertion in a Binary Tree162
1055Iterative Depth First Traversal of Graph162
1056Construction of Longest Increasing Subsequence (N log N)162
1057Maximum subsequence sum such that no three are consecutive162
1058Maximum Sum of 3 Non-Overlapping Subarrays162
1059Bitwise AND of Numbers Range LeetCode Solution162
1060Custom Sort String Leetcode Solution161
1061First missing positive161
1062Next Greater Element III LeetCode Solution161
1063Subarrays with K Different Integers Leetcode Solution161
1064Make The String Great Leetcode Solution161
1065Ugly Numbers161
1066Recover Binary Search Tree Leetcode Solution161
1067Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution161
1068Find Three Element From Different Three Arrays Such That a + b + c = sum161
1069Count minimum steps to get the given desired array161
1070Find maximum difference between nearest left and right smaller elements160
1071Rearrange array such that even index elements are smaller and odd index elements are greater160
1072Employee Importance LeetCode Solution160
1073Add two numbers160
1074Find Peak Element160
1075Lowest Common Ancestor160
1076Regular Expression Matching Regular Expression Matching LeetCode Solution159
1077Level order traversal using two Queues159
1078Print all triplets in sorted array that form AP159
1079Defanging an IP Address LeetCode Solution159
1080Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution159
1081Print Right View of a Binary Tree159
1082Remove duplicates from sorted array159
1083Super Ugly Number159
1084Morris Inorder Traversal159
1085Maximize Distance to Closest Person LeetCode Solution159
1086Minimum Size Subarray Sum159
1087Number of Closed Islands Leetcode Solution159
1088Smallest Common Region Leetcode Solution159
1089Partition Equal Subset Sum159
1090Maximum weight transformation of a given string159
1091Find whether a subarray is in form of a mountain or not159
1092Ugly Number II LeetCode Solution158
1093Find the minimum distance between two numbers158
1094Number of siblings of a given Node in n-ary Tree158
1095Increasing Triplet Subsequence LeetCode Solution158
1096Remove Palindromic Subsequences Leetcode Solution158
1097Valid Tic-Tac-Toe State LeetCode Solution158
1098Largest BST Subtree LeetCode Solution158
1099Kth Smallest Product of Two Sorted Arrays LeetCode Solution158
1100Implement Trie (Prefix Tree) Leetcode Solution158
1101Binary Tree Right Side View LeetCode Solution157
1102Serialize and Deserialize Binary Tree LeetCode Solution157
1103Binary Tree Data Structure157
1104Cells with Odd Values in a Matrix LeetCode Solution157
1105Palindrome Permutation LeetCode Solution157
1106Populating Next Right Pointers in Each Node Leetcode Solution157
1107Palindromic Substrings Leetcode Solution157
1108Bus Routes Leetcode Solution157
1109Count Largest Group Leetcode Solution156
1110Reformat The String Leetcode Solution156
1111Day of the Year Leetcode Solution156
1112Products of ranges in an array156
1113Path Sum156
1114Search in Sorted Rotated Array156
1115Number of Students Doing Homework at a Given Time Leetcode Solution156
1116Longest Bitonic Subsequence156
1117Root to Leaf path with target sum Leetcode Solutions155
1118Sum of Even Numbers After Queries155
1119Divisible Pairs Counting155
1120Find Smallest Range Containing Elements from k Lists155
1121Maximum Depth Of Binary Tree155
1122Search Insert Position155
1123Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution155
1124Distinct Subsequences155
1125Iterative method to find ancestors of a given binary tree154
1126Thousand Separator Leetcode Solution154
1127Queries for Number of Distinct Elements in a Subarray154
1128Minimum Score Triangulation of Polygon Leetcode Solution154
1129Clone a Binary Tree with Random Pointers154
1130Write Code to Determine if Two Trees are Identical154
1131Prime Palindrome LeetCode Solution154
1132Bottom View of a Binary Tree154
1133Minimum Absolute Difference in BST Leetcode Solution153
1134Third Maximum Number Leetcode Solution153
1135Mean of Array After Removing Some Elements Leetcode Solution153
1136Moser-de Bruijn Sequence153
1137Longest Repeated Subsequence153
1138Longest Subarray of 1’s After Deleting One Element LeetCode Solution153
1139Longest Increasing Consecutive Subsequence153
1140Minimum sum of squares of character counts in a given string after removing k characters152
1141Maximum Product of Splitted Binary Tree LeetCode Solution152
1142Minimum Swaps To Make Sequences Increasing LeetCode Solution152
1143Diameter of N-Ary Tree LeetCode Solution152
1144Construct K Palindrome Strings LeetCode Solution152
1145Reformat Date LeetCode Solution152
1146Closest Leaf in a Binary Tree LeetCode Solution152
1147Find a sorted subsequence of size 3 in linear time152
1148Golomb sequence152
1149Level of Each node in a Tree from source node152
1150Print modified array after executing the commands of addition and subtraction152
1151Closest Binary Search Tree Value Leetcode Solution152
1152Search an Element in Sorted Rotated Array151
1153Maximize sum of consecutive differences in a circular array151
1154Swap Nodes In Pairs151
1155Count even length binary sequences with same sum of first and second half bits151
1156Find Largest Value in Each Tree Row LeetCode Solution151
1157Maximum Product Subarray151
1158Minimum Moves to Equal Array Elements LeetCode Solution151
1159Replace two consecutive equal values with one greater151
1160Priority Queue151
1161Delete Nodes and Return Forest Leetcode Solution151
1162Cutting a Rod151
1163Constant time range add operation on an array151
1164Rotate Array151
1165Contiguous Array LeetCode Solution151
1166Kth Smallest Number in Multiplication Table Leetcode Solution150
1167Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1168Minimum Cost to Move Chips to The Same Position LeetCode Solution150
1169Convert BST into a Min-Heap without using array150
1170Topological Sorting150
1171Find maximum length Snake sequence150
1172Subset Sum Problem in O(sum) space149
1173Search Suggestions System LeetCode Solution149
1174Decrease Elements To Make Array Zigzag LeetCode Solution149
1175Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution149
1176Web Crawler LeetCode Solution149
1177Decision Tree149
1178Count Pairs Whose Products Exist in Array149
1179Factorial Trailing Zeroes LeetCode Solution149
1180First Bad Version149
1181Check Array Formation Through Concatenation Leetcode Solution149
1182Possible Bipartition LeetCode Solution148
1183Minimum Sideway Jumps LeetCode Solution148
1184Maximum Binary Tree148
1185Maximum number of segments of lengths a, b and c148
1186Perfect Squares LeetCode Solution148
1187Merge two BSTs with limited extra space148
1188Matchsticks to Square Leetcode Solution147
1189Sum of Left Leaves LeetCode Solution147
1190K’th Largest element in BST using constant extra space147
1191Reverse a Path in BST using Queue147
1192Given a binary tree, how do you remove all the half nodes?147
1193Binary Tree to Binary Search Tree Conversion147
1194Valid Triangle Number147
1195Transform a BST to Greater sum Tree147
1196Maximum Value at a Given Index in a Bounded Array LeetCode Solution146
1197Number of Orders in the Backlog Leetcode Solution146
1198Divide Two Integers Leetcode Solution146
1199Maximum sum of a path in a Right Number Triangle146
1200Red-Black Tree Introduction146
1201Sliding Window Median Leetcode Solution146
1202Concatenation of Array LeetCode Solution146
1203Convert Sorted Array to Binary Search Tree LeetCode Solutions146
1204Path Crossing Leetcode Solution146
1205Maximum sum bitonic subarray145
1206Find the smallest binary digit multiple of given number145
1207How to print maximum number of A’s using given four keys145
1208Swapping Nodes in a Linked List Leetcode Solution145
1209Queries on Probability of Even or Odd Number in given Ranges145
1210Maximum sum of pairs with specific difference145
1211Find minimum number of merge operations to make an array palindrome144
1212Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution144
1213Integer Break LeetCode Solution144
1214New 21 Game144
1215Champagne Tower LeetCode Solution144
1216Lowest Common Ancestor of a Binary Tree Leetcode Solution144
1217Queue Reconstruction by Height144
1218Valid Perfect Square LeetCode Solution144
1219Range Queries for Longest Correct Bracket Subsequence143
1220Maximum Array from Two given Arrays Keeping Order Same143
1221Print n terms of Newman-Conway Sequence143
1222Graph and its representation142
1223Find Minimum in Rotated Sorted Array II LeetCode Solution142
1224Maximum Sum Increasing Subsequence142
1225Range Sum Query using Sparse Table142
1226Lowest Common Ancestor in Binary Search Tree142
1227Moving Stones Until Consecutive Leetcode Solution142
1228The kth Factor of n Leetcode Solution142
1229Flatten 2D Vector LeetCode Solution142
1230Check if all levels of two Binary Tree are anagrams or not142
1231Array Queries for multiply replacements and product142
1232LRU Cache Leetcode Solution142
1233Bold Words in String LeetCode Solution142
1234Guess The Word142
1235Maximize Elements Using Another Array141
1236Kth Smallest Element in a BST141
1237Longest Common Prefix Using Word by Word Matching141
1238Contiguous Array140
1239Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution140
1240Largest Plus Sign Leetcode Solution140
1241Write a function to get the intersection point of two Linked Lists140
1242Merge k Sorted Lists Leetcode Solution140
1243Print modified array after multiple array range increment operations140
1244Arithmetic Slices II – Subsequence LeetCode Solution140
1245Mean of range in array140
1246BST to a Tree with Sum of all Smaller Keys139
1247Maximum Product Subarray139
1248Minimum Remove to Make Valid Parentheses LeetCode Solution139
1249Count Subsets Having Distinct Even Numbers139
1250Graph Cloning139
1251Missing Number138
1252Different Ways to Add Parentheses Leetcode Solution138
1253Design Skiplist LeetCode Solution138
1254Find k-th smallest element in BST (Order Statistics in BST)138
1255Parallel Courses II LeetCode Solution137
1256Check for Identical BSTs without building the trees137
1257Power of Two137
1258Verify Preorder Serialization of a Binary Tree136
1259Check if each internal node of a BST has exactly one child136
1260Image Overlap LeetCode Solution136
1261Minimum Time to Collect All Apples in a Tree LeetCode Solution136
1262Symmetric Tree LeetCode Solution Leetcode Solution136
1263Min Cost Climbing Stairs LeetCode Solution136
1264Next greater element135
1265Check in binary array the number represented by a subarray is odd or even135
1266Excel Sheet Column Title LeetCode Solution135
1267Check if two nodes are on the same path in a Tree135
1268Check Completeness of a Binary Tree LeetCode Solution135
1269Print Ancestors of a Given Binary Tree Node Without Recursion134
1270Smallest Range II Leetcode Solution134
1271Koko Eating Bananas LeetCode Solution134
1272Orderly Queue LeetCode Solution133
1273Longest Substring Without Repeating Characters Leetcode Solution133
1274Palindrome Number LeetCode Solution133
1275Count and Toggle Queries on a Binary Array133
1276Arranging Coins Leetcode Solution132
1277Merge Sorted Array132
1278Vertical Order Traversal of Binary Tree LeetCode Solution132
1279Array Nesting Leetcode Solution131
1280Number of elements less than or equal to a given number in a given subarray131
1281Largest Submatrix With Rearrangements LeetCode Solution131
1282Check if X can give change to every person in the Queue131
1283Continuous Subarray Sum LeetCode Solution130
1284Check If a String Can Break Another String Leetcode Solution130
1285Palindrome Partitioning129
1286Peeking Iterator LeetCode Solution129
1287Add Two Numbers II Leetcode Solution129
1288Find the Winner of the Circular Game LeetCode Solution128
1289Queries for Decimal Values of Subarrays of a Binary Array128
1290Find maximum average subarray of k length128
1291Maximum product of an increasing subsequence127
1292Insert Delete GetRandom O(1) Leetcode Solution126
1293Range Minimum Query (Square Root Decomposition and Sparse Table)126
1294Newman–Shanks–Williams prime126
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution125
1296Encoded String With Shortest Length LeetCode Solution124
1297Convert to Base -2 LeetCode Solution123
1298Number of indexes with equal elements in given range123
1299Jump Game IV LeetCode Solution123
1300Reach a Number LeetCode Solution123
1301Check given array of size n can represent BST of n levels or not123
1302Binary Tree to Binary Search Tree Conversion using STL set122
1303Random Pick Index LeetCode Solution122
1304Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1305Minimum Number of People to Teach LeetCode Solution121
1306Convert a BST to a Binary Tree such that sum of all greater keys is added to every key120
1307Design A Leaderboard Leetcode Solution119
1308Minimum Total Space Wasted With K Resizing Operations LeetCode Solution119
1309Design Underground System Leetcode Solution118
1310Queries on XOR of greatest odd divisor of the range118
1311Shifting Letters LeetCode Solution117
1312Print Maximum Length Chain of Pairs116
1313Minimum Swaps to Group All 1’s Together Leetcode Solution113
1314Detect Capital Leetcode Solution113
1315Minimum Path Sum Leetcode Solution111
1316Count Sub Islands LeetCode Solution110
1317Top K Frequent Elements LeetCode Solution110
1318Substring with Concatenation of All Words Leetcode Solution109
1319Odd Even Linked List Leetcode Solution108
1320Monotonic Array Leetcode Solution107
1321Maximum Population Year LeetCode Solution105
1322Binary Tree Inorder Traversal LeetCode Solution105
1323Decode String Leetcode Solution105
1324Find the Town Judge LeetCode Solution104
1325Longest Common Subsequence LeetCode Solution104
1326Shortest Unsorted Continuous Subarray LeetCode Solution99
1327Rectangle Overlap LeetCode Solution97
1328Sum Root to Leaf Numbers LeetCode Solution96
1329Best Meeting Point LeetCode Solution96
1330Find the Town Judge LeetCode Solution95
1331Flatten Binary Tree to Linked List LeetCode Solution94
1332Design Add and Search Words Data Structure LeetCode Solution94
1333Maximum Population Year LeetCode Solution94
1334Insert into a Sorted Circular Linked List LeetCode Solution94
1335Is Graph Bipartite? LeetCode Solution92
1336Score of Parenthesis LeetCode Solution92
1337Stone Game IV LeetCode Solution91
1338Reveal Cards In Increasing Order Leetcode Solution91
1339Valid Triangle Number LeetCode Solution90
1340Range Sum Query 2D – Immutable LeetCode Solution90
1341Divide Chocolate LeetCode Solution84
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution71
1344Reverse Integer Leetcode Solution71
1345Rotate String LeetCode Solution69
1346Find K Closest Elements LeetCode Solution67
1347Sort Colors LeetCode Solution65
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution64
1349Excel Sheet Column Number LeetCode Solution61
1350Maximum Size Subarray Sum Equals k Leetcode Solution55
1351Camelcase Matching Leetcode Solution47
1352H-Index Leetcode Solution47
1353Valid Anagram Leetcode Solution47
1354Most Stones Removed with Same Row or Column LeetCode Solution46
1355Sliding Window Maximum LeetCode Solution46
1356Container With Most Water LeetCode Solution45
1357Group Anagrams LeetCode Solution44
1358Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution44
1359Next Permutation LeetCode Solution44
1360Find Peak Element LeetCode Solution43
1361Binary Search LeetCode Solution43
1362High Five LeetCode Solution43
1363Paint House LeetCode Solution42
1364Group Shifted Strings Leetcode Solution40
1365Flatten Binary Tree to Linked List LeetCode Solution39
1366Sentence Screen Fitting LeetCode Solution39
1367Next Greater Element I Leetcode Solution38
1368Minimum Number of Arrows to Burst Balloons LeetCode Solution38
1369The Number of Weak Characters in the Game LeetCode Solution38
1370Split Linked List in Parts Leetcode Solution38
1371Isomorphic Strings LeetCode Solution37
1372Count Good Nodes in Binary Tree LeetCode Solution37
1373Valid Triangle Number LeetCode Solution36
1374Unique Binary Search Trees LeetCode Solution36
1375Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution34
1376Break a Palindrome LeetCode Solution34
1377Peak Index in a Mountain Array LeetCode Solution34
1378Best Time to Buy and Sell Stock IV LeetCode Solution33
1379Minimum Increment to Make Array Unique Leetcode Solution33
1380All Possible Full Binary Trees LeetCode Solution33
1381Closest Binary Search Tree Value II LeetCode Solution33
1382Swim in Rising Water LeetCode Solution33
1383Single Element in a Sorted Array LeetCode Solution32
1384Max Sum of Two Non-Overlapping Subarrays LeetCode Solution32
1385Implement Rand10() Using Rand7() Leetcode Solution31
1386Contains Duplicate LeetCode Solution31
1387Remove All Ones With Row and Column Flips Leetcode Solution31
1388Validate Stack Sequences LeetCode Solution30
1389Greatest Sum Divisible by Three LeetCode Solution30
1390Trapping Rain Water II LeetCode Solution30
1391Find First and Last Position of Element in Sorted Array LeetCode Solution30
1392Lowest Common Ancestor of a Binary Search Tree Leetcode Solution30
1393Implement strStr() LeetCode Solution29
1394Reverse Nodes in k-Group LeetCode Solution28
1395Detect Squares LeetCode Solution27
1396Stone Game IV LeetCode Solution26
1397Fibonacci Number LeetCode Solution24
1398Invert Binary Tree LeetCode Solution24
1399Design Bounded Blocking Queue LeetCode Solution23
1400Total Hamming Distance LeetCode Solution23
1401Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution22
1402Unique Paths III LeetCode Solution20
1403Candy LeetCode Solution18
Translate »