Jump Game IV LeetCode Solution

Difficulty Level Hard
Frequently asked in Amazon Google Twitter
Array Breadth First Search Hashing tiktokViews 88

Problem Statement:

Jump Game IV LeetCode Solution says – Given an array of integers arr, you are initially positioned at the first index of the array.

In one step you can jump from the index i to index:

  • i + 1 where: i + 1 < arr.length.
  • i - 1 where: i - 1 >= 0.
  • j where: arr[i] == arr[j] and i != j.

Return the minimum number of steps to reach the last index of the array.

Notice that you can not jump outside of the array at any time.

Examples:

Jump Game IV LeetCode SolutionPin

Input:

 arr = [100,-23,-23,404,100,23,23,23,3,404]

Output:

 3

Explanation:

 You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.

Approach:

Idea:

The problem Jump Game IV can be treated this problem as a graph problem, where every element i has edges to its adjacent elements i.e., i+1 and i-1, and the index of the elements with the same value. Then we can do a simple BFS starting from the first element until we reach the last index of the array.

We will use a hashmap to store the index of the elements having the same value. Also, we need to keep a visited array to prevent visiting an already visited element. For every iteration, we will be incrementing the answer value as it corresponds to one move. As soon as we encounter the n-1 cell we will return the answer. In the code, we have returned ans-1, as one extra move will be there because we are not checking for the n-1 element while inserting it into the queue.

Code:

Jump Game IV C++ Solution:

class Solution {
public:
    int minJumps(vector<int>& arr) {
        unordered_map<int,vector<int>> mp;
        int n = arr.size();
        for(int i=0;i<n;i++){
            mp[arr[i]].push_back(i);
        }
        
        unordered_set<int> vis;
        queue<int> q;
        q.push(0);
        int ans=0;
        while(!q.empty()){
            ans++;
            int x = q.size();
            for(int i=0;i<x;i++){
                int top = q.front();
                if(top==n-1)
                    return ans-1;
                q.pop();
                if(top<0 or top>=n or vis.count(top)){
                    continue;
                }
                for(auto it:mp[arr[top]]){
                    if(it!=top and !vis.count(it))
                        q.push(it);
                }
                
                q.push(top+1);
                q.push(top-1);
                vis.insert(top);
                mp.erase(arr[top]);
            }
        }
        return ans-1;
    }
};

Jump Game IV Java Solution:

class Solution {
    public int minJumps(int[] arr) {
        int n = arr.length;
        HashMap<Integer, List<Integer>> indicesOfValue = new HashMap<>();
        for (int i = 0; i < n; i++)
            indicesOfValue.computeIfAbsent(arr[i], x -> new LinkedList<>()).add(i);
        boolean[] visited = new boolean[n]; visited[0] = true;
        Queue<Integer> q = new LinkedList<>(); q.offer(0);
        int step = 0;
        while (!q.isEmpty()) {
            for (int size = q.size(); size > 0; --size) {
                int i = q.poll();
                if (i == n - 1) return step; // Reached to last index
                List<Integer> next = indicesOfValue.get(arr[i]);
                next.add(i - 1); next.add(i + 1);
                for (int j : next) {
                    if (j >= 0 && j < n && !visited[j]) {
                        visited[j] = true;
                        q.offer(j);
                    }
                }
                next.clear(); // avoid later lookup indicesOfValue arr[i]
            }
            step++;
        }
        return 0;
    }
}

