Minimum Increment to Make Array Unique Leetcode Solution

Difficulty Level Medium
Frequently asked in Coursera Databricks eBay Square Twitter Uber
Array Greedy SortingViews 21

Problem Statement:

Minimum Increment to Make Array Unique Leetcode Solution – You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.

Return the minimum number of moves to make every value in nums unique.

Example:

Example 1:

Input:
nums = [1,2,2]
Output: 1

Explanation:

After 1 move, the array could be [1, 2, 3].

Example 2:

Input: 
nums = [3,2,1,2,1,7]
Output: 6

Explanation:

After 6 moves, the array could be [3, 4, 1, 2, 5, 7].

It can be shown with 5 or fewer moves that it is impossible for the array to have all unique values.

 

imageaMinimum Increment to Make Array Unique Leetcode SolutionPin

Approach:

Idea:

  1. First, we need to sort the given array.
  2. When we find the condition that the current element is less than or equal to the previous elements then we need to update the current array element A[i] by A[i-1]+1.
  3. Also, in every iteration we need to keep track of results by result += A[i-1]+ 1 – A[i].
  4. Finally, we need to return the value stored in the result variable.

Code:

C++ Program of Minimum Increment to Make Array Unique:

class Solution {
public:
    int minIncrementForUnique(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        long long c=0;
        for(int i=1;i<nums.size();i++){
            if(nums[i]<=nums[i-1]){
                c+=nums[i-1]+1-nums[i];
                nums[i]=nums[i-1]+1;
            }
        }
        return c;
    }
};

Java Program of  Minimum Increment to Make Array Unique:

class Solution {
    public int minIncrementForUnique(int[] nums) {
        Arrays.sort(nums);
        int c=0;
        for(int i=1;i<nums.length;i++){
            if(nums[i]<=nums[i-1]){
                c+=nums[i-1]+1-nums[i];
                nums[i]=nums[i-1]+1;
            }
        }
        return c;
    }
}

Complexity Analysis for Minimum Increment to Make Array Unique Leetcode Solution:

Time Complexity:

The Time Complexity of the code is O(NlogN ) + O(N) as we need to sort the array first and then traverse through the given array only once.

Space Complexity:

The Space Complexity of the code is O(1) because we don’t need any extra space to solve this problem.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Java program to find the number of Nodes in a Binary Tree2541
3Reverse a string without affecting special characters2523
4Palindrome using Recursion2487
5Delete a node of a linked list at given position2022
6Quick Sort1768
7Insert nodes in a linked list in a sorted way (Ascending Order)1708
8Find elements pair from array whose sum equal to number1686
9Sort Elements by Frequency of Occurrences1672
10Write a program to print all permutations of a given string1655
11Find Minimum Distance Between Two Numbers in an Array1517
12Create a Doubly Linked List1483
13Reverse an Array1461
14Smallest window in a string containing all characters of another string1436
15Recursively remove all adjacent duplicates1404
16Find a Triplet That Sum to a Given Value1391
17First Repeating Element1384
18Sum of numbers in String1361
19Arrange Even and Odd number such that Odd comes after Even1357
20Smallest Positive Number Missing in an Unsorted Array1326
21Check if the Elements of an Array are Consecutive1290
22Detect a loop in the Linked List1272
23Largest Sum Contiguous Subarray1260
24Quick Sort on SIngly Linked List1256
25Subarray with Given Sum1247
26Print all Possible Combinations of R Elements in a given Array of size N1245
27Recursive function to do substring search1245
28Find the Maximum Repeating Number in Array1203
29Find the First and Second Smallest Elements1155
30Binary Tree Level order traversal in Java1154
31Maximum Subarray Sum using Divide and Conquer1141
32Check if two linked lists are identical1140
33Remove characters from first string which are in second1113
34Find Leaders in an Array1092
35Swap nodes in the linked list1083
36Find the second most frequent character1034
37Find the Number Occurring Odd Number of Times in an Array1033
38Arrange given Numbers to Form the Biggest Number II1027
39Given a string find its first non-repeating character1014
40Find Triplet in Array With a Given Sum1002
41Given a sorted array and a number x, find the pair in array whose sum is closest to x993
42Total number of occurrences of a given item in the linked list991
43A Program to check if strings are rotations of each other or not987
44Print all possible words from phone digits972
45Find the Missing Number962
46Rearrange Positive and Negative Numbers Alternatively in Array950
47Longest Palindromic Substring944
48Segregate even and odd nodes in a linked list933
49Print Longest common subsequence924
50Transform one string to another using minimum number of given operations911
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome895
53Rearrange given Array in Maximum Minimum Form876
54Iterative Implementation of Quick Sort867
55Insertion Sort855
56Count Possible Triangles855
57Multiplication of Two Matrices840
58Count of Triplets With Sum Less than Given Value829
59Stock Buy Sell to Maximize Profit827
60Rotate a Linked List825
61Check if the linked list is palindrome824
62Concatenation of two strings803
63Tug of War797
64Print all duplicates in the input string796
65Count Number of Substrings with K Distinct Character’s793
66Find Nearest Greater and Smaller Element782
67Reverse String Without Temporary Variable775
68The Celebrity Problem771
69Remove ‘b’ and ‘ac’ from a given string769
70Find Pythagorean Triplets from Array768
71Find all Common Elements in Given Three Sorted Arrays763
72Remove all duplicates in an unsorted linked list739
73Find the Row with Maximum Number of 1’s737
74Find the subarray whose sum is equal to a given number X736
75Remove Minimum Characters so that Two Strings Become Anagrams735
76Find the Peak Element from an Array733
77Addition of Two Matrices729
78Find Smallest Missing Number in a Sorted Array725
79Generate all Binary Strings Without Consecutive 1’s723
80A Product Array Puzzle720
81Maximum Sum of Non Consecutive Elements709
82Implement Two Stacks in an Array703
83Lexicographic rank of string697
84Check if Two given Matrices are Identical689
85Maximum Product Subarray II686
86Multiplication of Previous and Next680
87Subtraction of Two Matrices673
88Merge K Sorted Arrays and Print Sorted Output667
89Move All the Zeros to the End of the Given Array664
90Form Minimum Number from Given Sequence of D’s and I’s664
91Divide a string in N equal parts663
92Online Algorithm for Checking Palindrome in a Stream663
93Check whether two strings are anagram of each other656
94Remove recurring digits in a given number655
95Sort a stack using a temporary stack651
96Maximum Circular Subarray Sum648
97Sort a linked list that is sorted alternating ascending and descending644
98Subarray and Subsequence638
99Find the Minimum Element in a Sorted and Rotated Array636
100First Circular Tour to Visit all the Petrol Bunks632
101Move last element of the Linked List at first place632
1023Sum Leetcode Solution627
103Compare two strings(linked lists)627
104Largest Subarray with Equal Number of 0’s and 1’s626
105Maximum Element in an Array which is Increasing and then Decreasing626
106Palindrome Permutations of a String624
107Flattening a linked list623
108Palindromes in a given range620
109Majority Element617
110Pangram Checking615
111Minimum insertions to form a shortest palindrome615
112Run length encoding615
113Print all permutations with repetition612
114Elements Appear more than N/K times in Array611
115Minimum Characters to be Added at Front to Make String Palindrome608
116Most repeating character in a string605
117Two Sum Leetcode Solution601
118Rotate string to get lexicographically minimum string600
119Repeated Subsequence of Length Two or More596
120Merge a linked list into another at alternate positions594
121Minimum number of Merge Operations to make an Array Palindrome593
122Rearrange a given linked list in-place593
123Remove all duplicates in a sorted linked list593
124Print all anagrams together in a sequence of words585
125Reorder an Array According to the Given Indexes580
126Pancake Sorting Problem577
127Merge Overlapping Intervals II566
128Clone a Linked List with next and random pointer565
129Longest Palindrome can be Formed by Removing or Rearranging Characters564
130Remove duplicates from a string564
131Transpose of a Matrix564
132Remove Extra Spaces from a String563
133Smallest Palindrome after Replacement563
134Maximum Sum Increasing Subsequence559
135Removing Spaces from a String using stringstream557
136Size of The Subarray With Maximum Sum556
137Check if a given string is a rotation of a palindrome556
138Partition Problem551
139Check whether Strings are K Distance Apart or Not544
140Generate all Binary Strings from Given Pattern544
141Length of Longest valid Substring541
142Delete Last Occurrence537
143Check if Two given Strings are Isomorphic to each other535
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized533
145Insert Node in the Sorted Linked List531
146Program to Toggle all Characters in a String526
147Maximum difference between two elements such as larger element comes after smaller525
148Given string is interleaving of two other strings or not524
149Count Minimum Steps to Get the given Array514
150Number of Smaller Elements on Right Side512
151Check length of a String is Equal to the Number Appended at its Last511
152Check if all Rows of a Matrix are Circular Rotations of Each Other507
153Find Pair with Given Difference505
154Longest Common Prefix using Divide and Conquer504
155Merge sort better than quick sort for linked lists504
156Compare Two Version Numbers499
157Print all interleavings of given two strings496
158Print Reverse of a string (Recursion)495
159Find nth node of the Linked list from the end495
160Find a Fixed Point in a Given Array494
161Median of Two Sorted Arrays LeetCode Solution494
162Sort 0s 1s and 2s in an Array493
163Reorder Array Using Given Indexes491
164Reverse words in a given string490
165Merge two sorted linked lists such that merged list is in reverse order484
166Find the Subarray of given length with Least Average483
167Split linked list using alternate nodes480
168Print all Palindromic Partitions of a String474
169Print string of odd length in ‘X’ format470
170Find Element Using Binary Search in Sorted Array468
171Find K Length Subarray of Maximum Average465
172Swap Kth Node from beginning with Kth Node from End461
173Find Duplicates in an Array in Most Efficient Way457
174print all palindromic partitions453
175Shortest Superstring Problem453
176Check if String Follows Order of Characters by a Pattern or not450
177Maximum Length of Chain Pairs448
178Sort a String According to Another String446
179Flatten a multilevel linked list445
180Sorting a K Sorted Array438
181Program to add two binary digits431
182Recursively print all the sentences that can be formed from list of word lists427
183Find a Sorted Subsequence of size 3426
184Caesar Cipher425
185Longest Span with same Sum in two Binary Arrays II425
186Longest Common Prefix Using Binary Search II425
187Reverse a Linked List in groups424
188Find the two Numbers with Odd Occurrences in an Unsorted Array422
189Kth Non-repeating Character420
190Reverse a Singly Linked List (Iterative/Non-Recursive)418
191Check if String can Become Empty by Recursively Deleting given Substring413
192Rearrange a linked list in Zig-Zag408
193Longest Common Prefix Word by Word Matching408
194Rotate Image by 90 degrees405
195Perfect Reversible String403
196Permutations of a Given String Using STL403
197Pancake Sorting402
198Find First non-repeating character in a string400
199Merging Two Sorted Arrays398
2001`s and 2`s complement of binary number398
201Increasing Subsequence of Length three with Maximum Product394
202Maximum occurring character in a string393
203List items containing all characters of a given word391
204Find the point where a monotonically increasing function becomes positive first time390
205Sort a linked list with 0s, 1s and 2s389
206Four Elements that Sum to Given389
207Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes387
208Longest Common Prefix using Character by Character Matching385
209Count Number of Occurrences in a Sorted Array382
210Palindrome string (number)382
211Valid Parentheses LeetCode Solution380
212Delete N nodes after M377
213Minimum Characters to be Removed to Make a Binary String Alternate376
214Split a string374
215Even Substring Count373
216Recursive Implementation of atoi()371
217Convert a String that is Repetition of a Substring of Length K369
218Sorting the array of strings369
219Check if a Linked list of Strings form a Palindrome365
220Print Shortest Path to Print a String on Screen363
221Maximum Subarray Leetcode Solution361
222Convert string1 to string2 in one edit359
223Print All Distinct Elements of the Array358
224Reverse a String using Stack358
225Matrix Chain Multiplication using Dynamic Programming357
226Nth Character in Concatenated Decimal String356
227Find the first Repeating Number in a Given Array356
228Reverse a singly linked list recursively356
229Count the number of words355
230wildcard character matching355
231Lower Case To Upper Case352
232Can we reverse a linked list in less than O(n) time ?350
233Binary Tree to Doubly linked list347
234Sort Elements by Frequency II344
235Find the Lost Element From a Duplicated Array343
236Longest Common Subsequence with Permutations343
237Merge Two Sorted Arrays340
238Split Four Distinct Strings340
239Find middle of the Linked List335
240Roman to Integer Leetcode Solution334
241Count the Pairs at Same Distance as in English Alphabets334
242Toeplitz Matrix327
243Palindrome Permutation325
244Next Greater Element in an Array324
245Word Search Leetcode Solution324
246Move all negative elements to one side of array322
247N queen problem321
248Searching a node in a Binary Search Tree317
249Find Nth Node315
250Find All Pairs With a Given Difference315
251Sudoku Solver315
252First non Repeating Element314
253String(represents an integer) to value313
254Reverse Bits313
255Number of Islands LeetCode Solution313
256Count Pairs With Given Sum312
257Print all Possible Ways to Break a String in Bracket Form312
258Reverse a String311
259Triplet from three linked lists with given sum311
260Delete a Tree310
261Types of Binary Tree310
262Change Gender of a given String309
263Repeated Substring Pattern309
264How to Efficiently Implement k Stacks in a Single Array?308
265Meeting Rooms II LeetCode Solution307
266Fibonacci numbers306
267Sort an array of strings305
268Delete a node under given conditions305
269Number of sub-strings which recursively add up to 9305
270Longest Palindromic Substring LeetCode Solution304
271Reverse a linked list303
272Min Stack303
273Most Frequent Element in an Array303
274Cuckoo sequence program302
275Dijkstra Algorithm300
276Longest Common Extension297
277Binary Tree297
278Remove spaces from a string296
279House Robber Leetcode Solution296
280Max stack294
281Best Time to Buy and Sell Stock  II Leetcode Solution293
282Subset Leetcode292
283Word Search290
284Shuffle a given Array289
285Remove middle points in a linked list of line segments288
286KMP Algorithm288
287Plus One Leetcode Solution287
288Find, second, frequent, character286
289Minimize the maximum difference between the heights286
290Expression Evaluation286
291Combination Sum Leetcode Solution284
292Search Insert Position Leetcode Solution282
293Reverse words in a string282
294Number Of 1 bits282
295Pair of Positive Negative Values in an Array280
296Evaluation of Postfix Expression280
297Set Matrix Zeroes278
298Sliding Window Technique278
299Valid Palindrome Leetcode Solution276
300Min Stack Leetcode Solution276
301Rabin Karp Algorithm275
302Backspace String Compare273
303Common elements in all rows of a given matrix273
304Subarray with 0 sum273
305Sort linked which is sorted on absolute values272
306Clone a linked list with next and random pointer (Hashing)270
307Merge Sorted Arrays Leetcode Solution270
308Delete middle element of a stack268
309Sqrt(x) Leetcode Solution268
310Reversing a Queue266
311Contains Duplicate II Leetcode Solution265
312Implementation of Deque using Doubly Linked List264
313Count of index pairs with equal elements in an array264
314Product of array except self263
315Combination Sum262
316Contains Duplicate262
317Tower Of Hanoi262
318Pascal Triangle Leetcode262
319Count subarrays with equal number of 1’s and 0’s262
320Reverse individual words262
321String Compression261
322Find Top K (or Most Frequent) Numbers in a Stream261
323Intersection of Two Arrays II Leetcode Solution261
324Count Odd Numbers in an Interval Range Leetcode Solution260
325Page Replacement Algorithms in Operating Systems260
326Minimum swaps required to bring all elements less than or equal to k together260
327How to Delete a Linked List260
328Integer to Roman Leetcode Solution259
329Segregate even and odd numbers258
330Group Words With Same Set of Characters257
331Second Most Repeated Word in a Sequence257
332Postfix to Infix Conversion256
333Single Number Leetcode Solution256
334Minimum Value to Get Positive Step by Step Sum Leetcode Solution255
335Sort elements by frequency255
336Bellman Ford Algorithm255
337Sorting array using Stacks255
338Find sum of non-repeating elements (distinct) elements in an array255
339Sum of minimum and maximum elements of all subarrays of size k254
340Smallest Subarray with k Distinct Numbers254
341Arithmetic Expression Evaluation254
342K-th Smallest Element in a Sorted Matrix253
343Add Binary Leetcode Solution253
344Next Permutation252
345Top K Frequent Words252
346Construct Binary Tree from Given Inorder and Preorder Traversals251
347Maximum Number of Balloons Leetcode Solution251
348Pow(x, n) Leetcode Solution251
349Minimum operation to make all elements equal in array251
350Given two unsorted arrays find all pairs whose sum is x250
351Palindrome Linked List Leetcode Solution250
352Convex Hull Algorithm249
353Scramble String249
354Longest Common Prefix Leetcode Solution249
355Count subarrays having total distinct elements same as original array249
356Special Number248
357First element occurring k times in an array248
358Longest Substring Without Repeating Characters LeetCode Solution247
359Design a stack that supports getMin() in O(1) time and O(1) extra space247
360Kruskal Algorithm247
361Majority Element Leetcode Solution246
362Find Lucky Integer in an Array Leetcode Solution245
363Permutations Leetcode Solution245
364Evaluate Division245
365Find duplicates in a given array when elements are not limited to a range244
366Third Maximum Number Leetcode Solution244
367Maximum possible difference of two subsets of an array243
368Reversing the First K elements of a Queue243
369Spiral Matrix LeetCode Solution243
370Number of Good Pairs Leetcode Solution242
371Reverse a Number Using Stack242
372Running Sum of 1d Array Leetcode Solution242
373Prefix to Infix Conversion242
374Check if two arrays are equal or not241
375Minimum Path Sum241
376Fizz Buzz Leetcode241
377Maximum Subarray241
378Maximal Square240
379Find the Town Judge Leetcode Solution240
380Find Numbers with Even Number of Digits Leetcode Solution240
381Huffman Coding240
382Swap Nodes in Pairs Leetcode Solutions239
383Group Anagrams239
384Maximum Distance Between two Occurrences of Same Element in Array238
385Minimum Absolute Difference Leetcode Solution238
386Find the Closest Palindrome number238
387Single Number238
388Count Primes Leetcode Solutions238
389Minimum Steps to reach target by a Knight238
390Unique Paths238
391Sort Array by Increasing Frequency Leetcode Solution237
392Find top three repeated in array237
393Find the first repeating element in an array of integers236
394Smallest Element Repeated Exactly K Times236
395Range Sum Query 2D – Immutable Leetcode Solution236
396Palindrome Substring Queries236
397Zigzag Conversion235
398Pascal’s Triangle II Leetcode Solution235
399Cumulative Frequency of Count of Each Element in an Unsorted Array235
400Find Number of Employees Under every Employee235
401Convert String To Int235
402Sorting using trivial hash function235
403Leetcode Permutations234
404Find All Numbers Disappeared in an Array Leetcode Solution234
405Implement Stack and Queue using Deque234
406Remove Minimum Number of Elements Such That no Common Element Exist in both Array234
407Count Substrings with equal number of 0s, 1s and 2s233
408Sort Integers by The Number of 1 Bit Leetcode Solution233
409How to Implement Stack Using Priority Queue or Heap?233
410Missing Number Leetcode Solution233
411Power of Two Leetcode Solution233
412Merge Two Sorted Lists Leetcode Solutions233
413Print all subarrays with 0 sum233
414Letter Case Permutation233
415Matrix Diagonal Sum Leetcode Solution233
416Check if Array Contains Contiguous Integers With Duplicates Allowed233
417Length of the largest subarray with contiguous elements232
418Bipartite Graph232
419Expression Contains Redundant Bracket or Not232
420House Robber II Leetcode Solution232
421Print All Distinct Elements of a Given Integer Array231
422Top K Frequent Elements231
423LRU Cache Implementation231
424Happy Number Leetcode Solution231
425Difference between highest and least frequencies in an array231
426Prim’s Algorithm231
427Fizz Buzz231
428Unique Paths Leetcode Solution230
429Decode String230
430Maximum Depth of Binary Tree Leetcode Solution230
431Count pairs from two linked lists whose sum is equal to a given value230
432Subarray Sum Equals k230
433Subset sum problem230
434Sort a stack using recursion230
435Find Winner on a Tic Tac Toe Game Leetcode Solution229
436Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution229
437Find all pairs (a, b) in an array such that a % b = k229
438Search in Rotated Sorted Array Leetcode Solution229
439Find Median from data Stream228
440Check If N and Its Double Exist Leetcode Solution228
441Reverse Integer228
442Coin Change 2 Leetcode Solution228
443Max Consecutive Ones Leetcode Solution228
444Reverse a Stack Using Recursion227
445Nth Catalan Number227
446Capacity To Ship Packages Within D Days Leetcode Solution227
447Find elements which are present in first array and not in second226
448Monotonic Array LeetCode Solution226
449How Many Numbers Are Smaller Than the Current Number Leetcode Solution226
450Subarrays with distinct elements225
451Find the Difference Leetcode Solution225
452Trapping Rain Water Leetcode Solution225
453Find The Duplicate Number225
454Integer to English words225
455Floyd Warshall Algorithm224
456Reverse Vowels of a String Leetcode Solution224
457Edit Distance224
458Priority Queue Using Singly Linked List224
459Pair with given product224
460Text Justification LeetCode Solution224
461Subtract the Product and Sum of Digits of an Integer Leetcode Solution223
462Find Index of Closing Bracket for a Given Opening Bracket in an Expression223
463Fibonacci Number LeetCode Solution223
464Sum of Subarray Ranges Leetcode Solution223
465Target Sum223
466Subarray Sum Equals K LeetCode Solution223
467Valid Parenthesis String223
468Best Time to Buy and Sell Stock III Leetcode Solution223
469Remove Duplicates from Sorted Array Leetcode Solution222
470Count and Say222
471Kth largest element in an Array Leetcode Solutions222
472Reverse a String222
473Find distinct elements common to all rows of a matrix222
474Longest subarray not having more than K distinct elements221
475Find four elements that sum to a given value (Hashmap)220
476The K Weakest Rows in a Matrix Leetcode Solution220
477Find Minimum In Rotated Sorted Array220
478Jump Game Leetcode Solution220
479Find Common Characters Leetcode Solution220
480Delete a Node from linked list without head pointer220
481Design Parking System Leetcode Solution220
482Generate a String With Characters That Have Odd Counts Leetcode Solution220
483Longest Common Prefix using Trie220
484Find any one of the multiple repeating elements in read only array219
485Rearrange a binary string as alternate x and y occurrences219
486MiniMax Algorithm219
487Sorting a Queue without Extra Space219
488Shuffle String Leetcode Solution219
489Prefix to Postfix Conversion219
490Intersection of Two Arrays219
491Multiply Strings Leetcode Solution218
492Count number of triplets with product equal to given number218
493Top View of Binary Tree218
494Flood Fill LeetCode218
495Check if a given array contains duplicate elements within k distance from each other218
496Find missing elements of a range218
497Balanced Binary Tree Leetcode Solution217
498Iterative Tower of Hanoi217
499Substring With Concatenation Of All Words217
500Word Ladder LeetCode Solution217
501Shuffle the Array Leetcode Solution217
502The Stock Span Problem217
503Shortest Palindrome217
504Best Time to Buy and Sell Stock LeetCode Solution217
505Iterative Inorder Traversal of a Binary Tree216
506Merge Two Sorted Linked Lists216
507Priority Queue in C++216
508Next Greater Element I Leetcode Solution216
509Find subarray with given sum (Handles Negative Numbers)216
510Number of Steps to Reduce a Number to Zero Leetcode Solution216
511Degree of an array216
512Excel Sheet Column Number Leetcode Solution216
513Longest Common Subsequence215
514Kids With the Greatest Number of Candies Leetcode Solution215
515Count and Say Leetcode Solution215
516Check for Balanced Parentheses in an Expression215
517Slowest Key Leetcode Solution215
518Implement Stack using Queues215
519Valid Sudoku215
520Move Zeroes LeetCode Solution215
521Concatenation of Array LeetCode Solution215
522Reverse Words in a String III LeetCode Solution215
523Sum of Left Leaves Leetcode Solutions214
524Peak Index in a Mountain Array214
525Longest Common Prefix using Sorting214
526Max Area of Island214
527Recursion214
528K-th Distinct Element in an Array214
529Implement a stack using single queue213
530Minimum Knight Moves LeetCode Solution213
531Merge Overlapping Intervals213
532Kth Largest Element in a Stream Leetcode Solution213
533Find First and Last Position of Element in Sorted Array Leetcode Solution213
534Find the Duplicate Element213
535Postfix to Prefix Conversion213
536Minimum Moves to Equal Array Elements Leetcode Solution212
537Jewels and Stones Leetcode Solution212
538Largest Perimeter Triangle Leetcode Solution212
539Convert array into Zig-Zag fashion212
540Largest Sum Contiguous Subarray212
541Minimum Delete Operations to make all Elements of Array Same212
542Container with Most Water211
543Smallest Subarray With all Occurrences of a Most Frequent Element211
544Gold Mine Problem211
545Group Multiple Occurrence of Array Elements Ordered by first Occurrence211
546Is Subsequence Leetcode Solution211
547Find N Unique Integers Sum up to Zero Leetcode Solution210
548Last Stone Weight210
549Change the Array into Permutation of Numbers From 1 to N210
550Next Greater Frequency Element210
551Check if a queue can be sorted into another queue using a stack210
552Linked List Cycle II LeetCode Solution210
553Hamming Distance210
554Isomorphic Strings Leetcode Solution210
555How to check if two given sets are disjoint?210
556Excel Sheet Column Title Leetcode Solution210
557Arrange given numbers to form the biggest number210
558Convert a normal BST to Balanced BST209
559Find Sum of all unique sub-array sum for a given array209
560Delete Node in a Linked List Leetcode Solution209
561Minimum Bracket Reversals209
562Zigzag Conversion LeetCode Solution209
563Contiguous Array Leetcode209
564Best Time to Buy and Sell Stock208
565Maximum sum rectangle in a 2D matrix208
566Mobile Numeric Keypad Problem208
567Koko Eating Bananas Leetcode Solution208
568Count the number of nodes at given level in a tree using BFS208
569Shuffle an Array208
570Summary Ranges Leetcode Solution208
571Distribute Candies to People Leetcode Solution208
572Minimum Cost to Hire K Workers207
573Implementation of Deque using circular array207
574Length of Last Word Leetcode Solution207
575Valid Anagrams207
576N-th Tribonacci Number Leetcode Solution207
577Trapping Rain Water LeetCode Solution206
5783Sum Closest LeetCode Solution206
579Shortest Path in a Grid with Obstacles Elimination LeetCode Solution206
580Frog Jump Leetcode Solution206
581Maximum path sum in a triangle206
582Find Words That Can Be Formed by Characters Leetcode Solution205
583First negative integer in every window of size k205
584Minimum number of subsets with distinct elements205
585Relative Sort Array Leetcode Solution205
586Number of Provinces Leetcode Solution205
587Remove All Occurrences of a Substring LeetCode Solution205
588Find if an Expression has Duplicate Parenthesis or Not205
589Build Array From Permutation Leetcode Solution205
590Rotate Image LeetCode Solution205
591Integer to Roman205
592Maximum Distance in Array205
593LRU Cache LeetCode Solution204
59401 Matrix LeetCode Solution204
595Minimum Operations to convert X to Y204
596Decode Ways204
597Delete consecutive same words in a sequence204
598Minimum number of distinct elements after removing m items203
599Sieve of Eratosthenes203
600Maximum difference between first and last indexes of an element in array203
601Smallest Good Base203
602Word Pattern203
603Island Perimeter Leetcode Solution203
604Iterative Method to find Height of Binary Tree203
605Maximum Number of Occurrences of a Substring Leetcode Solution203
606Combinations Leetcode Solution203
607Longest Increasing Subsequence203
608Sort Characters By Frequency LeetCode Solution202
609Assign Cookies Leetcode Solution202
610Count all subsequences having product less than K202
611XOR Operation in an Array Leetcode Solution202
612Convert Sorted Array to Binary Search Tree Leetcode Solution201
613Minimum insertions to form a palindrome with permutations allowed201
614Insert Interval Leetcode Solution201
615Find the smallest positive integer value that cannot be represented as sum of any subset of a given array201
616GCD Of Two Numbers201
617Rotate List Leetcode Solution201
618Find minimum difference between any two elements201
619Remove Linked List Elements Leetcode Solution201
620Non-overlapping sum of two sets201
621Applications of Breadth First Search and Depth First Search200
622Tracking current Maximum Element in a Stack200
623Same Tree LeetCode Solution200
624Reverse a stack without using extra space in O(n)200
625Sum of f(a[i], a[j]) over all pairs in an array of n integers200
626The Knapsack Problem200
627Find the Duplicate Number LeetCode Solution199
628Bubble sort using two Stacks199
629Stone Game LeetCode199
630Permutation in String Leetcode Solution199
631Unique Binary Search Trees199
632Printing brackets in Matrix Chain Multiplication Problem198
633Maximum Number of Chocolates to be Distributed Equally Among k Students198
634Find Largest d in Array such that a + b + c = d198
635Count Good Nodes in Binary Tree Leetcode Solution198
636Optimal Account Balancing LeetCode Solution198
637Longest Increasing Path in a Matrix LeetCode Solution198
638K Empty Slots198
639Isomorphic Strings198
640Reorganize String198
641Defanging an IP Address Leetcode Solution197
642First Unique Character in a String LeetCode Solution197
643License Key Formatting Leetcode Solution197
644Letter Combinations of a Phone Number197
645Distance Between Bus Stops Leetcode Solution197
646How to Create Mergable Stack?197
647Minimum Depth of Binary Tree Leetcode Solution196
648Convert an array to reduced form196
649Employee Free Time LeetCode Solution196
650Form minimum number from given sequence196
651Replace Elements with Greatest Element on Right Side Leetcode Solution196
652Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
653Find Pair with Greatest Product in Array195
654Robot Room Cleaner Leetcode Solution195
655Check If It Is a Straight Line Leetcode Solution195
656Word Wrap Problem195
657Sort Array By Parity LeetCode Solution195
658Strobogrammatic Number LeetCode Solution195
659Merge Two Balanced Binary Search Trees195
660Find pairs with given sum such that elements of pair are in different rows195
661House Robber195
662Reducing Dishes LeetCode Solution195
663Moving Average from Data Stream Leetcode Solution194
664Queries for counts of array elements with values in given range194
665Painting Fence Algorithm194
666Kth Missing Positive Number Leetcode Solution194
667Convert a Number to Hexadecimal Leetcode Solution194
668Find Maximum Level sum in Binary Tree193
669Valid Palindrome II Leetcode Solution193
670Partition Labels LeetCode Solution193
671Maximum Product of Two Elements in an Array Leetcode Solution193
672Segregate 0s and 1s in an Array193
673String to Integer (atoi) LeetCode Solution193
674Longest Substring with At Least K Repeating Characters LeetCode Solution193
675K Empty Slots LeetCode193
676Longest Substring with At Most K Distinct Characters LeetCode Solution192
677Largest subarray with equal number of 0s and 1s192
678Power of Four Leetcode Solution192
679Distance of nearest cell having 1 in a binary matrix192
680Maximum Consecutive Numbers Present in an Array192
681Partition Array Into Three Parts With Equal Sum Leetcode Solution192
682Coin Change Problem192
683Print the Fibonacci numbers in reverse order192
684Dynamic Programming Basics191
685Find unique character in a string191
686Longest Span with same Sum in two Binary arrays191
687Reservoir Sampling191
688Valid Palindrome191
689Remove Invalid Parentheses Leetcode Solution191
690Best Time to Buy and Sell Stock with Cooldown Leetcode Solution191
691Check If Two String Arrays are Equivalent Leetcode Solution191
692String Compression LeetCode Solution191
693Find the Distance Value Between Two Arrays Leetcode Solution191
694Sum of All Odd Length Subarrays Leetcode Solution191
695Wiggle Sort190
696Generate all possible sorted arrays from alternate elements of two given sorted arrays190
697Binary Tree Maximum Path Sum LeetCode Solution190
698Reverse Only Letters LeetCode Solution190
699Find the Smallest Divisor given a Threshold Leetcode Solution190
700Find the node with minimum value in a Binary Search Tree190
701Find the largest multiple of 3190
702Number of Dice Rolls With Target Sum LeetCode Solution190
703Path With Maximum Minimum Value LeetCode Solution190
704To Lower Case Leetcode Solution190
705Unique Paths II Leetcode Solution190
706Numbers with prime frequencies greater than or equal to k190
707Flipping an Image LeetCode Solution190
708Inorder Successor of a node in Binary Tree190
709Find Leaves of Binary Tree LeetCode Solution190
710Increasing Decreasing String Leetcode Solution189
711Factorial Trailing Zeroes Leetcode Solution189
712Delete Nth node from the end of the given linked list189
713Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest189
714Maximum Number of Coins You Can Get Leetcode Solution189
715Stack Permutations (Check if an array is stack permutation of other)189
716Sort Array by Increasing Frequency Leetcode Solution188
717Count quadruples from four sorted arrays whose sum is equal to a given value x188
718Snakes and Ladders LeetCode Solution188
719Race Car LeetCode Solution188
720Bulb Switcher LeetCode Solution188
721Edit Distance LeetCode Solution188
722Permutation Sequence LeetCode Solution188
723Subset Sum Leetcode188
724Find whether an array is subset of another array188
725Reversing a Queue using Recursion188
726Non-decreasing Array LeetCode Solution188
727Populating Next Right Pointers in Each Node187
728Find Maximum Depth of Nested Parenthesis in a String187
729Lucky Numbers in a Matrix Leetcode Solution187
730Merge Two Binary Trees LeetCode Solution187
731Maximum 69 Number Leetcode Solution187
732Valid Perfect Square Leetcode Solution187
733BFS vs DFS for Binary Tree187
734Perform String Shifts Leetcode187
735Majority Element II Leetcode Solution187
736Ugly Number Leetcode Solution187
737Binary Tree Zigzag Level Order Traversal LeetCode Solution187
738Student Attendance Record I Leetcode Solution186
739Base 7 Leetcode Solution186
740Keyboard Row Leetcode Solution186
741Remove brackets from an algebraic string containing + and – operators186
742Tiling Problem186
743Find if Path Exists in Graph Leetcode Solution186
744Maximum Length of a Concatenated String with Unique Characters Leetcode Solution186
745Recover Binary Search Tree186
746Best Meeting Point LeetCode Solution186
747Merge Sorted Array LeetCode Solution186
748Program for Bridge and Torch problem185
749Restore IP Addresses Leetcode Solution185
750Find Median from Data Stream LeetCode Solution185
751String comparison containing wildcards185
752Elements to be added so that all elements of a range are present in array185
753Minimum Cost For Tickets Leetcode Solution185
754Symmetric Tree Leetcode Solution185
755Maximum Product of Three Numbers LeetCode Solution185
756Morris Traversal185
757Valid Number185
758Print a Binary Tree in Vertical Order185
759k-th missing element in increasing sequence which is not present in a given sequence185
760Finding K closest element185
761Rank Transform of an Array Leetcode Solution185
762Split a String in Balanced Strings Leetcode Solution185
763Number of NGEs to the Right185
764Binary Tree zigzag level order Traversal185
765Find All Possible Recipes from Given Supplies LeetCode Solution185
766Binomial Coefficient184
767Partition to K Equal Sum Subsets Leetcode Solution184
768Find All Duplicates in an Array LeetCode Solution184
769Construct BST from given Preorder Traversal184
770Evaluate Reverse Polish Notation LeetCode Solution184
771Check If Array Pairs Are Divisible by k LeetCode Solution184
772Add and Search Word – Data structure design LeetCode184
773Maximum Profit in Job Scheduling Leetcode Solution184
774Special Array With X Elements Greater Than or Equal X Leetcode Solution184
775N-Queens LeetCode Solution184
776Check if Two Expressions With Brackets are Same184
777Word Pattern LeetCode Solution184
778Jump Game183
779Brick Wall LeetCode Solution183
780Growable array based stack183
781Priority Queue using doubly linked list183
782Sorted Linked List to Balanced BST183
783Decompress Run-Length Encoded List Leetcode Solution183
784Minimum Distance Between BST Nodes Leetcode Solution183
785Regular Expression Matching183
786Total Numbers With no Repeated Digits in a Range182
787Invert Binary Tree LeetCode Solution182
788Largest rectangular sub-matrix whose sum is 0182
789Minimize Maximum Pair Sum in Array LeetCode Solution182
790One Edit Distance LeetCode Solution182
791Hamming Distance Leetcode Solution182
792Search in a Binary Search Tree Leetcode Solution182
793Maximum Depth of N-ary Tree Leetcode Solution182
794Merge K Sorted Linked Lists182
795Minimum Height Trees182
796Top K Frequent Words LeetCode Solution182
797Kth ancestor of a node in binary tree182
798Largest Rectangle in Histogram LeetCode Solution182
799Nearest Exit from Entrance in Maze LeetCode Solution182
800Form Minimum Number From Given Sequence182
801Sort an array according to the order defined by another array182
802Minimum sum of multiplications of n numbers181
803Check for Palindrome after every character replacement Query181
804Maximum Difference Between Increasing Elements LeetCode Solution181
805Remove Nth Node From End of List Leetcode Solution181
806Final Prices With a Special Discount in a Shop Leetcode Solution181
807Balanced Expression with Replacement181
808Identify and Mark Unmatched Parenthesis in an Expression181
809Minimum Time Visiting All Points Leetcode Solution181
810Number of Islands II LeetCode Solution181
811Number of Days Between Two Dates LeetCode Solution181
812Relative Ranks Leetcode Solution180
813Nested List Weight Sum II LeetCode Solution180
814Repeated Substring Pattern LeetCode Solution180
815Maximum Nesting Depth of the Parentheses Leetcode Solution180
816Linked List Cycle180
817Longest Subarray Having Count of 1s One More than Count of 0s180
818Diagonal Traversal of Binary Tree180
819Circular Queue180
820Queue based approach for first non-repeating character in a stream180
821Deletion in a Binary Tree179
822Search a 2D Matrix II Leetcode Solution179
823Minimum Number of Taps to Open to Water a Garden LeetCode Solution179
824Transpose Graph179
825Minimum time required to rot all oranges179
826Crawler Log Folder Leetcode Solution179
827Minimum Swaps to Make Strings Equal Leetcode Solution179
828Given an Array of Pairs Find all Symmetric Pairs in it179
829Count items common to both the lists but with different prices179
830Split Array Into Consecutive Subsequences178
831Clone Graph LeetCode Solution178
832Sort Array By Parity II Leetcode Solution178
833Permutation Coefficient178
834Number Complement Leetcode Solution178
835Course Schedule II – LeetCode178
836Subarray Product Less Than K LeetCode Solution178
837Lemonade Change Leetcode Solution177
838Daily Temperatures Leetcode Solution177
839Binary Search Tree Search and Insertion177
840LCS (Longest Common Subsequence) of three strings177
841A Space Optimized DP solution for 0-1 Knapsack Problem177
842Find all permuted rows of a given row in a matrix177
843Missing Element in Sorted Array LeetCode Solution177
844Reorder Data in Log Files LeetCode Solution177
845Distinct adjacent elements in an array177
846Check if an Array is Stack Sortable177
847Check if stack elements are pairwise consecutive177
848Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution177
849Minimum Jumps to Reach Home LeetCode Solution177
850Subset with sum divisible by m176
851Tree Traversal (Preorder, Inorder & Postorder)176
852Design Browser History LeetCode Solution176
853Minimum number of jumps to reach end176
854Last Stone Weight II LeetCode Solution176
855Sliding Window Maximum176
856Find Maximum Sum Possible Equal Sum of Three Stacks176
857Insert Delete GetRandom176
858Subsequence of Size K With the Largest Even Sum LeetCode Solution176
859Check if a given array can represent Preorder Traversal of Binary Search Tree176
860Alien Dictionary LeetCode Solution175
861Minimum Sum Path in a Triangle175
862Count Distinct Elements in Every Window of Size K175
863An Interesting Method to generate Binary Numbers from 1 to n175
864Path with maximum average value175
865Valid Parentheses Leetcode Solution175
866Partition List Leetcode Solution175
867Interval Tree175
868Can Place Flowers LeetCode Solution175
869Remove Duplicates from Sorted List II175
870Design a Stack With Increment Operation Leetcode Solution175
871Iterative Preorder Traversal175
872Remove Duplicates from Sorted List LeetCode Solution175
873Union and Intersection of two Linked Lists175
874Guess Number Higher or Lower LeetCode Solution175
875Get Maximum in Generated Array Leetcode Solution174
876Minimum swaps to make sequences increasing174
877Convert BST to Min Heap174
878Spiral Matrix II Leetcode Solution174
879Dividing Array into Pairs With Sum Divisible by K174
880Minesweeper LeetCode Solution174
881Infix to Postfix174
882Brightest Position on Street LeetCode Solution174
883GCDs of given index ranges in an array173
884Find all triplets with zero sum173
885Water Bottles Leetcode Solution173
886Check whether a given Binary Tree is Complete or not173
887Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i173
888Sum of nearest smaller and greater number173
889Find the subarray with least average173
890Sorted Array to Balanced BST173
891Find distance between two nodes of a Binary Tree173
892Pattern Occurrences using Stack173
893Maximum size subarray sum equals k173
894Sequences of given length where every element is more than or equal to twice of previous173
895Level order Traversal in Spiral Form173
896Count ways to reach the nth stair using step 1, 2 or 3173
897Guess Number Higher or Lower II173
898Least Number of Unique Integers after K Removals Leetcode Solution173
899Find the Only Repetitive Element Between 1 to N-1173
900Diagonal Traverse LeetCode Solution173
901Friends Pairing Problem173
902Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution172
903Lexicographical Numbers Leetcode Solution172
904Insert into a Binary Search Tree Leetcode Solution172
905Shortest Word Distance Leetcode Solution172
906Sort Colors172
907Number of Distinct Islands Leetcode Solution172
908Delete And Earn172
909Matrix Chain Multiplication172
910Robot Bounded In Circle LeetCode Solution171
911Alien Dictionary171
912All Unique Triplets that Sum up to a Given Value171
913Median of Two Sorted Arrays171
914Range sum queries without updates171
915Difference Array | Range update query in O(1)171
916Time Based Key-Value Store LeetCode Solution171
917Count Negative Numbers in a Sorted Matrix LeetCode Solution171
918Check if any two intervals overlap among a given set of intervals171
919Diagonal Traversal LeetCode Solution171
920Averages of Levels in Binary Tree171
921Maximum Score After Splitting a String Leetcode Solution171
922Range LCM Queries171
923A program to check if a binary tree is BST or not171
924Iterative Postorder Traversal Using Two Stacks171
925Rearrange an Array Such that arr[i] is equal to i170
926Rearrange Spaces Between Words Leetcode Solution170
927Construct the Rectangle Leetcode Solution170
928Destination City Leetcode Solution170
929Binary Tree Longest Consecutive Sequence LeetCode Solution170
930Three way partitioning of an array around a given range170
931My Calendar I LeetCode Solution170
932Set Matrix Zeroes Leetcode Solution170
933Check if the given array can represent Level Order Traversal of Binary Search Tree170
934K’th Largest Element in BST when modification to BST is not allowed169
935Count Submatrices With All Ones LeetCode Solution169
936Trim a Binary Search Tree169
937Intersection of Two Linked Lists LeetCode Solution169
938Construct Complete Binary Tree from its Linked List Representation169
939Product of Array Except Self LeetCode Solution169
940Vertical sum in a given binary tree169
941Queue using Stacks169
942Number of Equivalent Domino Pairs Leetcode Solution169
943Convert Sorted List to Binary Search Tree169
944Find Common Characters Leetcode Solution169
945Spiral Matrix III LeetCode Solution169
946Merge Two Sorted Lists Leetcode169
947Maximum Frequency Stack Leetcode Solution169
948Three Consecutive Odds Leetcode Solution168
949Palindrome Partitioning Leetcode Solution168
950Word Break168
951Remove Duplicates from Sorted List II LeetCode Solution168
952Strongly Connected Component168
953Largest area rectangular sub-matrix with equal number of 1’s and 0’s168
954Binary array after M range toggle operations168
955Count Subarrays with Same Even and Odd Elements168
956Create Maximum Number167
9573 Sum167
958Special Positions in a Binary Matrix Leetcode Solution167
959Analyze User Website Visit Pattern LeetCode Solution167
960Minimum Height Trees LeetCode Solution167
961Climbing stairs167
962Sign of the Product of an Array LeetCode Solution167
963BFS for Disconnected Graph167
964Queries for GCD of all numbers of an array except elements in a given range167
965Kth Smallest Element in a BST Leetcode Solution167
966Construct BST from its given Level Order Traversal167
967Count pair with Given Sum166
9684Sum166
969Maximum Product Subarray166
970Unique Paths II166
971Stone Game II Leetcode166
972Longest subsequence such that difference between adjacents is one166
973Count subarrays where second highest lie before highest166
974Longest Palindromic Subsequence166
975Combination Sum IV LeetCode Solution166
976Symmetric Tree165
977Merging Intervals165
978Largest Number Leetcode Solution165
979Count Primes in Ranges165
980Depth First Search (DFS) for a Graph165
981Find Maximum of Minimum for Every Window Size in a Given Array165
982Number of palindromic paths in a matrix165
983Serialize and Deserialize Binary Tree165
984Maximize Sum of Array after K Negations Leetcode Solution165
985Design Hit Counter LeetCode Solution165
986Reverse Nodes in K-Group165
987Breadth First Search (BFS) for a Graph165
988Maximum Product of Indexes of Next Greater on Left and Right164
989The Maze III LeetCode Solution164
990Longest Nice Substring LeetCode Solution164
991Find number of pairs in an array such that their XOR is 0164
992Valid Boomerang Leetcode Solution164
993Find the First Circular Tour that visits all the Petrol Pumps164
994Asteroid Collision LeetCode Solution164
995Binary Search Tree Delete Operation164
996Maximum Length of Repeated Subarray164
997Next Permutation Leetcode Solution163
998Graph Valid Tree LeetCode Solution163
999Consecutive Characters LeetCode Solution163
1000K Closest Points to Origin Leetcode Solution163
1001Palindrome Partitioning163
1002Can Make Arithmetic Progression From Sequence Leetcode Solution163
1003String Matching in an Array Leetcode Solution163
1004Print Fibonacci sequence using 2 variables163
1005Height of a generic tree from parent array162
1006Validate Binary Search Tree162
1007Scramble String LeetCode Solution162
1008Collect maximum points in a grid using two traversals162
1009Count pairs from two sorted arrays whose sum is equal to a given value x162
1010Minimum Index Sum of Two Lists162
1011Maximum Sum of 3 Non-Overlapping Subarrays162
1012Find the Difference Leetcode Solution162
1013Decrypt String from Alphabet to Integer Mapping Leetcode Solution162
1014Kth Smallest Element in a Sorted Matrix LeetCode Solution162
1015Length of Longest Fibonacci Subsequence162
1016Maximum Subarray Sum Excluding Certain Elements162
1017Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space162
1018Balanced Binary Tree162
1019The Painter’s Partition Problem162
1020Level Order Traversal of Binary Tree162
1021Find postorder traversal of BST from preorder traversal162
1022Largest divisible pairs subset161
1023Newman-Conway Sequence161
1024Segment Tree161
1025Maximum length subsequence with difference between adjacent elements as either 0 or 1161
1026Merge Sort161
1027Invalid Transactions LeetCode Solution161
1028Shortest Completing Word Leetcode Solution161
1029Generate Parentheses Leetcode Solution161
1030Maximum difference between frequency of two elements such that element having greater frequency is also greater161
1031Print Next Greater Number of Q queries161
1032Find Duplicate Subtrees161
1033K maximum sums of overlapping contiguous sub-arrays161
1034Advantages of BST over Hash Table160
1035Make The String Great Leetcode Solution160
1036Custom Sort String Leetcode Solution160
1037Next Greater Element III LeetCode Solution160
1038Binary Search Tree160
1039Maximum Number of Ways to Partition an Array LeetCode Solution160
1040Number Of Longest Increasing Subsequence160
1041Largest Substring Between Two Equal Characters Leetcode Solution160
1042Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’160
1043Construction of Longest Increasing Subsequence (N log N)160
1044First missing positive160
1045Insertion in a Binary Tree160
1046Compute nCr % p159
1047Find a Peak Element II LeetCode Solution159
1048Friends Of Appropriate Ages LeetCode Solution159
1049Boundary Traversal of binary tree159
1050Rearrange array such that even positioned are greater than odd159
1051Move all negative elements to end in order with extra space allowed159
1052Available Captures for Rook Leetcode Solution159
1053Count minimum steps to get the given desired array159
1054Construct Binary Tree from given Parent Array representation159
1055Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution159
1056Maximum subsequence sum such that no three are consecutive158
1057Kill Process LeetCode Solution158
1058Build an Array With Stack Operations Leetcode Solution158
1059Rearrange array such that even index elements are smaller and odd index elements are greater158
1060Bitwise AND of Numbers Range LeetCode Solution158
1061Boolean Parenthesization Problem158
1062Double the first element and move zero to end158
1063Iterative Depth First Traversal of Graph158
1064Path Sum II LeetCode Solution158
1065Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution157
1066Subarrays with K Different Integers Leetcode Solution157
1067Remove Duplicates from Sorted Array II Leetcode Solution157
1068Find Peak Element157
1069Defanging an IP Address LeetCode Solution157
1070Largest BST Subtree LeetCode Solution157
1071Level order traversal using two Queues157
1072Remove Palindromic Subsequences Leetcode Solution157
1073Recover Binary Search Tree Leetcode Solution157
1074Palindrome Permutation LeetCode Solution156
1075Regular Expression Matching Regular Expression Matching LeetCode Solution156
1076Print Right View of a Binary Tree156
1077Employee Importance LeetCode Solution156
1078Morris Inorder Traversal156
1079Lowest Common Ancestor156
1080Maximum weight transformation of a given string156
1081Smallest Common Region Leetcode Solution156
1082Add two numbers156
1083Super Ugly Number155
1084Ugly Numbers155
1085Number of Closed Islands Leetcode Solution155
1086Minimum Size Subarray Sum155
1087Binary Tree Right Side View LeetCode Solution155
1088Partition Equal Subset Sum155
1089Maximize Distance to Closest Person LeetCode Solution155
1090Increasing Triplet Subsequence LeetCode Solution155
1091Remove duplicates from sorted array155
1092Ugly Number II LeetCode Solution155
1093Implement Trie (Prefix Tree) Leetcode Solution154
1094Find maximum difference between nearest left and right smaller elements154
1095Populating Next Right Pointers in Each Node Leetcode Solution154
1096Bus Routes Leetcode Solution154
1097Valid Tic-Tac-Toe State LeetCode Solution154
1098Palindromic Substrings Leetcode Solution154
1099Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution154
1100Path Sum154
1101Longest Bitonic Subsequence153
1102Reformat The String Leetcode Solution153
1103Sum of Even Numbers After Queries153
1104Print all triplets in sorted array that form AP153
1105Binary Tree Data Structure153
1106Thousand Separator Leetcode Solution153
1107Number of siblings of a given Node in n-ary Tree153
1108Search in Sorted Rotated Array153
1109Find whether a subarray is in form of a mountain or not153
1110Divisible Pairs Counting153
1111Cells with Odd Values in a Matrix LeetCode Solution152
1112Count Largest Group Leetcode Solution152
1113Find Smallest Range Containing Elements from k Lists152
1114Find Three Element From Different Three Arrays Such That a + b + c = sum152
1115Number of Students Doing Homework at a Given Time Leetcode Solution152
1116Find the minimum distance between two numbers152
1117Moser-de Bruijn Sequence152
1118Iterative method to find ancestors of a given binary tree151
1119Day of the Year Leetcode Solution151
1120Distinct Subsequences151
1121Kth Smallest Product of Two Sorted Arrays LeetCode Solution151
1122Level of Each node in a Tree from source node151
1123Search Insert Position151
1124Clone a Binary Tree with Random Pointers151
1125Products of ranges in an array151
1126Root to Leaf path with target sum Leetcode Solutions151
1127Serialize and Deserialize Binary Tree LeetCode Solution150
1128Prime Palindrome LeetCode Solution150
1129Mean of Array After Removing Some Elements Leetcode Solution150
1130Longest Increasing Consecutive Subsequence150
1131Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution150
1132Compare Strings by Frequency of the Smallest Character Leetcode Solution149
1133Queries for Number of Distinct Elements in a Subarray149
1134Maximum Product Subarray149
1135Minimum Absolute Difference in BST Leetcode Solution149
1136Third Maximum Number Leetcode Solution149
1137Construct K Palindrome Strings LeetCode Solution149
1138Bottom View of a Binary Tree149
1139Maximum Depth Of Binary Tree149
1140Topological Sorting149
1141Longest Repeated Subsequence149
1142Find maximum length Snake sequence149
1143Constant time range add operation on an array149
1144Convert BST into a Min-Heap without using array149
1145Minimum sum of squares of character counts in a given string after removing k characters148
1146Diameter of N-Ary Tree LeetCode Solution148
1147Rotate Array148
1148Longest Subarray of 1’s After Deleting One Element LeetCode Solution148
1149Print modified array after executing the commands of addition and subtraction148
1150Web Crawler LeetCode Solution147
1151Cutting a Rod147
1152Maximum Product of Splitted Binary Tree LeetCode Solution147
1153Priority Queue147
1154Subset Sum Problem in O(sum) space147
1155Minimum Score Triangulation of Polygon Leetcode Solution147
1156Find a sorted subsequence of size 3 in linear time147
1157Search an Element in Sorted Rotated Array147
1158Closest Binary Search Tree Value Leetcode Solution147
1159Write Code to Determine if Two Trees are Identical147
1160Count even length binary sequences with same sum of first and second half bits146
1161Find Largest Value in Each Tree Row LeetCode Solution146
1162Delete Nodes and Return Forest Leetcode Solution146
1163Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1164Swap Nodes In Pairs146
1165Maximize sum of consecutive differences in a circular array146
1166Search Suggestions System LeetCode Solution146
1167Count Pairs Whose Products Exist in Array145
1168Minimum Swaps To Make Sequences Increasing LeetCode Solution145
1169Red-Black Tree Introduction145
1170Decision Tree145
1171Minimum Moves to Equal Array Elements LeetCode Solution145
1172Possible Bipartition LeetCode Solution145
1173Contiguous Array LeetCode Solution145
1174Golomb sequence145
1175Transform a BST to Greater sum Tree145
1176Reformat Date LeetCode Solution145
1177Closest Leaf in a Binary Tree LeetCode Solution145
1178K’th Largest element in BST using constant extra space145
1179First Bad Version144
1180Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution144
1181Matchsticks to Square Leetcode Solution144
1182Kth Smallest Number in Multiplication Table Leetcode Solution144
1183Path Crossing Leetcode Solution144
1184Find the smallest binary digit multiple of given number144
1185Minimum Sideway Jumps LeetCode Solution144
1186Reverse a Path in BST using Queue144
1187Maximum Value at a Given Index in a Bounded Array LeetCode Solution144
1188Binary Tree to Binary Search Tree Conversion144
1189Merge two BSTs with limited extra space144
1190Check Array Formation Through Concatenation Leetcode Solution144
1191Sum of Left Leaves LeetCode Solution143
1192Decrease Elements To Make Array Zigzag LeetCode Solution143
1193Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution143
1194Maximum number of segments of lengths a, b and c143
1195Given a binary tree, how do you remove all the half nodes?143
1196Maximum Binary Tree143
1197Replace two consecutive equal values with one greater143
1198Perfect Squares LeetCode Solution143
1199Valid Triangle Number143
1200Concatenation of Array LeetCode Solution142
1201Sliding Window Median Leetcode Solution142
1202Divide Two Integers Leetcode Solution142
1203Factorial Trailing Zeroes LeetCode Solution142
1204Convert Sorted Array to Binary Search Tree LeetCode Solutions142
1205Queue Reconstruction by Height142
1206Maximum sum of pairs with specific difference142
1207Number of Orders in the Backlog Leetcode Solution142
1208Valid Perfect Square LeetCode Solution141
1209Maximum sum bitonic subarray141
1210Swapping Nodes in a Linked List Leetcode Solution141
1211Print n terms of Newman-Conway Sequence141
1212Champagne Tower LeetCode Solution140
1213New 21 Game140
1214How to print maximum number of A’s using given four keys140
1215Kth Smallest Element in a BST140
1216Lowest Common Ancestor in Binary Search Tree140
1217Lowest Common Ancestor of a Binary Tree Leetcode Solution140
1218Maximum sum of a path in a Right Number Triangle139
1219Integer Break LeetCode Solution139
1220Array Queries for multiply replacements and product139
1221Guess The Word139
1222Queries on Probability of Even or Odd Number in given Ranges139
1223Find minimum number of merge operations to make an array palindrome139
1224Merge k Sorted Lists Leetcode Solution139
1225Longest Common Prefix Using Word by Word Matching139
1226Flatten 2D Vector LeetCode Solution139
1227Check if all levels of two Binary Tree are anagrams or not138
1228Moving Stones Until Consecutive Leetcode Solution138
1229Mean of range in array138
1230Graph and its representation138
1231Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution138
1232LRU Cache Leetcode Solution137
1233Contiguous Array137
1234Maximum Array from Two given Arrays Keeping Order Same137
1235Maximum Sum Increasing Subsequence137
1236Design Skiplist LeetCode Solution137
1237Find Minimum in Rotated Sorted Array II LeetCode Solution137
1238Print modified array after multiple array range increment operations137
1239Missing Number137
1240Range Queries for Longest Correct Bracket Subsequence137
1241Range Sum Query using Sparse Table137
1242Maximize Elements Using Another Array136
1243BST to a Tree with Sum of all Smaller Keys136
1244Write a function to get the intersection point of two Linked Lists136
1245Maximum Product Subarray136
1246Largest Plus Sign Leetcode Solution136
1247Min Cost Climbing Stairs LeetCode Solution136
1248Count Subsets Having Distinct Even Numbers135
1249Check in binary array the number represented by a subarray is odd or even135
1250Bold Words in String LeetCode Solution135
1251Minimum Remove to Make Valid Parentheses LeetCode Solution135
1252The kth Factor of n Leetcode Solution135
1253Arithmetic Slices II – Subsequence LeetCode Solution134
1254Parallel Courses II LeetCode Solution134
1255Check if each internal node of a BST has exactly one child134
1256Find k-th smallest element in BST (Order Statistics in BST)134
1257Power of Two134
1258Graph Cloning134
1259Different Ways to Add Parentheses Leetcode Solution133
1260Check if two nodes are on the same path in a Tree133
1261Symmetric Tree LeetCode Solution Leetcode Solution132
1262Image Overlap LeetCode Solution132
1263Minimum Time to Collect All Apples in a Tree LeetCode Solution132
1264Print Ancestors of a Given Binary Tree Node Without Recursion132
1265Smallest Range II Leetcode Solution132
1266Check for Identical BSTs without building the trees132
1267Check Completeness of a Binary Tree LeetCode Solution132
1268Verify Preorder Serialization of a Binary Tree131
1269Orderly Queue LeetCode Solution130
1270Koko Eating Bananas LeetCode Solution130
1271Arranging Coins Leetcode Solution129
1272Merge Sorted Array129
1273Next greater element129
1274Excel Sheet Column Title LeetCode Solution129
1275Longest Substring Without Repeating Characters Leetcode Solution128
1276Vertical Order Traversal of Binary Tree LeetCode Solution128
1277Number of elements less than or equal to a given number in a given subarray128
1278Count and Toggle Queries on a Binary Array128
1279Array Nesting Leetcode Solution127
1280Check If a String Can Break Another String Leetcode Solution126
1281Largest Submatrix With Rearrangements LeetCode Solution126
1282Palindrome Partitioning126
1283Add Two Numbers II Leetcode Solution125
1284Palindrome Number LeetCode Solution125
1285Peeking Iterator LeetCode Solution125
1286Newman–Shanks–Williams prime125
1287Check if X can give change to every person in the Queue125
1288Queries for Decimal Values of Subarrays of a Binary Array125
1289Insert Delete GetRandom O(1) Leetcode Solution125
1290Maximum product of an increasing subsequence124
1291Range Minimum Query (Square Root Decomposition and Sparse Table)124
1292Find maximum average subarray of k length124
1293Find the Winner of the Circular Game LeetCode Solution124
1294Encoded String With Shortest Length LeetCode Solution122
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution122
1296Continuous Subarray Sum LeetCode Solution121
1297Check given array of size n can represent BST of n levels or not121
1298Jump Game IV LeetCode Solution119
1299Reach a Number LeetCode Solution119
1300Binary Tree to Binary Search Tree Conversion using STL set119
1301Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution119
1302Random Pick Index LeetCode Solution119
1303Number of indexes with equal elements in given range118
1304Convert a BST to a Binary Tree such that sum of all greater keys is added to every key117
1305Minimum Number of People to Teach LeetCode Solution117
1306Convert to Base -2 LeetCode Solution116
1307Design A Leaderboard Leetcode Solution115
1308Minimum Total Space Wasted With K Resizing Operations LeetCode Solution115
1309Queries on XOR of greatest odd divisor of the range115
1310Design Underground System Leetcode Solution114
1311Shifting Letters LeetCode Solution112
1312Print Maximum Length Chain of Pairs111
1313Detect Capital Leetcode Solution111
1314Minimum Swaps to Group All 1’s Together Leetcode Solution110
1315Count Sub Islands LeetCode Solution108
1316Top K Frequent Elements LeetCode Solution108
1317Minimum Path Sum Leetcode Solution107
1318Monotonic Array Leetcode Solution105
1319Odd Even Linked List Leetcode Solution104
1320Substring with Concatenation of All Words Leetcode Solution104
1321Longest Common Subsequence LeetCode Solution102
1322Binary Tree Inorder Traversal LeetCode Solution101
1323Decode String Leetcode Solution101
1324Maximum Population Year LeetCode Solution100
1325Find the Town Judge LeetCode Solution100
1326Best Meeting Point LeetCode Solution94
1327Shortest Unsorted Continuous Subarray LeetCode Solution94
1328Rectangle Overlap LeetCode Solution94
1329Maximum Population Year LeetCode Solution93
1330Find the Town Judge LeetCode Solution91
1331Insert into a Sorted Circular Linked List LeetCode Solution90
1332Flatten Binary Tree to Linked List LeetCode Solution89
1333Design Add and Search Words Data Structure LeetCode Solution89
1334Sum Root to Leaf Numbers LeetCode Solution88
1335Stone Game IV LeetCode Solution87
1336Range Sum Query 2D – Immutable LeetCode Solution87
1337Reveal Cards In Increasing Order Leetcode Solution86
1338Valid Triangle Number LeetCode Solution86
1339Is Graph Bipartite? LeetCode Solution86
1340Score of Parenthesis LeetCode Solution84
1341Divide Chocolate LeetCode Solution81
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution75
1343Range Sum of BST LeetCode Solution68
1344Reverse Integer Leetcode Solution66
1345Find K Closest Elements LeetCode Solution64
1346Rotate String LeetCode Solution64
1347Sort Colors LeetCode Solution63
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution61
1349Excel Sheet Column Number LeetCode Solution56
1350Maximum Size Subarray Sum Equals k Leetcode Solution49
1351Camelcase Matching Leetcode Solution45
1352H-Index Leetcode Solution45
1353Valid Anagram Leetcode Solution44
1354Most Stones Removed with Same Row or Column LeetCode Solution43
1355Group Anagrams LeetCode Solution42
1356Container With Most Water LeetCode Solution42
1357Sliding Window Maximum LeetCode Solution42
1358Next Permutation LeetCode Solution41
1359High Five LeetCode Solution41
1360Find Peak Element LeetCode Solution40
1361Binary Search LeetCode Solution40
1362Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution38
1363Paint House LeetCode Solution37
1364Minimum Number of Arrows to Burst Balloons LeetCode Solution36
1365Unique Binary Search Trees LeetCode Solution35
1366Next Greater Element I Leetcode Solution35
1367Flatten Binary Tree to Linked List LeetCode Solution35
1368Valid Triangle Number LeetCode Solution35
1369Group Shifted Strings Leetcode Solution34
1370Sentence Screen Fitting LeetCode Solution33
1371Count Good Nodes in Binary Tree LeetCode Solution32
1372Isomorphic Strings LeetCode Solution32
1373Closest Binary Search Tree Value II LeetCode Solution31
1374Swim in Rising Water LeetCode Solution31
1375Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution31
1376Peak Index in a Mountain Array LeetCode Solution30
1377The Number of Weak Characters in the Game LeetCode Solution30
1378Split Linked List in Parts Leetcode Solution27
1379Validate Stack Sequences LeetCode Solution26
1380Greatest Sum Divisible by Three LeetCode Solution24
1381Single Element in a Sorted Array LeetCode Solution24
1382All Possible Full Binary Trees LeetCode Solution24
1383Best Time to Buy and Sell Stock IV LeetCode Solution24
1384Lowest Common Ancestor of a Binary Search Tree Leetcode Solution23
1385Max Sum of Two Non-Overlapping Subarrays LeetCode Solution23
1386Implement strStr() LeetCode Solution23
1387Implement Rand10() Using Rand7() Leetcode Solution22
1388Break a Palindrome LeetCode Solution22
1389Trapping Rain Water II LeetCode Solution22
1390Minimum Increment to Make Array Unique Leetcode Solution21
1391Stone Game IV LeetCode Solution21
1392Find First and Last Position of Element in Sorted Array LeetCode Solution20
1393Contains Duplicate LeetCode Solution20
1394Detect Squares LeetCode Solution19
1395Remove All Ones With Row and Column Flips Leetcode Solution19
1396Reverse Nodes in k-Group LeetCode Solution17
1397Fibonacci Number LeetCode Solution17
1398Design Bounded Blocking Queue LeetCode Solution16
1399Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution16
1400Invert Binary Tree LeetCode Solution16
1401Total Hamming Distance LeetCode Solution14
1402Candy LeetCode Solution13
1403Unique Paths III LeetCode Solution11
Translate »