Complexity Analysis of Jump Game IV Leetcode Solution:

  • Time Complexity: The time complexity of the above code is  since we will visit every node at most once, where n = size of the input array.
  • Space Complexity: The space complexity of the above code is for the vis set and hashmap. A good hashmap allows insertion and deletion in average O(1) time hence an efficient operation.

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2815
2Java program to find the number of Nodes in a Binary Tree2497
3Reverse a string without affecting special characters2453
4Delete a node of a linked list at given position1972
5Palindrome using Recursion1773
6Insert nodes in a linked list in a sorted way (Ascending Order)1656
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1625
9Write a program to print all permutations of a given string1599
10Find Minimum Distance Between Two Numbers in an Array1468
11Create a Doubly Linked List1443
12Quick Sort1415
13Reverse an Array1408
14Smallest window in a string containing all characters of another string1393
15Find a Triplet That Sum to a Given Value1354
16Recursively remove all adjacent duplicates1350
17First Repeating Element1334
18Arrange Even and Odd number such that Odd comes after Even1315
19Sum of numbers in String1308
20Smallest Positive Number Missing in an Unsorted Array1277
21Check if the Elements of an Array are Consecutive1250
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1226
24Quick Sort on SIngly Linked List1212
25Subarray with Given Sum1208
26Print all Possible Combinations of R Elements in a given Array of size N1197
27Recursive function to do substring search1193
28Find the Maximum Repeating Number in Array1149
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1099
32Maximum Subarray Sum using Divide and Conquer1097
33Remove characters from first string which are in second1064
34Find Leaders in an Array1057
35Swap nodes in the linked list1030
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II987
38Find the second most frequent character983
39Given a string find its first non-repeating character962
40Find Triplet in Array With a Given Sum956
41Total number of occurrences of a given item in the linked list950
42Given a sorted array and a number x, find the pair in array whose sum is closest to x949
43A Program to check if strings are rotations of each other or not941
44Print all possible words from phone digits927
45Find the Missing Number922
46Rearrange Positive and Negative Numbers Alternatively in Array916
47Longest Palindromic Substring900
48Segregate even and odd nodes in a linked list880
49Print Longest common subsequence877
50Union and Intersection of Two Linked Lists869
51Transform one string to another using minimum number of given operations860
52Rearrange given Array in Maximum Minimum Form841
53Check rearranged string can form a palindrome841
54Count Possible Triangles817
55Iterative Implementation of Quick Sort811
56Multiplication of Two Matrices796
57Check if the linked list is palindrome792
58Count of Triplets With Sum Less than Given Value787
59Rotate a Linked List787
60Stock Buy Sell to Maximize Profit784
61Concatenation of two strings756
62Tug of War754
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string748
65Find Nearest Greater and Smaller Element742
66Find Pythagorean Triplets from Array734
67The Celebrity Problem734
68Reverse String Without Temporary Variable728
69Remove ‘b’ and ‘ac’ from a given string726
70Find all Common Elements in Given Three Sorted Arrays724
71Remove all duplicates in an unsorted linked list707
72Find the Row with Maximum Number of 1’s701
73Find the Peak Element from an Array694
74Find the subarray whose sum is equal to a given number X692
75Insertion Sort685
76Remove Minimum Characters so that Two Strings Become Anagrams683
77Find Smallest Missing Number in a Sorted Array682
78A Product Array Puzzle680
79Addition of Two Matrices680
80Implement Two Stacks in an Array673
81Generate all Binary Strings Without Consecutive 1’s670
82Maximum Sum of Non Consecutive Elements666
83Maximum Product Subarray II658
84Lexicographic rank of string649
85Multiplication of Previous and Next641
86Check if Two given Matrices are Identical641
87Merge K Sorted Arrays and Print Sorted Output631
88Subtraction of Two Matrices630
89Move All the Zeros to the End of the Given Array625
90Online Algorithm for Checking Palindrome in a Stream620
91Divide a string in N equal parts620
92Form Minimum Number from Given Sequence of D’s and I’s619
93Check whether two strings are anagram of each other611
94Remove recurring digits in a given number607
95Maximum Circular Subarray Sum607
96Sort a linked list that is sorted alternating ascending and descending606
97Sort a stack using a temporary stack603
98Find the Minimum Element in a Sorted and Rotated Array602
99Move last element of the Linked List at first place600
100First Circular Tour to Visit all the Petrol Bunks595
101Largest Subarray with Equal Number of 0’s and 1’s592
102Subarray and Subsequence592
103Compare two strings(linked lists)589
104Flattening a linked list589
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array580
108Majority Element572
109Minimum insertions to form a shortest palindrome571
110Run length encoding571
111Print all permutations with repetition570
112Palindromes in a given range569
113Pangram Checking565
114Merge a linked list into another at alternate positions563
115Rearrange a given linked list in-place561
116Remove all duplicates in a sorted linked list561
117Minimum Characters to be Added at Front to Make String Palindrome560
118Minimum number of Merge Operations to make an Array Palindrome557
119Rotate string to get lexicographically minimum string556
120Repeated Subsequence of Length Two or More553
121Most repeating character in a string550
122Print all anagrams together in a sequence of words548
123Reorder an Array According to the Given Indexes546
124Pancake Sorting Problem540
125Clone a Linked List with next and random pointer535
126Merge Overlapping Intervals II534
127Two Sum Leetcode Solution531
128Size of The Subarray With Maximum Sum524
129Transpose of a Matrix522
130Remove Extra Spaces from a String518
131Removing Spaces from a String using stringstream517
132Check if a given string is a rotation of a palindrome515
133Smallest Palindrome after Replacement514
134Partition Problem513
135Remove duplicates from a string512
136Longest Palindrome can be Formed by Removing or Rearranging Characters511
137Maximum Sum Increasing Subsequence510
138Check whether Strings are K Distance Apart or Not499
139Generate all Binary Strings from Given Pattern499
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized497
141Insert Node in the Sorted Linked List496
142Delete Last Occurrence494
143Length of Longest valid Substring494
1443Sum Leetcode Solution493
145Check if Two given Strings are Isomorphic to each other489
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String481
148Given string is interleaving of two other strings or not478
149Count Minimum Steps to Get the given Array477
150Merge sort better than quick sort for linked lists474
151Number of Smaller Elements on Right Side471
152Find Pair with Given Difference469
153Check if all Rows of a Matrix are Circular Rotations of Each Other468
154Check length of a String is Equal to the Number Appended at its Last468
155Find nth node of the Linked list from the end466
156Longest Common Prefix using Divide and Conquer466
157Sort 0s 1s and 2s in an Array457
158Find a Fixed Point in a Given Array455
159Print all interleavings of given two strings454
160Merge two sorted linked lists such that merged list is in reverse order452
161Compare Two Version Numbers452
162Find the Subarray of given length with Least Average451
163Reorder Array Using Given Indexes449
164Reverse words in a given string448
165Split linked list using alternate nodes448
166Print Reverse of a string (Recursion)445
167Median of Two Sorted Arrays LeetCode Solution444
168Print string of odd length in ‘X’ format434
169Find K Length Subarray of Maximum Average430
170Swap Kth Node from beginning with Kth Node from End430
171Find Element Using Binary Search in Sorted Array430
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way424
174print all palindromic partitions418
175Maximum Length of Chain Pairs414
176Flatten a multilevel linked list414
177Shortest Superstring Problem413
178Check if String Follows Order of Characters by a Pattern or not410
179Sorting a K Sorted Array408
180Sort a String According to Another String401
181Longest Span with same Sum in two Binary Arrays II396
182Reverse a Linked List in groups394
183Find a Sorted Subsequence of size 3391
184Program to add two binary digits388
185Find the two Numbers with Odd Occurrences in an Unsorted Array386
186Recursively print all the sentences that can be formed from list of word lists385
187Longest Common Prefix Using Binary Search II382
188Reverse a Singly Linked List (Iterative/Non-Recursive)380
189Rearrange a linked list in Zig-Zag376
190Kth Non-repeating Character376
191Check if String can Become Empty by Recursively Deleting given Substring374
192Caesar Cipher374
193Pancake Sorting372
194Rotate Image by 90 degrees369
195Longest Common Prefix Word by Word Matching367
196Permutations of a Given String Using STL363
197Perfect Reversible String363
198Increasing Subsequence of Length three with Maximum Product361
199Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes360
200Merging Two Sorted Arrays360
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
203Find First non-repeating character in a string355
2041`s and 2`s complement of binary number355
205Four Elements that Sum to Given352
206Delete N nodes after M350
207List items containing all characters of a given word350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array343
210Split a string338
211Palindrome string (number)338
212Minimum Characters to be Removed to Make a Binary String Alternate337
213Check if a Linked list of Strings form a Palindrome332
214Recursive Implementation of atoi()330
215Sorting the array of strings329
216Print All Distinct Elements of the Array328
217Convert a String that is Repetition of a Substring of Length K327
218Even Substring Count324
219Find the first Repeating Number in a Given Array324
220Reverse a singly linked list recursively323
221Valid Parentheses LeetCode Solution322
222Binary Tree to Doubly linked list321
223Print Shortest Path to Print a String on Screen320
224Maximum occurring character in a string320
225Can we reverse a linked list in less than O(n) time ?318
226Nth Character in Concatenated Decimal String316
227Convert string1 to string2 in one edit315
228Sort Elements by Frequency II315
229Reverse a String using Stack315
230Lower Case To Upper Case313
231wildcard character matching313
232Merge Two Sorted Arrays310
233Maximum Subarray Leetcode Solution309
234Find the Lost Element From a Duplicated Array309
235Count the number of words308
236Split Four Distinct Strings307
237Find middle of the Linked List304
238Longest Common Subsequence with Permutations298
239Count the Pairs at Same Distance as in English Alphabets298
240Next Greater Element in an Array293
241Matrix Chain Multiplication using Dynamic Programming291
242Palindrome Permutation286
243Find Nth Node283
244Searching a node in a Binary Search Tree283
245Find All Pairs With a Given Difference281
246Triplet from three linked lists with given sum280
247Roman to Integer Leetcode Solution279
248Delete a Tree279
249String(represents an integer) to value275
250Reverse a String275
251Print all Possible Ways to Break a String in Bracket Form274
252Binary Tree271
253Change Gender of a given String270
254Delete a node under given conditions270
255Reverse Bits270
256Sort an array of strings268
257Word Search Leetcode Solution267
258Number of sub-strings which recursively add up to 9265
259How to Efficiently Implement k Stacks in a Single Array?265
260Remove middle points in a linked list of line segments264
261Longest Common Extension263
262Toeplitz Matrix261
263Remove spaces from a string261
264Meeting Rooms II LeetCode Solution261
265Count Pairs With Given Sum260
266First non Repeating Element259
267Shuffle a given Array257
268Repeated Substring Pattern257
269Longest Palindromic Substring LeetCode Solution257
270Move all negative elements to one side of array255
271N queen problem253
272Min Stack252
273Find, second, frequent, character249
274Dijkstra Algorithm248
275Cuckoo sequence program247
276Number of Islands LeetCode Solution246
277Clone a linked list with next and random pointer (Hashing)245
278Most Frequent Element in an Array244
279Minimize the maximum difference between the heights243
280Sort linked which is sorted on absolute values243
281Max stack243
282House Robber Leetcode Solution241
283Expression Evaluation241
284Search Insert Position Leetcode Solution240
285Fibonacci numbers239
286Valid Palindrome Leetcode Solution237
287How to Delete a Linked List237
288KMP Algorithm236
289Min Stack Leetcode Solution235
290Sudoku Solver235
291Plus One Leetcode Solution234
292Word Search234
293Evaluation of Postfix Expression233
294Subset Leetcode233
295Combination Sum Leetcode Solution232
296Number Of 1 bits232
297Reverse words in a string232
298Merge Sorted Arrays Leetcode Solution226
299Backspace String Compare226
300Rabin Karp Algorithm225
301Pair of Positive Negative Values in an Array224
302Set Matrix Zeroes223
303Sqrt(x) Leetcode Solution222
304Reversing a Queue222
305Contains Duplicate II Leetcode Solution222
306Tower Of Hanoi222
307Combination Sum220
308Subarray with 0 sum220
309Product of array except self219
310Common elements in all rows of a given matrix218
311Integer to Roman Leetcode Solution217
312Intersection of Two Arrays II Leetcode Solution216
313Pascal Triangle Leetcode215
314Delete middle element of a stack214
315Reverse individual words214
316String Compression213
317Construct Binary Tree from Given Inorder and Preorder Traversals213
318Sliding Window Technique212
319Find Top K (or Most Frequent) Numbers in a Stream212
320Count subarrays with equal number of 1’s and 0’s212
321Minimum swaps required to bring all elements less than or equal to k together212
322Pow(x, n) Leetcode Solution211
323Bellman Ford Algorithm211
324Add Binary Leetcode Solution211
325Arithmetic Expression Evaluation210
326Next Permutation209
327Page Replacement Algorithms in Operating Systems209
328Second Most Repeated Word in a Sequence209
329Kruskal Algorithm208
330Count of index pairs with equal elements in an array208
331Single Number Leetcode Solution208
332Palindrome Linked List Leetcode Solution208
333Segregate even and odd numbers208
334Find sum of non-repeating elements (distinct) elements in an array208
335Contains Duplicate207
336Implementation of Deque using Doubly Linked List207
337Design a stack that supports getMin() in O(1) time and O(1) extra space207
338Postfix to Infix Conversion207
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution207
340Maximum Number of Balloons Leetcode Solution206
341Count Odd Numbers in an Interval Range Leetcode Solution206
342Sort elements by frequency205
343Group Words With Same Set of Characters204
344Longest Common Prefix Leetcode Solution204
345Maximum Subarray203
346K-th Smallest Element in a Sorted Matrix203
347Permutations Leetcode Solution203
348Convex Hull Algorithm203
349Third Maximum Number Leetcode Solution203
350Find Lucky Integer in an Array Leetcode Solution202
351Longest Substring Without Repeating Characters LeetCode Solution202
352Find Numbers with Even Number of Digits Leetcode Solution202
353Minimum operation to make all elements equal in array201
354Majority Element Leetcode Solution201
355Spiral Matrix LeetCode Solution201
356Sorting array using Stacks201
357Top K Frequent Words201
358Sum of minimum and maximum elements of all subarrays of size k201
359Count subarrays having total distinct elements same as original array200
360Find the Town Judge Leetcode Solution200
361Swap Nodes in Pairs Leetcode Solutions200
362Scramble String200
363Smallest Subarray with k Distinct Numbers199
364Evaluate Division198
365Special Number197
366Reverse a Number Using Stack197
367First element occurring k times in an array197
368Merge Two Sorted Lists Leetcode Solutions196
369Check if two arrays are equal or not196
370Given two unsorted arrays find all pairs whose sum is x196
371Pascal’s Triangle II Leetcode Solution195
372Best Time to Buy and Sell Stock  II Leetcode Solution195
373Group Anagrams195
374Minimum Path Sum195
375Prefix to Infix Conversion195
376Search in Rotated Sorted Array Leetcode Solution195
377Find duplicates in a given array when elements are not limited to a range194
378Reversing the First K elements of a Queue194
379Huffman Coding194
380Number of Good Pairs Leetcode Solution194
381Count Primes Leetcode Solutions194
382Power of Two Leetcode Solution193
383Minimum Absolute Difference Leetcode Solution193
384Maximum Distance Between two Occurrences of Same Element in Array192
385Sort Array by Increasing Frequency Leetcode Solution192
386Minimum Steps to reach target by a Knight192
387House Robber II Leetcode Solution192
388Missing Number Leetcode Solution192
389Maximum possible difference of two subsets of an array191
390Maximal Square191
391Single Number191
392Fizz Buzz Leetcode191
393Range Sum Query 2D – Immutable Leetcode Solution191
394Top K Frequent Elements190
395Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution190
396Max Consecutive Ones Leetcode Solution189
397Unique Paths Leetcode Solution189
398Matrix Diagonal Sum Leetcode Solution189
399Running Sum of 1d Array Leetcode Solution189
400Sorting using trivial hash function189
401Find All Numbers Disappeared in an Array Leetcode Solution189
402Leetcode Permutations188
403Palindrome Substring Queries188
404Subarray Sum Equals K LeetCode Solution188
405Zigzag Conversion187
406Difference between highest and least frequencies in an array187
407Coin Change 2 Leetcode Solution187
408Find The Duplicate Number187
409Expression Contains Redundant Bracket or Not187
410Find Winner on a Tic Tac Toe Game Leetcode Solution187
411Unique Paths187
412Fibonacci Number LeetCode Solution187
413Happy Number Leetcode Solution187
414Sort Integers by The Number of 1 Bit Leetcode Solution187
415How to Implement Stack Using Priority Queue or Heap?187
416Subset sum problem187
417Check if Array Contains Contiguous Integers With Duplicates Allowed187
418Decode String186
419Find the Closest Palindrome number186
420How Many Numbers Are Smaller Than the Current Number Leetcode Solution186
421Reverse Vowels of a String Leetcode Solution186
422Letter Case Permutation186
423Subtract the Product and Sum of Digits of an Integer Leetcode Solution185
424Subarray Sum Equals k185
425Find top three repeated in array185
426Smallest Element Repeated Exactly K Times185
427Cumulative Frequency of Count of Each Element in an Unsorted Array185
428Find Number of Employees Under every Employee185
429Reverse Integer185
430Print All Distinct Elements of a Given Integer Array185
431Nth Catalan Number185
432Convert String To Int185
433Monotonic Array LeetCode Solution185
434Reverse Words in a String III LeetCode Solution184
435Remove Duplicates from Sorted Array Leetcode Solution184
436Best Time to Buy and Sell Stock III Leetcode Solution184
437Check If N and Its Double Exist Leetcode Solution184
438Sort a stack using recursion184
439Length of the largest subarray with contiguous elements184
440Trapping Rain Water Leetcode Solution184
441Shuffle the Array Leetcode Solution184
442Capacity To Ship Packages Within D Days Leetcode Solution183
443Find the first repeating element in an array of integers183
444Bipartite Graph183
445Find Median from data Stream183
446Implement Stack and Queue using Deque182
447LRU Cache Implementation182
448Find Minimum In Rotated Sorted Array182
449Find the Duplicate Element182
450Generate a String With Characters That Have Odd Counts Leetcode Solution182
451Priority Queue Using Singly Linked List182
452Maximum Depth of Binary Tree Leetcode Solution182
453Prim’s Algorithm182
454Kth largest element in an Array Leetcode Solutions181
455Minimum Moves to Equal Array Elements Leetcode Solution181
456Sum of Subarray Ranges Leetcode Solution181
457Reverse a Stack Using Recursion181
458Subarrays with distinct elements181
459Merge Two Sorted Linked Lists181
460Integer to English words181
461Count Substrings with equal number of 0s, 1s and 2s181
462Find all pairs (a, b) in an array such that a % b = k180
463Count pairs from two linked lists whose sum is equal to a given value180
464The K Weakest Rows in a Matrix Leetcode Solution180
465Delete a Node from linked list without head pointer180
466Sorting a Queue without Extra Space180
467Fizz Buzz180
468Remove Minimum Number of Elements Such That no Common Element Exist in both Array179
469Edit Distance179
470Find elements which are present in first array and not in second179
471Find Common Characters Leetcode Solution179
472Longest Common Subsequence179
473Find the Difference Leetcode Solution179
474Target Sum178
475Next Greater Element I Leetcode Solution178
476Reverse a String178
477Degree of an array178
478Concatenation of Array LeetCode Solution178
479MiniMax Algorithm178
480Reverse a linked list178
481Count and Say178
482Find First and Last Position of Element in Sorted Array Leetcode Solution177
483Kth Largest Element in a Stream Leetcode Solution177
484Text Justification LeetCode Solution177
485Print all subarrays with 0 sum177
486Floyd Warshall Algorithm177
487Number of Steps to Reduce a Number to Zero Leetcode Solution177
488Excel Sheet Column Number Leetcode Solution177
489Longest Common Prefix using Trie176
490Balanced Binary Tree Leetcode Solution176
491Kids With the Greatest Number of Candies Leetcode Solution176
492Multiply Strings Leetcode Solution176
493Merge Overlapping Intervals176
494Iterative Tower of Hanoi175
495Design Parking System Leetcode Solution175
496Koko Eating Bananas Leetcode Solution175
497Top View of Binary Tree175
498Priority Queue in C++175
499Longest subarray not having more than K distinct elements175
500Pair with given product175
501Flood Fill LeetCode175
502Word Ladder LeetCode Solution175
503Max Area of Island174
504Shortest Palindrome174
505Move Zeroes LeetCode Solution174
506Postfix to Prefix Conversion174
507Count and Say Leetcode Solution174
508Prefix to Postfix Conversion174
509Mobile Numeric Keypad Problem173
510Implement a stack using single queue173
511Shuffle String Leetcode Solution173
512Peak Index in a Mountain Array173
513Zigzag Conversion LeetCode Solution173
514Valid Parenthesis String173
515Intersection of Two Arrays173
516Find subarray with given sum (Handles Negative Numbers)173
517The Stock Span Problem173
518Find N Unique Integers Sum up to Zero Leetcode Solution173
519Recursion173
520Check if a given array contains duplicate elements within k distance from each other173
521Find four elements that sum to a given value (Hashmap)173
522Length of Last Word Leetcode Solution173
523Implement Stack using Queues173
524Count number of triplets with product equal to given number172
525Find missing elements of a range172
526Substring With Concatenation Of All Words172
527Slowest Key Leetcode Solution172
528Find distinct elements common to all rows of a matrix172
529Convert array into Zig-Zag fashion172
530Contiguous Array Leetcode172
531Iterative Inorder Traversal of a Binary Tree172
532Find Index of Closing Bracket for a Given Opening Bracket in an Expression171
533Best Time to Buy and Sell Stock171
534Last Stone Weight171
535Longest Common Prefix using Sorting171
536Find any one of the multiple repeating elements in read only array170
537Container with Most Water170
538K-th Distinct Element in an Array170
539Maximum sum rectangle in a 2D matrix170
540Largest Perimeter Triangle Leetcode Solution170
541Delete Node in a Linked List Leetcode Solution170
542Jump Game Leetcode Solution170
543Smallest Subarray With all Occurrences of a Most Frequent Element170
544Relative Sort Array Leetcode Solution170
545Convert a normal BST to Balanced BST170
546Valid Sudoku169
547Next Greater Frequency Element169
548Minimum Bracket Reversals169
549Excel Sheet Column Title Leetcode Solution169
550First negative integer in every window of size k168
551Shuffle an Array168
552Build Array From Permutation Leetcode Solution168
553Check for Balanced Parentheses in an Expression168
554Arrange given numbers to form the biggest number168
555Assign Cookies Leetcode Solution168
556Group Multiple Occurrence of Array Elements Ordered by first Occurrence167
557The Knapsack Problem167
558Distribute Candies to People Leetcode Solution167
559Is Subsequence Leetcode Solution167
560Sum of Left Leaves Leetcode Solutions167
561Implementation of Deque using circular array167
562Find Words That Can Be Formed by Characters Leetcode Solution167
563Change the Array into Permutation of Numbers From 1 to N167
564Shortest Path in a Grid with Obstacles Elimination LeetCode Solution167
565Minimum Operations to convert X to Y167
566Rearrange a binary string as alternate x and y occurrences167
567Integer to Roman167
568Isomorphic Strings Leetcode Solution167
569Decode Ways166
57001 Matrix LeetCode Solution166
571Jewels and Stones Leetcode Solution166
572Linked List Cycle II LeetCode Solution166
573N-th Tribonacci Number Leetcode Solution166
574Valid Anagrams166
575How to check if two given sets are disjoint?165
576Maximum path sum in a triangle165
577Convert Sorted Array to Binary Search Tree Leetcode Solution165
578Hamming Distance165
579Island Perimeter Leetcode Solution165
580Unique Binary Search Trees165
581Count the number of nodes at given level in a tree using BFS165
582Gold Mine Problem165
583Minimum Delete Operations to make all Elements of Array Same165
584Rotate List Leetcode Solution165
585Trapping Rain Water LeetCode Solution164
586Sieve of Eratosthenes164
587Remove Linked List Elements Leetcode Solution164
588Same Tree LeetCode Solution164
589Find the smallest positive integer value that cannot be represented as sum of any subset of a given array164
590Maximum difference between first and last indexes of an element in array164
591Combinations Leetcode Solution164
592Minimum Knight Moves LeetCode Solution164
593Maximum Distance in Array164
5943Sum Closest LeetCode Solution164
595Summary Ranges Leetcode Solution163
596LRU Cache LeetCode Solution163
597Insert Interval Leetcode Solution163
598Count all subsequences having product less than K163
599Distance Between Bus Stops Leetcode Solution163
600Minimum number of subsets with distinct elements163
601Find minimum difference between any two elements163
602K Empty Slots LeetCode162
603Applications of Breadth First Search and Depth First Search162
604Rotate Image LeetCode Solution162
605Find Sum of all unique sub-array sum for a given array162
606Minimum insertions to form a palindrome with permutations allowed162
607Maximum Number of Chocolates to be Distributed Equally Among k Students162
608Printing brackets in Matrix Chain Multiplication Problem161
609Best Time to Buy and Sell Stock LeetCode Solution161
610Minimum number of distinct elements after removing m items161
611Frog Jump Leetcode Solution161
612Word Pattern161
613Replace Elements with Greatest Element on Right Side Leetcode Solution161
614Find if an Expression has Duplicate Parenthesis or Not161
615Find Maximum Level sum in Binary Tree160
616Distance of nearest cell having 1 in a binary matrix160
617Stone Game LeetCode160
618Remove All Occurrences of a Substring LeetCode Solution160
619Word Wrap Problem160
620Find the Duplicate Number LeetCode Solution160
621House Robber160
622Permutation in String Leetcode Solution160
623License Key Formatting Leetcode Solution160
624Minimum Depth of Binary Tree Leetcode Solution160
625Sort Array By Parity LeetCode Solution160
626Minimum Cost to Hire K Workers160
627Sort Characters By Frequency LeetCode Solution159
628Longest Increasing Subsequence159
629Painting Fence Algorithm159
630Defanging an IP Address Leetcode Solution159
631XOR Operation in an Array Leetcode Solution159
632Segregate 0s and 1s in an Array159
633Maximum Consecutive Numbers Present in an Array159
634Coin Change Problem158
635Check If It Is a Straight Line Leetcode Solution158
636Kth Missing Positive Number Leetcode Solution158
637Reverse a stack without using extra space in O(n)158
638Non-overlapping sum of two sets158
639Smallest Good Base158
640Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest158
641Queries for counts of array elements with values in given range157
642Iterative Method to find Height of Binary Tree157
643Optimal Account Balancing LeetCode Solution157
644Longest Substring with At Most K Distinct Characters LeetCode Solution157
645Isomorphic Strings157
646Best Time to Buy and Sell Stock with Cooldown Leetcode Solution157
647Valid Palindrome II Leetcode Solution157
648Count Good Nodes in Binary Tree Leetcode Solution157
649Reorganize String157
650Tracking current Maximum Element in a Stack156
651GCD Of Two Numbers156
652Number of Provinces Leetcode Solution156
653Employee Free Time LeetCode Solution156
654Binary Tree Zigzag Level Order Traversal LeetCode Solution156
655Check If Two String Arrays are Equivalent Leetcode Solution156
656Power of Four Leetcode Solution156
657Wiggle Sort156
658Partition Labels LeetCode Solution156
659Merge Two Balanced Binary Search Trees156
660Sum of All Odd Length Subarrays Leetcode Solution156
661Strobogrammatic Number LeetCode Solution156
662How to Create Mergable Stack?156
663Find Largest d in Array such that a + b + c = d156
664Longest Substring with At Least K Repeating Characters LeetCode Solution155
665Letter Combinations of a Phone Number155
666K Empty Slots155
667Inorder Successor of a node in Binary Tree155
668Check if a queue can be sorted into another queue using a stack155
669BFS vs DFS for Binary Tree155
670Sum of f(a[i], a[j]) over all pairs in an array of n integers155
671Flipping an Image LeetCode Solution155
672Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
673Convert an array to reduced form155
674Moving Average from Data Stream Leetcode Solution155
675Populating Next Right Pointers in Each Node154
676Largest Sum Contiguous Subarray154
677Delete consecutive same words in a sequence154
678Increasing Decreasing String Leetcode Solution154
679Form minimum number from given sequence154
680Subset Sum Leetcode154
681Lucky Numbers in a Matrix Leetcode Solution154
682Path With Maximum Minimum Value LeetCode Solution154
683Maximum Number of Occurrences of a Substring Leetcode Solution154
684Maximum Number of Coins You Can Get Leetcode Solution154
685Find the Distance Value Between Two Arrays Leetcode Solution154
686Ugly Number Leetcode Solution154
687Reservoir Sampling153
688Sort Array by Increasing Frequency Leetcode Solution153
689Find the Smallest Divisor given a Threshold Leetcode Solution153
690Reducing Dishes LeetCode Solution153
691Majority Element II Leetcode Solution153
692Maximum Product of Three Numbers LeetCode Solution153
693Find Leaves of Binary Tree LeetCode Solution153
694Hamming Distance Leetcode Solution153
695Longest Increasing Path in a Matrix LeetCode Solution153
696To Lower Case Leetcode Solution153
697Valid Palindrome153
698Print the Fibonacci numbers in reverse order153
699String to Integer (atoi) LeetCode Solution153
700Permutation Sequence LeetCode Solution152
701Add and Search Word – Data structure design LeetCode152
702Number of Dice Rolls With Target Sum LeetCode Solution152
703Factorial Trailing Zeroes Leetcode Solution152
704Find the node with minimum value in a Binary Search Tree152
705Construct BST from given Preorder Traversal152
706Delete Nth node from the end of the given linked list152
707Unique Paths II Leetcode Solution152
708Reverse Only Letters LeetCode Solution152
709Reversing a Queue using Recursion152
710Numbers with prime frequencies greater than or equal to k152
711Remove Invalid Parentheses Leetcode Solution152
712Find pairs with given sum such that elements of pair are in different rows152
713Partition Array Into Three Parts With Equal Sum Leetcode Solution152
714Largest subarray with equal number of 0s and 1s151
715Edit Distance LeetCode Solution151
716Decompress Run-Length Encoded List Leetcode Solution151
717Dynamic Programming Basics151
718Valid Perfect Square Leetcode Solution151
719Recover Binary Search Tree151
720Convert a Number to Hexadecimal Leetcode Solution151
721Binary Tree zigzag level order Traversal151
722Find whether an array is subset of another array151
723Deletion in a Binary Tree150
724Longest Span with same Sum in two Binary arrays150
725Restore IP Addresses Leetcode Solution150
726Binomial Coefficient150
727Maximum Product of Two Elements in an Array Leetcode Solution150
728Minimum Cost For Tickets Leetcode Solution150
729Maximum 69 Number Leetcode Solution149
730Find Pair with Greatest Product in Array149
731Minimum Height Trees149
732Merge Two Binary Trees LeetCode Solution149
733Find the largest multiple of 3149
734Keyboard Row Leetcode Solution149
735Find Maximum Depth of Nested Parenthesis in a String149
736Merge K Sorted Linked Lists149
737Find unique character in a string149
738Rank Transform of an Array Leetcode Solution149
739Bubble sort using two Stacks149
740Minimum Distance Between BST Nodes Leetcode Solution149
741Elements to be added so that all elements of a range are present in array148
742Symmetric Tree Leetcode Solution148
743Race Car LeetCode Solution148
744Word Pattern LeetCode Solution148
745Remove brackets from an algebraic string containing + and – operators148
746Morris Traversal148
747Bulb Switcher LeetCode Solution148
748Invert Binary Tree LeetCode Solution148
749Growable array based stack148
750Sorted Linked List to Balanced BST148
751Perform String Shifts Leetcode148
752Stack Permutations (Check if an array is stack permutation of other)148
753Best Meeting Point LeetCode Solution148
754Finding K closest element148
755Robot Room Cleaner Leetcode Solution147
756k-th missing element in increasing sequence which is not present in a given sequence147
757Count quadruples from four sorted arrays whose sum is equal to a given value x147
758Find All Duplicates in an Array LeetCode Solution147
759Non-decreasing Array LeetCode Solution147
760Generate all possible sorted arrays from alternate elements of two given sorted arrays147
761Student Attendance Record I Leetcode Solution147
762Minimum time required to rot all oranges147
763Diagonal Traversal of Binary Tree147
764Binary Tree Maximum Path Sum LeetCode Solution147
765Kth ancestor of a node in binary tree147
766Jump Game147
767Search in a Binary Search Tree Leetcode Solution146
768Remove Nth Node From End of List Leetcode Solution146
769Largest Rectangle in Histogram LeetCode Solution146
770Snakes and Ladders LeetCode Solution146
771N-Queens LeetCode Solution146
772Nested List Weight Sum II LeetCode Solution146
773Evaluate Reverse Polish Notation LeetCode Solution146
774Valid Number146
775Maximum Depth of N-ary Tree Leetcode Solution146
776String Compression LeetCode Solution146
777Maximum Length of a Concatenated String with Unique Characters Leetcode Solution146
778Program for Bridge and Torch problem146
779Minimum number of jumps to reach end146
780Largest rectangular sub-matrix whose sum is 0146
781Tiling Problem146
782Base 7 Leetcode Solution145
783Check for Palindrome after every character replacement Query145
784Interval Tree145
785Special Array With X Elements Greater Than or Equal X Leetcode Solution145
786Number of NGEs to the Right145
787Count items common to both the lists but with different prices145
788First Unique Character in a String LeetCode Solution145
789Maximum Difference Between Increasing Elements LeetCode Solution145
790Find Median from Data Stream LeetCode Solution145
791Queue based approach for first non-repeating character in a stream145
792Linked List Cycle145
793Search a 2D Matrix II Leetcode Solution145
794Number of Islands II LeetCode Solution145
795Sort an array according to the order defined by another array145
796Minimize Maximum Pair Sum in Array LeetCode Solution145
797Partition to K Equal Sum Subsets Leetcode Solution145
798Find if Path Exists in Graph Leetcode Solution145
799A Space Optimized DP solution for 0-1 Knapsack Problem144
800Transpose Graph144
801Crawler Log Folder Leetcode Solution144
802Check if Two Expressions With Brackets are Same144
803Split a String in Balanced Strings Leetcode Solution144
804Alien Dictionary LeetCode Solution144
805Circular Queue144
806Final Prices With a Special Discount in a Shop Leetcode Solution144
807Print a Binary Tree in Vertical Order144
808Check If Array Pairs Are Divisible by k LeetCode Solution144
809Minimum swaps to make sequences increasing144
810Remove Duplicates from Sorted List LeetCode Solution144
811String comparison containing wildcards144
812Number Complement Leetcode Solution143
813Convert BST to Min Heap143
814Longest Subarray Having Count of 1s One More than Count of 0s143
815Relative Ranks Leetcode Solution143
816Minimum Time Visiting All Points Leetcode Solution143
817Find all triplets with zero sum143
818Priority Queue using doubly linked list143
819Nearest Exit from Entrance in Maze LeetCode Solution143
820Clone Graph LeetCode Solution143
821Iterative Preorder Traversal143
822Remove Duplicates from Sorted List II143
823Get Maximum in Generated Array Leetcode Solution143
824Permutation Coefficient143
825Total Numbers With no Repeated Digits in a Range143
826Reorder Data in Log Files LeetCode Solution143
827Course Schedule II – LeetCode143
828Subset with sum divisible by m142
829Maximum Nesting Depth of the Parentheses Leetcode Solution142
830Merge Sorted Array LeetCode Solution142
831One Edit Distance LeetCode Solution142
832Top K Frequent Words LeetCode Solution142
833Minimum Swaps to Make Strings Equal Leetcode Solution142
834Partition List Leetcode Solution142
835Path with maximum average value142
836Sort Colors142
837Find the Only Repetitive Element Between 1 to N-1142
838Find the subarray with least average142
839Design a Stack With Increment Operation Leetcode Solution142
840Sort Array By Parity II Leetcode Solution142
841Last Stone Weight II LeetCode Solution142
842Friends Pairing Problem141
843Check if an Array is Stack Sortable141
844Check if a given array can represent Preorder Traversal of Binary Search Tree141
845Minimum Jumps to Reach Home LeetCode Solution141
846Regular Expression Matching141
847Matrix Chain Multiplication141
848Maximum size subarray sum equals k141
849Sorted Array to Balanced BST141
850Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution141
851Spiral Matrix II Leetcode Solution141
852Brick Wall LeetCode Solution141
853Can Place Flowers LeetCode Solution140
854LCS (Longest Common Subsequence) of three strings140
855Tree Traversal (Preorder, Inorder & Postorder)140
856Subarray Product Less Than K LeetCode Solution140
857Level order Traversal in Spiral Form140
858Valid Parentheses Leetcode Solution140
859Sum of nearest smaller and greater number140
860Binary Search Tree Search and Insertion140
861Brightest Position on Street LeetCode Solution140
862Find All Possible Recipes from Given Supplies LeetCode Solution140
863Maximum Profit in Job Scheduling Leetcode Solution140
864Check whether a given Binary Tree is Complete or not140
865Count Distinct Elements in Every Window of Size K140
866Minimum Number of Taps to Open to Water a Garden LeetCode Solution140
867Form Minimum Number From Given Sequence140
868Count ways to reach the nth stair using step 1, 2 or 3140
869Given an Array of Pairs Find all Symmetric Pairs in it140
870Insert Delete GetRandom139
871Sequences of given length where every element is more than or equal to twice of previous139
872Subsequence of Size K With the Largest Even Sum LeetCode Solution139
873Union and Intersection of two Linked Lists139
874Guess Number Higher or Lower II139
875Guess Number Higher or Lower LeetCode Solution139
876Insert into a Binary Search Tree Leetcode Solution139
877Minimum Sum Path in a Triangle139
878Rearrange an Array Such that arr[i] is equal to i139
879Range sum queries without updates139
880Destination City Leetcode Solution138
881Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
882Delete And Earn138
883Shortest Word Distance Leetcode Solution138
884Find Maximum Sum Possible Equal Sum of Three Stacks138
885Maximum Score After Splitting a String Leetcode Solution138
886Find distance between two nodes of a Binary Tree138
887Daily Temperatures Leetcode Solution138
888Count Subarrays with Same Even and Odd Elements138
889Alien Dictionary138
890Distinct adjacent elements in an array138
891Count Negative Numbers in a Sorted Matrix LeetCode Solution138
892Rearrange Spaces Between Words Leetcode Solution138
893Check if stack elements are pairwise consecutive138
894A program to check if a binary tree is BST or not138
895BFS for Disconnected Graph138
896Missing Element in Sorted Array LeetCode Solution138
897Convert Sorted List to Binary Search Tree138
898Minimum sum of multiplications of n numbers138
899An Interesting Method to generate Binary Numbers from 1 to n138
900Identify and Mark Unmatched Parenthesis in an Expression138
901Lemonade Change Leetcode Solution137
902Find all permuted rows of a given row in a matrix137
903Check if the given array can represent Level Order Traversal of Binary Search Tree137
904GCDs of given index ranges in an array137
905Water Bottles Leetcode Solution137
906Construct Complete Binary Tree from its Linked List Representation137
907Special Positions in a Binary Matrix Leetcode Solution137
908Set Matrix Zeroes Leetcode Solution137
909Range LCM Queries137
910Balanced Expression with Replacement137
911Repeated Substring Pattern LeetCode Solution137
912Find Common Characters Leetcode Solution137
913Number of Equivalent Domino Pairs Leetcode Solution136
914Least Number of Unique Integers after K Removals Leetcode Solution136
915Number of Days Between Two Dates LeetCode Solution136
916Spiral Matrix III LeetCode Solution136
917Merge Two Sorted Lists Leetcode136
918Diagonal Traversal LeetCode Solution136
919Design Browser History LeetCode Solution136
920Diagonal Traverse LeetCode Solution136
921Robot Bounded In Circle LeetCode Solution136
9224Sum136
923Vertical sum in a given binary tree136
924Three way partitioning of an array around a given range136
925Construct the Rectangle Leetcode Solution135
926Print Fibonacci sequence using 2 variables135
927Palindrome Partitioning Leetcode Solution135
928Averages of Levels in Binary Tree135
929Queue using Stacks135
930K’th Largest Element in BST when modification to BST is not allowed135
931Longest Palindromic Subsequence135
932Maximum Subarray Sum Excluding Certain Elements135
933Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i135
934Lexicographical Numbers Leetcode Solution134
935Remove Duplicates from Sorted List II LeetCode Solution134
936Infix to Postfix134
937Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
938Binary array after M range toggle operations134
939Median of Two Sorted Arrays134
940Dividing Array into Pairs With Sum Divisible by K134
9413 Sum134
942Stone Game II Leetcode134
943Time Based Key-Value Store LeetCode Solution134
944Check if any two intervals overlap among a given set of intervals134
945Queries for GCD of all numbers of an array except elements in a given range134
946Trim a Binary Search Tree134
947Word Break133
948Merging Intervals133
949Largest Substring Between Two Equal Characters Leetcode Solution133
950Can Make Arithmetic Progression From Sequence Leetcode Solution133
951Construct BST from its given Level Order Traversal133
952Strongly Connected Component133
953Symmetric Tree133
954All Unique Triplets that Sum up to a Given Value133
955Pattern Occurrences using Stack133
956Newman-Conway Sequence133
957Binary Tree Longest Consecutive Sequence LeetCode Solution133
958Maximum Frequency Stack Leetcode Solution133
959Three Consecutive Odds Leetcode Solution133
960Number of Distinct Islands Leetcode Solution133
961Iterative Postorder Traversal Using Two Stacks133
962Maximize Sum of Array after K Negations Leetcode Solution133
963Analyze User Website Visit Pattern LeetCode Solution133
964Length of Longest Fibonacci Subsequence132
965Maximum Product Subarray132
966Count Submatrices With All Ones LeetCode Solution132
967Sliding Window Maximum132
968Depth First Search (DFS) for a Graph132
969Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space132
970Create Maximum Number132
971My Calendar I LeetCode Solution132
972Sign of the Product of an Array LeetCode Solution132
973Find Maximum of Minimum for Every Window Size in a Given Array132
974Difference Array | Range update query in O(1)132
975Palindrome Partitioning132
976Split Array Into Consecutive Subsequences132
977Segment Tree132
978Binary Search Tree Delete Operation131
979Maximum subsequence sum such that no three are consecutive131
980Climbing stairs131
981Count pair with Given Sum131
982Breadth First Search (BFS) for a Graph131
983Find the Difference Leetcode Solution131
984Intersection of Two Linked Lists LeetCode Solution131
985Level Order Traversal of Binary Tree131
986First missing positive131
987Minimum Height Trees LeetCode Solution131
988Count Primes in Ranges131
989Height of a generic tree from parent array131
990Find Duplicate Subtrees130
991Find postorder traversal of BST from preorder traversal130
992Boundary Traversal of binary tree130
993Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
994Reverse Nodes in K-Group130
995Serialize and Deserialize Binary Tree130
996Find the First Circular Tour that visits all the Petrol Pumps130
997Insertion in a Binary Tree130
998Double the first element and move zero to end129
999Number Of Longest Increasing Subsequence129
1000Largest Number Leetcode Solution129
1001Kth Smallest Element in a BST Leetcode Solution129
1002The Painter’s Partition Problem129
1003Largest divisible pairs subset129
1004Unique Paths II129
1005Compute nCr % p129
1006Valid Boomerang Leetcode Solution129
1007Asteroid Collision LeetCode Solution129
1008Count subarrays where second highest lie before highest129
1009Find number of pairs in an array such that their XOR is 0129
1010Minesweeper LeetCode Solution129
1011Maximum Length of Repeated Subarray128
1012The Maze III LeetCode Solution128
1013Collect maximum points in a grid using two traversals128
1014Binary Search Tree128
1015Graph Valid Tree LeetCode Solution128
1016Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1017Rearrange array such that even positioned are greater than odd128
1018Partition Equal Subset Sum128
1019Level order traversal using two Queues128
1020Longest Nice Substring LeetCode Solution128
1021Scramble String LeetCode Solution128
1022Product of Array Except Self LeetCode Solution128
1023Friends Of Appropriate Ages LeetCode Solution128
1024Design Hit Counter LeetCode Solution127
1025Balanced Binary Tree127
1026Advantages of BST over Hash Table127
1027Construction of Longest Increasing Subsequence (N log N)127
1028Next Greater Element III LeetCode Solution127
1029Find whether a subarray is in form of a mountain or not127
1030Maximum Number of Ways to Partition an Array LeetCode Solution127
1031String Matching in an Array Leetcode Solution127
1032Make The String Great Leetcode Solution127
1033Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1034Longest subsequence such that difference between adjacents is one127
1035Ugly Numbers127
1036Build an Array With Stack Operations Leetcode Solution127
1037Shortest Completing Word Leetcode Solution127
1038Invalid Transactions LeetCode Solution127
1039Construct Binary Tree from given Parent Array representation127
1040Number of palindromic paths in a matrix127
1041Boolean Parenthesization Problem127
1042Maximum weight transformation of a given string126
1043Morris Inorder Traversal126
1044K Closest Points to Origin Leetcode Solution126
1045Implement Trie (Prefix Tree) Leetcode Solution126
1046Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1047Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1048Maximum Product of Indexes of Next Greater on Left and Right126
1049Lowest Common Ancestor126
1050Minimum Size Subarray Sum126
1051Minimum Index Sum of Two Lists126
1052Kill Process LeetCode Solution126
1053Custom Sort String Leetcode Solution125
1054Maximum Sum of 3 Non-Overlapping Subarrays125
1055Regular Expression Matching Regular Expression Matching LeetCode Solution125
1056Find a Peak Element II LeetCode Solution125
1057Ugly Number II LeetCode Solution125
1058Path Sum II LeetCode Solution125
1059Iterative Depth First Traversal of Graph125
1060Add two numbers125
1061Validate Binary Search Tree125
1062Move all negative elements to end in order with extra space allowed124
1063Recover Binary Search Tree Leetcode Solution124
1064Number of Closed Islands Leetcode Solution124
1065Available Captures for Rook Leetcode Solution124
1066Super Ugly Number124
1067Largest BST Subtree LeetCode Solution124
1068Bitwise AND of Numbers Range LeetCode Solution124
1069Defanging an IP Address LeetCode Solution124
1070Find Peak Element124
1071Divisible Pairs Counting124
1072Employee Importance LeetCode Solution124
1073Binary Tree Right Side View LeetCode Solution124
1074Count pairs from two sorted arrays whose sum is equal to a given value x123
1075Count minimum steps to get the given desired array123
1076Rearrange array such that even index elements are smaller and odd index elements are greater123
1077Print all triplets in sorted array that form AP123
1078Populating Next Right Pointers in Each Node Leetcode Solution123
1079Types of Binary Tree123
1080Subarrays with K Different Integers Leetcode Solution123
1081Day of the Year Leetcode Solution123
1082Print Next Greater Number of Q queries123
1083Maximum difference between frequency of two elements such that element having greater frequency is also greater123
1084Binary Tree Data Structure123
1085Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution123
1086Clone a Binary Tree with Random Pointers123
1087Find Smallest Range Containing Elements from k Lists123
1088Remove Duplicates from Sorted Array II Leetcode Solution123
1089Number of Students Doing Homework at a Given Time Leetcode Solution122
1090Number of siblings of a given Node in n-ary Tree122
1091Path Sum122
1092Longest Bitonic Subsequence122
1093Smallest Common Region Leetcode Solution122
1094Generate Parentheses Leetcode Solution122
1095Remove Palindromic Subsequences Leetcode Solution122
1096Serialize and Deserialize Binary Tree LeetCode Solution122
1097Search in Sorted Rotated Array122
1098Find the minimum distance between two numbers122
1099Convert BST into a Min-Heap without using array121
1100Write Code to Determine if Two Trees are Identical121
1101Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1102Remove duplicates from sorted array121
1103Print Right View of a Binary Tree121
1104Root to Leaf path with target sum Leetcode Solutions121
1105Third Maximum Number Leetcode Solution121
1106Constant time range add operation on an array121
1107Combination Sum IV LeetCode Solution121
1108Valid Tic-Tac-Toe State LeetCode Solution120
1109Search Insert Position120
1110Minimum sum of squares of character counts in a given string after removing k characters120
1111Maximize Distance to Closest Person LeetCode Solution120
1112Bottom View of a Binary Tree120
1113Palindrome Permutation LeetCode Solution120
1114Level of Each node in a Tree from source node120
1115Products of ranges in an array120
1116Distinct Subsequences120
1117Find maximum difference between nearest left and right smaller elements120
1118Minimum Score Triangulation of Polygon Leetcode Solution119
1119Count Largest Group Leetcode Solution119
1120Increasing Triplet Subsequence LeetCode Solution119
1121Thousand Separator Leetcode Solution119
1122Cutting a Rod119
1123Maximum Binary Tree119
1124Find Three Element From Different Three Arrays Such That a + b + c = sum119
1125Prime Palindrome LeetCode Solution119
1126Print modified array after executing the commands of addition and subtraction119
1127Maximum Product Subarray119
1128Next Permutation Leetcode Solution119
1129Longest Increasing Consecutive Subsequence119
1130Moser-de Bruijn Sequence118
1131Construct K Palindrome Strings LeetCode Solution118
1132Mean of Array After Removing Some Elements Leetcode Solution118
1133Reformat The String Leetcode Solution118
1134Topological Sorting118
1135Iterative method to find ancestors of a given binary tree118
1136Consecutive Characters LeetCode Solution118
1137Golomb sequence118
1138Cells with Odd Values in a Matrix LeetCode Solution118
1139Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1140Swap Nodes In Pairs117
1141Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1142Transform a BST to Greater sum Tree117
1143K maximum sums of overlapping contiguous sub-arrays117
1144Minimum Absolute Difference in BST Leetcode Solution117
1145Sum of Even Numbers After Queries117
1146Search an Element in Sorted Rotated Array117
1147Red-Black Tree Introduction117
1148Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1149Priority Queue116
1150Check Array Formation Through Concatenation Leetcode Solution116
1151Subset Sum Problem in O(sum) space116
1152Longest Repeated Subsequence116
1153Delete Nodes and Return Forest Leetcode Solution116
1154Rotate Array116
1155Maximum Product of Splitted Binary Tree LeetCode Solution116
1156K’th Largest element in BST using constant extra space116
1157Count even length binary sequences with same sum of first and second half bits116
1158Factorial Trailing Zeroes LeetCode Solution116
1159Queries for Number of Distinct Elements in a Subarray116
1160Binary Tree to Binary Search Tree Conversion116
1161Palindromic Substrings Leetcode Solution116
1162Find maximum length Snake sequence116
1163Kth Smallest Number in Multiplication Table Leetcode Solution116
1164Decision Tree115
1165Merge two BSTs with limited extra space115
1166Possible Bipartition LeetCode Solution115
1167Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1168Find the smallest binary digit multiple of given number115
1169Maximize sum of consecutive differences in a circular array115
1170Search Suggestions System LeetCode Solution114
1171Minimum Sideway Jumps LeetCode Solution114
1172Count Pairs Whose Products Exist in Array114
1173Bus Routes Leetcode Solution114
1174Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1175Closest Binary Search Tree Value Leetcode Solution114
1176Minimum Moves to Equal Array Elements LeetCode Solution114
1177First Bad Version113
1178Given a binary tree, how do you remove all the half nodes?113
1179Minimum Cost to Move Chips to The Same Position LeetCode Solution113
1180Diameter of N-Ary Tree LeetCode Solution113
1181Number of Orders in the Backlog Leetcode Solution113
1182Find a sorted subsequence of size 3 in linear time113
1183Maximum number of segments of lengths a, b and c113
1184Find Largest Value in Each Tree Row LeetCode Solution112
1185Decrease Elements To Make Array Zigzag LeetCode Solution112
1186Reverse a Path in BST using Queue112
1187Lowest Common Ancestor in Binary Search Tree112
1188Queue Reconstruction by Height112
1189Swapping Nodes in a Linked List Leetcode Solution112
1190Web Crawler LeetCode Solution112
1191Contiguous Array LeetCode Solution112
1192Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution111
1193Closest Leaf in a Binary Tree LeetCode Solution111
1194Moving Stones Until Consecutive Leetcode Solution111
1195Champagne Tower LeetCode Solution111
1196Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1197Matchsticks to Square Leetcode Solution111
1198Graph and its representation110
1199New 21 Game110
1200Valid Triangle Number110
1201Replace two consecutive equal values with one greater110
1202Sum of Left Leaves LeetCode Solution110
1203Maximum sum bitonic subarray110
1204Range Sum Query using Sparse Table110
1205Maximum sum of pairs with specific difference110
1206How to print maximum number of A’s using given four keys110
1207Reformat Date LeetCode Solution110
1208Array Queries for multiply replacements and product110
1209Integer Break LeetCode Solution110
1210Valid Perfect Square LeetCode Solution110
1211Path Crossing Leetcode Solution109
1212BST to a Tree with Sum of all Smaller Keys109
1213Write a function to get the intersection point of two Linked Lists109
1214Print modified array after multiple array range increment operations109
1215Kth Smallest Element in a BST109
1216The kth Factor of n Leetcode Solution109
1217Concatenation of Array LeetCode Solution109
1218Maximum Depth Of Binary Tree109
1219Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution109
1220Maximum sum of a path in a Right Number Triangle108
1221Lowest Common Ancestor of a Binary Tree Leetcode Solution108
1222Guess The Word108
1223Arithmetic Slices II – Subsequence LeetCode Solution108
1224Range Queries for Longest Correct Bracket Subsequence108
1225Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1226Check if each internal node of a BST has exactly one child108
1227Maximum Value at a Given Index in a Bounded Array LeetCode Solution108
1228Merge Sort108
1229Design Skiplist LeetCode Solution108
1230Graph Cloning107
1231Perfect Squares LeetCode Solution107
1232Check for Identical BSTs without building the trees107
1233Divide Two Integers Leetcode Solution107
1234Flatten 2D Vector LeetCode Solution107
1235Queries on Probability of Even or Odd Number in given Ranges107
1236Check Completeness of a Binary Tree LeetCode Solution107
1237Count Subsets Having Distinct Even Numbers107
1238Sliding Window Median Leetcode Solution107
1239Check if all levels of two Binary Tree are anagrams or not107
1240Longest Common Prefix Using Word by Word Matching106
1241Largest Plus Sign Leetcode Solution106
1242Print n terms of Newman-Conway Sequence106
1243Maximum Array from Two given Arrays Keeping Order Same106
1244Power of Two106
1245Symmetric Tree LeetCode Solution Leetcode Solution106
1246LRU Cache Leetcode Solution106
1247Find k-th smallest element in BST (Order Statistics in BST)105
1248Bold Words in String LeetCode Solution105
1249Count and Toggle Queries on a Binary Array105
1250Contiguous Array105
1251Find Minimum in Rotated Sorted Array II LeetCode Solution105
1252Find minimum number of merge operations to make an array palindrome105
1253Maximize Elements Using Another Array105
1254Mean of range in array105
1255Next greater element104
1256Missing Number104
1257Verify Preorder Serialization of a Binary Tree104
1258Check If a String Can Break Another String Leetcode Solution103
1259Print Ancestors of a Given Binary Tree Node Without Recursion103
1260Merge k Sorted Lists Leetcode Solution103
1261Maximum Product Subarray103
1262Parallel Courses II LeetCode Solution103
1263Image Overlap LeetCode Solution102
1264Excel Sheet Column Title LeetCode Solution102
1265Minimum Remove to Make Valid Parentheses LeetCode Solution102
1266Smallest Range II Leetcode Solution102
1267Palindrome Partitioning101
1268Check if two nodes are on the same path in a Tree101
1269Minimum Time to Collect All Apples in a Tree LeetCode Solution101
1270Orderly Queue LeetCode Solution101
1271Koko Eating Bananas LeetCode Solution100
1272Check in binary array the number represented by a subarray is odd or even100
1273Check if X can give change to every person in the Queue98
1274Different Ways to Add Parentheses Leetcode Solution98
1275Merge Sorted Array98
1276Number of elements less than or equal to a given number in a given subarray98
1277Peeking Iterator LeetCode Solution98
1278Min Cost Climbing Stairs LeetCode Solution98
1279Newman–Shanks–Williams prime98
1280Largest Submatrix With Rearrangements LeetCode Solution97
1281Maximum Sum Increasing Subsequence96
1282Number of indexes with equal elements in given range95
1283Range Minimum Query (Square Root Decomposition and Sparse Table)95
1284Find maximum average subarray of k length95
1285Longest Substring Without Repeating Characters Leetcode Solution95
1286Queries for Decimal Values of Subarrays of a Binary Array94
1287Array Nesting Leetcode Solution93
1288Binary Tree to Binary Search Tree Conversion using STL set93
1289Maximum product of an increasing subsequence93
1290Arranging Coins Leetcode Solution92
1291Check given array of size n can represent BST of n levels or not92
1292Minimum Number of People to Teach LeetCode Solution92
1293Random Pick Index LeetCode Solution91
1294Minimum Total Space Wasted With K Resizing Operations LeetCode Solution91
1295Encoded String With Shortest Length LeetCode Solution91
1296Reach a Number LeetCode Solution90
1297Find the Winner of the Circular Game LeetCode Solution90
1298Queries on XOR of greatest odd divisor of the range90
1299Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1300Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1301Convert to Base -2 LeetCode Solution89
1302Insert Delete GetRandom O(1) Leetcode Solution88
1303Jump Game IV LeetCode Solution88
1304Palindrome Number LeetCode Solution86
1305Add Two Numbers II Leetcode Solution86
1306Vertical Order Traversal of Binary Tree LeetCode Solution85
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution84
1308Print Maximum Length Chain of Pairs83
1309Design Underground System Leetcode Solution83
1310Continuous Subarray Sum LeetCode Solution82
1311Detect Capital Leetcode Solution80
1312Design A Leaderboard Leetcode Solution78
1313Minimum Swaps to Group All 1’s Together Leetcode Solution75
1314Substring with Concatenation of All Words Leetcode Solution75
1315Minimum Path Sum Leetcode Solution72
1316Top K Frequent Elements LeetCode Solution72
1317Odd Even Linked List Leetcode Solution71
1318Decode String Leetcode Solution70
1319Binary Tree Inorder Traversal LeetCode Solution70
1320Maximum Population Year LeetCode Solution70
1321Count Sub Islands LeetCode Solution69
1322Shifting Letters LeetCode Solution69
1323Shortest Unsorted Continuous Subarray LeetCode Solution68
1324Find the Town Judge LeetCode Solution68
1325Best Meeting Point LeetCode Solution68
1326Longest Common Subsequence LeetCode Solution68
1327Sum Root to Leaf Numbers LeetCode Solution67
1328Find the Town Judge LeetCode Solution66
1329Design Add and Search Words Data Structure LeetCode Solution65
1330Rectangle Overlap LeetCode Solution63
1331Maximum Population Year LeetCode Solution62
1332Score of Parenthesis LeetCode Solution60
1333Stone Game IV LeetCode Solution60
1334Insert into a Sorted Circular Linked List LeetCode Solution60
1335Flatten Binary Tree to Linked List LeetCode Solution59
1336Range Sum Query 2D – Immutable LeetCode Solution59
1337Valid Triangle Number LeetCode Solution57
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution52
1340Divide Chocolate LeetCode Solution47
1341Range Sum of BST LeetCode Solution40
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution38
1343Sort Colors LeetCode Solution36
1344Reverse Integer Leetcode Solution36
1345Find K Closest Elements LeetCode Solution32
1346Rotate String LeetCode Solution30
1347Excel Sheet Column Number LeetCode Solution29
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »