Reach a Number LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon
Binary Search MathViews 92

Problem statement:

Reach a Number LeetCode Solution says – You are standing at a position 0 on an infinite number line. There is a destination at the position target.

You can make a number of moves numMoves so that:

  • On each move, you can either go left or right.
  • During the ith move (starting from i == 1 to i == numMoves), you take i steps in the chosen direction.

Given the integer target, return the minimum number of moves required (i.e., the minimum numMoves) to reach the destination.


Example 1:


 target = 2




On the 1st move, we step from 0 to 1 (1 step). 
On the 2nd move, we step from 1 to -1 (2 steps). 
On the 3rd move, we step from -1 to 2 (3 steps).

Example 2:


 target = 3




On the 1st move, we step from 0 to 1 (1 step).
 On the 2nd move, we step from 1 to 3 (2 steps).


  • -109 <= target <= 109
  • target != 0

Approach for Reach a Number Leetcode Solution:

1. If the target is negative we just convert it into absolute value. As we are dealing with the symmetric axis.

2. First of all we keep adding  sum=1+2+..+n>=target.

3. So, the assumption is when we flip a number then we have to subtract that number from the summation twice.

4. From here we can observe that for flipping we have to subtract twice some number from the summation. So, obviously, we are subtracting an even number.

5. We will get our target step when our summation and target value difference is even number.


Reach a Number C++ code:

class Solution {
    #define ll long long
    int reachNumber(int target) {
        ll cnt=0;
           ll ans=cnt*(cnt+1)/2;
               ll left=(ans-target);
                   return cnt;
        return 0;

Reach a Number Java code:

class Solution {
    public int reachNumber(int target) {
        int cnt=0;
            long ans=cnt*(cnt+1)/2;
               long left=(ans-target);
         return cnt;

Complexity Analysis of Reach a Number Leetcode Solution:

Time Complexity:

Time Complexity is O(sqrt(n)). Our while loop needs this many steps, as 1+2+…+n=target, n*(n+1)/2=target.

Space Complexity:

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


Similar Problem:

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2826
2Java program to find the number of Nodes in a Binary Tree2506
3Reverse a string without affecting special characters2467
4Delete a node of a linked list at given position1981
5Palindrome using Recursion1878
6Insert nodes in a linked list in a sorted way (Ascending Order)1666
7Find elements pair from array whose sum equal to number1654
8Sort Elements by Frequency of Occurrences1637
9Write a program to print all permutations of a given string1610
10Find Minimum Distance Between Two Numbers in an Array1479
11Create a Doubly Linked List1449
12Quick Sort1422
13Reverse an Array1416
14Smallest window in a string containing all characters of another string1399
15Find a Triplet That Sum to a Given Value1363
16Recursively remove all adjacent duplicates1357
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1325
19Sum of numbers in String1322
20Smallest Positive Number Missing in an Unsorted Array1289
21Check if the Elements of an Array are Consecutive1259
22Detect a loop in the Linked List1242
23Largest Sum Contiguous Subarray1234
24Quick Sort on SIngly Linked List1220
25Subarray with Given Sum1216
26Print all Possible Combinations of R Elements in a given Array of size N1207
27Recursive function to do substring search1200
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1128
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1110
32Maximum Subarray Sum using Divide and Conquer1103
33Remove characters from first string which are in second1073
34Find Leaders in an Array1064
35Swap nodes in the linked list1041
36Find the Number Occurring Odd Number of Times in an Array1008
37Arrange given Numbers to Form the Biggest Number II996
38Find the second most frequent character990
39Given a string find its first non-repeating character972
40Find Triplet in Array With a Given Sum967
41Total number of occurrences of a given item in the linked list957
42Given a sorted array and a number x, find the pair in array whose sum is closest to x957
43A Program to check if strings are rotations of each other or not949
44Print all possible words from phone digits937
45Find the Missing Number928
46Rearrange Positive and Negative Numbers Alternatively in Array925
47Longest Palindromic Substring907
48Segregate even and odd nodes in a linked list888
49Print Longest common subsequence885
50Union and Intersection of Two Linked Lists877
51Transform one string to another using minimum number of given operations872
52Check rearranged string can form a palindrome851
53Rearrange given Array in Maximum Minimum Form849
54Count Possible Triangles823
55Iterative Implementation of Quick Sort820
56Multiplication of Two Matrices806
57Check if the linked list is palindrome800
58Count of Triplets With Sum Less than Given Value796
59Stock Buy Sell to Maximize Profit795
60Rotate a Linked List795
61Concatenation of two strings766
62Tug of War763
63Print all duplicates in the input string759
64Count Number of Substrings with K Distinct Character’s758
65Find Nearest Greater and Smaller Element750
66The Celebrity Problem741
67Find Pythagorean Triplets from Array740
68Reverse String Without Temporary Variable735
69Remove ‘b’ and ‘ac’ from a given string734
70Find all Common Elements in Given Three Sorted Arrays731
71Remove all duplicates in an unsorted linked list713
72Find the Row with Maximum Number of 1’s712
73Find the Peak Element from an Array704
74Find the subarray whose sum is equal to a given number X697
75Remove Minimum Characters so that Two Strings Become Anagrams693
76Find Smallest Missing Number in a Sorted Array691
77A Product Array Puzzle689
78Addition of Two Matrices689
79Insertion Sort688
80Implement Two Stacks in an Array679
81Generate all Binary Strings Without Consecutive 1’s679
82Maximum Sum of Non Consecutive Elements672
83Maximum Product Subarray II660
84Lexicographic rank of string657
85Multiplication of Previous and Next650
86Check if Two given Matrices are Identical649
87Subtraction of Two Matrices639
88Merge K Sorted Arrays and Print Sorted Output636
89Move All the Zeros to the End of the Given Array634
90Form Minimum Number from Given Sequence of D’s and I’s626
91Divide a string in N equal parts626
92Online Algorithm for Checking Palindrome in a Stream626
93Check whether two strings are anagram of each other619
94Remove recurring digits in a given number616
95Maximum Circular Subarray Sum615
96Sort a stack using a temporary stack612
97Sort a linked list that is sorted alternating ascending and descending610
98Find the Minimum Element in a Sorted and Rotated Array609
99Move last element of the Linked List at first place604
100First Circular Tour to Visit all the Petrol Bunks602
101Subarray and Subsequence602
102Largest Subarray with Equal Number of 0’s and 1’s600
103Flattening a linked list598
104Compare two strings(linked lists)596
105Maximum Element in an Array which is Increasing and then Decreasing592
106Palindrome Permutations of a String587
107Elements Appear more than N/K times in Array584
108Majority Element581
109Palindromes in a given range580
110Run length encoding577
111Print all permutations with repetition575
112Pangram Checking573
113Minimum insertions to form a shortest palindrome573
114Merge a linked list into another at alternate positions569
115Minimum Characters to be Added at Front to Make String Palindrome568
116Remove all duplicates in a sorted linked list567
117Minimum number of Merge Operations to make an Array Palindrome564
118Most repeating character in a string564
119Rearrange a given linked list in-place564
120Rotate string to get lexicographically minimum string560
121Repeated Subsequence of Length Two or More558
122Print all anagrams together in a sequence of words556
123Reorder an Array According to the Given Indexes551
124Pancake Sorting Problem544
125Two Sum Leetcode Solution542
126Merge Overlapping Intervals II540
1273Sum Leetcode Solution539
128Clone a Linked List with next and random pointer538
129Transpose of a Matrix530
130Size of The Subarray With Maximum Sum529
131Removing Spaces from a String using stringstream524
132Remove duplicates from a string524
133Remove Extra Spaces from a String523
134Smallest Palindrome after Replacement521
135Maximum Sum Increasing Subsequence521
136Check if a given string is a rotation of a palindrome519
137Partition Problem518
138Longest Palindrome can be Formed by Removing or Rearranging Characters517
139Check whether Strings are K Distance Apart or Not508
140Generate all Binary Strings from Given Pattern506
141Insert Node in the Sorted Linked List504
142Delete Last Occurrence504
143Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized504
144Length of Longest valid Substring500
145Check if Two given Strings are Isomorphic to each other495
146Maximum difference between two elements such as larger element comes after smaller490
147Given string is interleaving of two other strings or not486
148Program to Toggle all Characters in a String486
149Count Minimum Steps to Get the given Array482
150Number of Smaller Elements on Right Side481
151Merge sort better than quick sort for linked lists480
152Find Pair with Given Difference478
153Check length of a String is Equal to the Number Appended at its Last478
154Check if all Rows of a Matrix are Circular Rotations of Each Other473
155Find nth node of the Linked list from the end472
156Longest Common Prefix using Divide and Conquer470
157Find a Fixed Point in a Given Array467
158Sort 0s 1s and 2s in an Array465
159Print all interleavings of given two strings461
160Find the Subarray of given length with Least Average458
161Reverse words in a given string458
162Compare Two Version Numbers457
163Median of Two Sorted Arrays LeetCode Solution455
164Split linked list using alternate nodes454
165Print Reverse of a string (Recursion)454
166Merge two sorted linked lists such that merged list is in reverse order454
167Reorder Array Using Given Indexes453
168Print string of odd length in ‘X’ format444
169Find K Length Subarray of Maximum Average440
170Find Element Using Binary Search in Sorted Array437
171Swap Kth Node from beginning with Kth Node from End435
172Print all Palindromic Partitions of a String432
173Find Duplicates in an Array in Most Efficient Way431
174print all palindromic partitions422
175Maximum Length of Chain Pairs419
176Shortest Superstring Problem418
177Flatten a multilevel linked list416
178Check if String Follows Order of Characters by a Pattern or not415
179Sorting a K Sorted Array412
180Sort a String According to Another String408
181Longest Span with same Sum in two Binary Arrays II403
182Reverse a Linked List in groups399
183Find a Sorted Subsequence of size 3399
184Program to add two binary digits396
185Recursively print all the sentences that can be formed from list of word lists394
186Find the two Numbers with Odd Occurrences in an Unsorted Array390
187Longest Common Prefix Using Binary Search II386
188Caesar Cipher385
189Reverse a Singly Linked List (Iterative/Non-Recursive)384
190Kth Non-repeating Character382
191Check if String can Become Empty by Recursively Deleting given Substring381
192Rearrange a linked list in Zig-Zag379
193Rotate Image by 90 degrees378
194Pancake Sorting377
195Longest Common Prefix Word by Word Matching373
196Permutations of a Given String Using STL372
197Perfect Reversible String370
198Merging Two Sorted Arrays366
199Increasing Subsequence of Length three with Maximum Product365
200Sort a linked list with 0s, 1s and 2s364
201Find the point where a monotonically increasing function becomes positive first time362
202Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes362
203Find First non-repeating character in a string362
2041`s and 2`s complement of binary number361
205Four Elements that Sum to Given355
206Delete N nodes after M354
207List items containing all characters of a given word354
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Split a string344
211Palindrome string (number)343
212Minimum Characters to be Removed to Make a Binary String Alternate341
213Recursive Implementation of atoi()339
214Print All Distinct Elements of the Array335
215Check if a Linked list of Strings form a Palindrome335
216Even Substring Count333
217Valid Parentheses LeetCode Solution332
218Convert a String that is Repetition of a Substring of Length K332
219Sorting the array of strings332
220Reverse a singly linked list recursively331
221Maximum occurring character in a string330
222Find the first Repeating Number in a Given Array329
223Can we reverse a linked list in less than O(n) time ?326
224Print Shortest Path to Print a String on Screen325
225Binary Tree to Doubly linked list323
226Convert string1 to string2 in one edit322
227Reverse a String using Stack322
228Nth Character in Concatenated Decimal String322
229Sort Elements by Frequency II320
230Maximum Subarray Leetcode Solution320
231wildcard character matching320
232Lower Case To Upper Case317
233Count the number of words315
234Merge Two Sorted Arrays313
235Find the Lost Element From a Duplicated Array311
236Split Four Distinct Strings311
237Find middle of the Linked List310
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets302
240Matrix Chain Multiplication using Dynamic Programming299
241Next Greater Element in an Array296
242Palindrome Permutation293
243Roman to Integer Leetcode Solution289
244Find Nth Node286
245Triplet from three linked lists with given sum285
246Searching a node in a Binary Search Tree285
247Find All Pairs With a Given Difference284
248String(represents an integer) to value282
249Delete a Tree281
250Word Search Leetcode Solution280
251Reverse a String279
252Reverse Bits279
253Print all Possible Ways to Break a String in Bracket Form278
254Binary Tree276
255How to Efficiently Implement k Stacks in a Single Array?274
256Delete a node under given conditions274
257Change Gender of a given String273
258Sort an array of strings272
259First non Repeating Element272
260Meeting Rooms II LeetCode Solution271
261Count Pairs With Given Sum270
262Number of sub-strings which recursively add up to 9269
263Remove middle points in a linked list of line segments269
264Longest Common Extension269
265Repeated Substring Pattern268
266Toeplitz Matrix266
267Move all negative elements to one side of array266
268Longest Palindromic Substring LeetCode Solution264
269Remove spaces from a string263
270Shuffle a given Array263
271Min Stack262
272N queen problem261
273Cuckoo sequence program257
274Number of Islands LeetCode Solution255
275Dijkstra Algorithm255
276House Robber Leetcode Solution253
277Minimize the maximum difference between the heights253
278Max stack253
279Find, second, frequent, character252
280Search Insert Position Leetcode Solution250
281Most Frequent Element in an Array250
282Clone a linked list with next and random pointer (Hashing)249
283Expression Evaluation247
284Valid Palindrome Leetcode Solution247
285KMP Algorithm246
286Sort linked which is sorted on absolute values246
287Subset Leetcode245
288Sudoku Solver245
289Reverse words in a string244
290Number Of 1 bits243
291Fibonacci numbers243
292Min Stack Leetcode Solution243
293Combination Sum Leetcode Solution242
294Plus One Leetcode Solution242
295Evaluation of Postfix Expression241
296How to Delete a Linked List241
297Word Search240
298Backspace String Compare236
299Set Matrix Zeroes234
300Merge Sorted Arrays Leetcode Solution234
301Sqrt(x) Leetcode Solution233
302Pair of Positive Negative Values in an Array233
303Reversing a Queue232
304Subarray with 0 sum232
305Rabin Karp Algorithm231
306Contains Duplicate II Leetcode Solution230
307Product of array except self229
308Common elements in all rows of a given matrix229
309Tower Of Hanoi227
310Integer to Roman Leetcode Solution227
311Combination Sum226
312Delete middle element of a stack226
313Pascal Triangle Leetcode226
314Intersection of Two Arrays II Leetcode Solution226
315Reverse individual words224
316String Compression224
317Find Top K (or Most Frequent) Numbers in a Stream222
318Minimum swaps required to bring all elements less than or equal to k together222
319Count subarrays with equal number of 1’s and 0’s221
320Sliding Window Technique221
321Construct Binary Tree from Given Inorder and Preorder Traversals221
322Count of index pairs with equal elements in an array221
323Arithmetic Expression Evaluation221
324Implementation of Deque using Doubly Linked List220
325Bellman Ford Algorithm220
326Single Number Leetcode Solution220
327Add Binary Leetcode Solution219
328Minimum Value to Get Positive Step by Step Sum Leetcode Solution219
329Second Most Repeated Word in a Sequence218
330Contains Duplicate218
331Segregate even and odd numbers218
332Palindrome Linked List Leetcode Solution218
333Sort elements by frequency217
334Pow(x, n) Leetcode Solution217
335Design a stack that supports getMin() in O(1) time and O(1) extra space216
336Postfix to Infix Conversion216
337Count Odd Numbers in an Interval Range Leetcode Solution216
338Page Replacement Algorithms in Operating Systems216
339Find sum of non-repeating elements (distinct) elements in an array216
340Kruskal Algorithm215
341Next Permutation215
342Maximum Number of Balloons Leetcode Solution215
343Third Maximum Number Leetcode Solution214
344Group Words With Same Set of Characters213
345K-th Smallest Element in a Sorted Matrix212
346Sum of minimum and maximum elements of all subarrays of size k212
347Permutations Leetcode Solution211
348Convex Hull Algorithm211
349Smallest Subarray with k Distinct Numbers210
350Find the Town Judge Leetcode Solution210
351Longest Common Prefix Leetcode Solution210
352Longest Substring Without Repeating Characters LeetCode Solution210
353Find Lucky Integer in an Array Leetcode Solution209
354Top K Frequent Words209
355Majority Element Leetcode Solution209
356Spiral Matrix LeetCode Solution208
357Find Numbers with Even Number of Digits Leetcode Solution208
358Maximum Subarray208
359Scramble String208
360Count subarrays having total distinct elements same as original array207
361Sorting array using Stacks207
362Swap Nodes in Pairs Leetcode Solutions207
363Number of Good Pairs Leetcode Solution206
364Minimum operation to make all elements equal in array206
365First element occurring k times in an array206
366Evaluate Division206
367Merge Two Sorted Lists Leetcode Solutions205
368Missing Number Leetcode Solution205
369Prefix to Infix Conversion205
370Minimum Path Sum205
371Search in Rotated Sorted Array Leetcode Solution204
372Special Number204
373Count Primes Leetcode Solutions204
374Check if two arrays are equal or not204
375Best Time to Buy and Sell Stock  II Leetcode Solution204
376Given two unsorted arrays find all pairs whose sum is x204
377Reverse a Number Using Stack203
378Minimum Absolute Difference Leetcode Solution203
379Huffman Coding202
380Pascal’s Triangle II Leetcode Solution202
381Power of Two Leetcode Solution202
382Top K Frequent Elements202
383Sort Array by Increasing Frequency Leetcode Solution202
384Find All Numbers Disappeared in an Array Leetcode Solution202
385Unique Paths Leetcode Solution201
386Minimum Steps to reach target by a Knight201
387House Robber II Leetcode Solution201
388Reversing the First K elements of a Queue201
389Find duplicates in a given array when elements are not limited to a range201
390Maximal Square201
391Fizz Buzz Leetcode200
392Single Number200
393How Many Numbers Are Smaller Than the Current Number Leetcode Solution199
394Sorting using trivial hash function199
395Matrix Diagonal Sum Leetcode Solution199
396Running Sum of 1d Array Leetcode Solution199
397Maximum possible difference of two subsets of an array199
398Leetcode Permutations198
399Find Minimum In Rotated Sorted Array198
400Sort Integers by The Number of 1 Bit Leetcode Solution198
401Group Anagrams198
402Find the Closest Palindrome number197
403Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution197
404How to Implement Stack Using Priority Queue or Heap?197
405Range Sum Query 2D – Immutable Leetcode Solution197
406Maximum Distance Between two Occurrences of Same Element in Array197
407Coin Change 2 Leetcode Solution197
408Happy Number Leetcode Solution197
409Unique Paths196
410Max Consecutive Ones Leetcode Solution196
411Difference between highest and least frequencies in an array195
412Remove Duplicates from Sorted Array Leetcode Solution195
413Expression Contains Redundant Bracket or Not195
414Convert String To Int195
415Find Number of Employees Under every Employee195
416Decode String195
417Find Winner on a Tic Tac Toe Game Leetcode Solution195
418Monotonic Array LeetCode Solution195
419Zigzag Conversion195
420Smallest Element Repeated Exactly K Times194
421Fibonacci Number LeetCode Solution194
422Best Time to Buy and Sell Stock III Leetcode Solution194
423Subarray Sum Equals k194
424Subarray Sum Equals K LeetCode Solution194
425Length of the largest subarray with contiguous elements194
426Check if Array Contains Contiguous Integers With Duplicates Allowed194
427Reverse Vowels of a String Leetcode Solution193
428Capacity To Ship Packages Within D Days Leetcode Solution193
429Reverse Integer193
430Subset sum problem193
431Find The Duplicate Number193
432Implement Stack and Queue using Deque192
433Palindrome Substring Queries192
434Delete a Node from linked list without head pointer192
435Reverse a Stack Using Recursion192
436Check If N and Its Double Exist Leetcode Solution192
437Subtract the Product and Sum of Digits of an Integer Leetcode Solution192
438Find Median from data Stream192
439Letter Case Permutation192
440LRU Cache Implementation191
441Find top three repeated in array191
442Nth Catalan Number191
443Generate a String With Characters That Have Odd Counts Leetcode Solution191
444Shuffle the Array Leetcode Solution191
445Maximum Depth of Binary Tree Leetcode Solution191
446Reverse Words in a String III LeetCode Solution191
447Find the Duplicate Element190
448Trapping Rain Water Leetcode Solution190
449Print All Distinct Elements of a Given Integer Array190
450Cumulative Frequency of Count of Each Element in an Unsorted Array190
451Sort a stack using recursion190
452Priority Queue Using Singly Linked List190
453Subarrays with distinct elements189
454Excel Sheet Column Number Leetcode Solution189
455Target Sum189
456Kth largest element in an Array Leetcode Solutions189
457Find Common Characters Leetcode Solution189
458Sorting a Queue without Extra Space189
459Bipartite Graph189
460Reverse a String189
461Count Substrings with equal number of 0s, 1s and 2s189
462Iterative Tower of Hanoi188
463Longest Common Subsequence188
464Print all subarrays with 0 sum188
465Find the first repeating element in an array of integers188
466Integer to English words188
467Sum of Subarray Ranges Leetcode Solution188
468Find First and Last Position of Element in Sorted Array Leetcode Solution187
469The K Weakest Rows in a Matrix Leetcode Solution187
470Minimum Moves to Equal Array Elements Leetcode Solution187
471Find the Difference Leetcode Solution187
472Balanced Binary Tree Leetcode Solution187
473Kids With the Greatest Number of Candies Leetcode Solution187
474Find all pairs (a, b) in an array such that a % b = k187
475Word Ladder LeetCode Solution187
476Prim’s Algorithm187
477Concatenation of Array LeetCode Solution186
478Find elements which are present in first array and not in second186
479Merge Two Sorted Linked Lists186
480Count pairs from two linked lists whose sum is equal to a given value186
481Floyd Warshall Algorithm186
482Next Greater Element I Leetcode Solution185
483Merge Overlapping Intervals185
484Number of Steps to Reduce a Number to Zero Leetcode Solution185
485Kth Largest Element in a Stream Leetcode Solution185
486Fizz Buzz185
487Text Justification LeetCode Solution185
488Zigzag Conversion LeetCode Solution184
489Edit Distance184
490Reverse a linked list184
491Multiply Strings Leetcode Solution184
492Prefix to Postfix Conversion183
493Flood Fill LeetCode183
494Slowest Key Leetcode Solution183
495Remove Minimum Number of Elements Such That no Common Element Exist in both Array183
496Degree of an array183
497The Stock Span Problem183
498Count and Say Leetcode Solution183
499Count and Say183
500Move Zeroes LeetCode Solution183
501Longest Common Prefix using Trie183
502Design Parking System Leetcode Solution183
503Mobile Numeric Keypad Problem182
504Implement a stack using single queue182
505Max Area of Island182
506Shuffle String Leetcode Solution182
507Intersection of Two Arrays182
508Length of Last Word Leetcode Solution182
509MiniMax Algorithm182
510Valid Parenthesis String181
511Substring With Concatenation Of All Words181
512Last Stone Weight181
513Next Greater Frequency Element181
514Priority Queue in C++181
515Jump Game Leetcode Solution181
516Top View of Binary Tree181
517Find subarray with given sum (Handles Negative Numbers)180
518Find N Unique Integers Sum up to Zero Leetcode Solution180
519Convert array into Zig-Zag fashion180
520Find distinct elements common to all rows of a matrix180
521Peak Index in a Mountain Array180
522Koko Eating Bananas Leetcode Solution179
523Pair with given product179
525Longest subarray not having more than K distinct elements179
526Postfix to Prefix Conversion179
527Iterative Inorder Traversal of a Binary Tree179
528N-th Tribonacci Number Leetcode Solution178
529Count number of triplets with product equal to given number178
530Find any one of the multiple repeating elements in read only array178
531Relative Sort Array Leetcode Solution178
532Container with Most Water178
533Shortest Palindrome178
534Find Index of Closing Bracket for a Given Opening Bracket in an Expression178
535Contiguous Array Leetcode178
536Find four elements that sum to a given value (Hashmap)178
537Delete Node in a Linked List Leetcode Solution178
538Implement Stack using Queues178
539Smallest Subarray With all Occurrences of a Most Frequent Element178
540Excel Sheet Column Title Leetcode Solution178
541Longest Common Prefix using Sorting178
542Minimum Operations to convert X to Y177
543Check if a given array contains duplicate elements within k distance from each other177
544Convert a normal BST to Balanced BST177
545Jewels and Stones Leetcode Solution177
546Is Subsequence Leetcode Solution177
547Best Time to Buy and Sell Stock177
548Find missing elements of a range177
549Isomorphic Strings Leetcode Solution177
550Sum of Left Leaves Leetcode Solutions176
551Remove Linked List Elements Leetcode Solution176
552K-th Distinct Element in an Array176
553Implementation of Deque using circular array176
554Largest Perimeter Triangle Leetcode Solution176
555First negative integer in every window of size k176
556Build Array From Permutation Leetcode Solution175
557Check for Balanced Parentheses in an Expression175
558Find Words That Can Be Formed by Characters Leetcode Solution175
559Linked List Cycle II LeetCode Solution175
56001 Matrix LeetCode Solution175
561Island Perimeter Leetcode Solution175
562Change the Array into Permutation of Numbers From 1 to N174
563Shuffle an Array174
564Convert Sorted Array to Binary Search Tree Leetcode Solution174
565Valid Sudoku174
566Distribute Candies to People Leetcode Solution174
567Assign Cookies Leetcode Solution174
568Maximum sum rectangle in a 2D matrix174
569Summary Ranges Leetcode Solution174
570Largest Sum Contiguous Subarray174
571Valid Anagrams174
572Minimum Bracket Reversals174
573Arrange given numbers to form the biggest number174
574Group Multiple Occurrence of Array Elements Ordered by first Occurrence174
575Unique Binary Search Trees173
576Integer to Roman173
577Find the smallest positive integer value that cannot be represented as sum of any subset of a given array173
578Gold Mine Problem173
579Hamming Distance173
580Insert Interval Leetcode Solution173
581Rotate List Leetcode Solution173
582Combinations Leetcode Solution173
583Count the number of nodes at given level in a tree using BFS173
584Count all subsequences having product less than K173
585Trapping Rain Water LeetCode Solution172
586Maximum Number of Chocolates to be Distributed Equally Among k Students172
587Decode Ways172
588Minimum number of distinct elements after removing m items172
589Maximum Distance in Array172
590Minimum Delete Operations to make all Elements of Array Same172
591Maximum path sum in a triangle172
5923Sum Closest LeetCode Solution172
593The Knapsack Problem172
594Rotate Image LeetCode Solution171
595Distance Between Bus Stops Leetcode Solution171
596Shortest Path in a Grid with Obstacles Elimination LeetCode Solution171
597Same Tree LeetCode Solution170
598LRU Cache LeetCode Solution170
599Rearrange a binary string as alternate x and y occurrences170
600Sieve of Eratosthenes170
601K Empty Slots LeetCode170
602Minimum Knight Moves LeetCode Solution170
603Permutation in String Leetcode Solution170
604Minimum number of subsets with distinct elements169
605Stone Game LeetCode169
606Remove All Occurrences of a Substring LeetCode Solution169
607House Robber168
608Sort Array By Parity LeetCode Solution168
609XOR Operation in an Array Leetcode Solution168
610Find the Duplicate Number LeetCode Solution168
611How to check if two given sets are disjoint?168
612Printing brackets in Matrix Chain Multiplication Problem168
613Defanging an IP Address Leetcode Solution168
614Distance of nearest cell having 1 in a binary matrix168
615Minimum Depth of Binary Tree Leetcode Solution167
616Find if an Expression has Duplicate Parenthesis or Not167
617Applications of Breadth First Search and Depth First Search167
618Painting Fence Algorithm167
619Coin Change Problem167
620Sort Characters By Frequency LeetCode Solution167
621Tracking current Maximum Element in a Stack167
622Maximum difference between first and last indexes of an element in array167
623Frog Jump Leetcode Solution167
624Find Sum of all unique sub-array sum for a given array167
625Word Pattern167
626License Key Formatting Leetcode Solution167
627Minimum insertions to form a palindrome with permutations allowed167
628Best Time to Buy and Sell Stock LeetCode Solution167
629Word Wrap Problem167
630Replace Elements with Greatest Element on Right Side Leetcode Solution167
631Maximum Consecutive Numbers Present in an Array167
632Segregate 0s and 1s in an Array167
633Smallest Good Base166
634Longest Substring with At Most K Distinct Characters LeetCode Solution166
635Find minimum difference between any two elements166
636Check If It Is a Straight Line Leetcode Solution166
637Sum of All Odd Length Subarrays Leetcode Solution166
638Longest Substring with At Least K Repeating Characters LeetCode Solution165
639Count Good Nodes in Binary Tree Leetcode Solution165
640Queries for counts of array elements with values in given range165
641Best Time to Buy and Sell Stock with Cooldown Leetcode Solution165
642Isomorphic Strings165
643Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions165
644Wiggle Sort164
645Letter Combinations of a Phone Number164
646Binary Tree Zigzag Level Order Traversal LeetCode Solution164
647Number of Provinces Leetcode Solution164
648Find Maximum Level sum in Binary Tree164
649Maximum Number of Occurrences of a Substring Leetcode Solution164
650Optimal Account Balancing LeetCode Solution164
651Employee Free Time LeetCode Solution164
652Kth Missing Positive Number Leetcode Solution164
653Iterative Method to find Height of Binary Tree164
654Minimum Cost to Hire K Workers164
655Merge Two Balanced Binary Search Trees164
656Reverse a stack without using extra space in O(n)163
657GCD Of Two Numbers163
658Find pairs with given sum such that elements of pair are in different rows163
659Reorganize String163
660Non-overlapping sum of two sets163
661Strobogrammatic Number LeetCode Solution163
662Valid Palindrome II Leetcode Solution163
663Power of Four Leetcode Solution163
664Partition Labels LeetCode Solution163
665Valid Perfect Square Leetcode Solution163
666Valid Palindrome162
667Edit Distance LeetCode Solution162
668Maximum Number of Coins You Can Get Leetcode Solution162
669Print the Fibonacci numbers in reverse order162
670Find the Distance Value Between Two Arrays Leetcode Solution162
671Recover Binary Search Tree162
672Delete consecutive same words in a sequence162
673Moving Average from Data Stream Leetcode Solution162
674To Lower Case Leetcode Solution161
675Find Largest d in Array such that a + b + c = d161
676Ugly Number Leetcode Solution161
677Flipping an Image LeetCode Solution161
678Dynamic Programming Basics161
679Path With Maximum Minimum Value LeetCode Solution161
680Inorder Successor of a node in Binary Tree161
681Reducing Dishes LeetCode Solution161
682String to Integer (atoi) LeetCode Solution161
683Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
684Longest Increasing Subsequence161
685Sort Array by Increasing Frequency Leetcode Solution161
686Permutation Sequence LeetCode Solution161
687BFS vs DFS for Binary Tree160
688Maximum Product of Two Elements in an Array Leetcode Solution160
689Factorial Trailing Zeroes Leetcode Solution160
690Populating Next Right Pointers in Each Node160
691Reversing a Queue using Recursion160
692Longest Increasing Path in a Matrix LeetCode Solution160
693K Empty Slots160
694Find Leaves of Binary Tree LeetCode Solution160
695Check if a queue can be sorted into another queue using a stack160
696Subset Sum Leetcode160
697Number of Dice Rolls With Target Sum LeetCode Solution160
698Convert an array to reduced form160
699Restore IP Addresses Leetcode Solution160
700Find whether an array is subset of another array160
701Reverse Only Letters LeetCode Solution160
702Check If Two String Arrays are Equivalent Leetcode Solution160
703How to Create Mergable Stack?160
704Partition Array Into Three Parts With Equal Sum Leetcode Solution160
705Remove Invalid Parentheses Leetcode Solution159
706Reservoir Sampling159
707Construct BST from given Preorder Traversal159
708Majority Element II Leetcode Solution159
709Increasing Decreasing String Leetcode Solution159
710Binary Tree zigzag level order Traversal159
711Form minimum number from given sequence159
712Add and Search Word – Data structure design LeetCode159
713Unique Paths II Leetcode Solution159
714Delete Nth node from the end of the given linked list159
715Minimum Cost For Tickets Leetcode Solution158
716Bulb Switcher LeetCode Solution158
717Find Pair with Greatest Product in Array158
718Convert a Number to Hexadecimal Leetcode Solution158
719Find the largest multiple of 3158
720Robot Room Cleaner Leetcode Solution158
721Lucky Numbers in a Matrix Leetcode Solution158
722Find the Smallest Divisor given a Threshold Leetcode Solution158
723Perform String Shifts Leetcode158
724Sum of f(a[i], a[j]) over all pairs in an array of n integers157
725Morris Traversal157
726Merge Two Binary Trees LeetCode Solution157
727Keyboard Row Leetcode Solution157
728Bubble sort using two Stacks156
729Find the node with minimum value in a Binary Search Tree156
730First Unique Character in a String LeetCode Solution156
731Student Attendance Record I Leetcode Solution156
732Rank Transform of an Array Leetcode Solution156
733Decompress Run-Length Encoded List Leetcode Solution156
734Sorted Linked List to Balanced BST155
735Minimum Distance Between BST Nodes Leetcode Solution155
736Hamming Distance Leetcode Solution155
737Finding K closest element155
738Invert Binary Tree LeetCode Solution155
739Maximum Product of Three Numbers LeetCode Solution155
740Maximum 69 Number Leetcode Solution155
741Best Meeting Point LeetCode Solution155
742Merge K Sorted Linked Lists154
743String Compression LeetCode Solution154
744Evaluate Reverse Polish Notation LeetCode Solution154
745Snakes and Ladders LeetCode Solution154
746Find unique character in a string154
747Binary Tree Maximum Path Sum LeetCode Solution154
748Find if Path Exists in Graph Leetcode Solution154
749Elements to be added so that all elements of a range are present in array154
750Split a String in Balanced Strings Leetcode Solution154
751Diagonal Traversal of Binary Tree154
752Minimum Height Trees154
753Maximum Depth of N-ary Tree Leetcode Solution154
754Find Median from Data Stream LeetCode Solution154
755Largest rectangular sub-matrix whose sum is 0154
756Symmetric Tree Leetcode Solution154
757Maximum Difference Between Increasing Elements LeetCode Solution154
758Minimum time required to rot all oranges154
759Non-decreasing Array LeetCode Solution154
760Word Pattern LeetCode Solution154
761Maximum Length of a Concatenated String with Unique Characters Leetcode Solution154
762Generate all possible sorted arrays from alternate elements of two given sorted arrays154
763Number of Islands II LeetCode Solution154
764Queue based approach for first non-repeating character in a stream154
765Largest subarray with equal number of 0s and 1s154
766Find All Duplicates in an Array LeetCode Solution154
767Search a 2D Matrix II Leetcode Solution154
768Tiling Problem154
769Stack Permutations (Check if an array is stack permutation of other)154
770Jump Game153
771k-th missing element in increasing sequence which is not present in a given sequence153
772Race Car LeetCode Solution153
773Check If Array Pairs Are Divisible by k LeetCode Solution153
774Numbers with prime frequencies greater than or equal to k153
775Transpose Graph153
776Deletion in a Binary Tree153
777Binomial Coefficient153
778Minimize Maximum Pair Sum in Array LeetCode Solution153
779Special Array With X Elements Greater Than or Equal X Leetcode Solution153
780Kth ancestor of a node in binary tree153
781Final Prices With a Special Discount in a Shop Leetcode Solution152
782Longest Span with same Sum in two Binary arrays152
783Minimum Time Visiting All Points Leetcode Solution152
784Minimum swaps to make sequences increasing152
785Minimum number of jumps to reach end152
786Largest Rectangle in Histogram LeetCode Solution152
787Remove Nth Node From End of List Leetcode Solution152
788Program for Bridge and Torch problem152
789Find Maximum Depth of Nested Parenthesis in a String152
790Check if Two Expressions With Brackets are Same152
791Count quadruples from four sorted arrays whose sum is equal to a given value x152
792N-Queens LeetCode Solution152
793Remove Duplicates from Sorted List II152
794Search in a Binary Search Tree Leetcode Solution152
795Remove Duplicates from Sorted List LeetCode Solution151
796Partition to K Equal Sum Subsets Leetcode Solution151
797Number of NGEs to the Right151
798Interval Tree151
799String comparison containing wildcards151
800A Space Optimized DP solution for 0-1 Knapsack Problem151
801Base 7 Leetcode Solution151
802Linked List Cycle151
803Sort an array according to the order defined by another array151
804Crawler Log Folder Leetcode Solution151
805Remove brackets from an algebraic string containing + and – operators151
806Minimum Jumps to Reach Home LeetCode Solution151
807Last Stone Weight II LeetCode Solution150
808Brick Wall LeetCode Solution150
809Iterative Preorder Traversal150
810Nested List Weight Sum II LeetCode Solution150
811Find all triplets with zero sum150
812Course Schedule II – LeetCode150
813Maximum Profit in Job Scheduling Leetcode Solution150
814Relative Ranks Leetcode Solution150
815Number Complement Leetcode Solution150
816Check for Palindrome after every character replacement Query150
817Total Numbers With no Repeated Digits in a Range150
818Nearest Exit from Entrance in Maze LeetCode Solution150
819Circular Queue149
820Merge Sorted Array LeetCode Solution149
821Reorder Data in Log Files LeetCode Solution149
822Print a Binary Tree in Vertical Order149
823Alien Dictionary LeetCode Solution149
824Can Place Flowers LeetCode Solution149
825Maximum size subarray sum equals k149
826Growable array based stack149
827Find the subarray with least average149
828Convert BST to Min Heap149
829Get Maximum in Generated Array Leetcode Solution149
830One Edit Distance LeetCode Solution149
831Valid Parentheses Leetcode Solution149
832Path with maximum average value149
833Longest Subarray Having Count of 1s One More than Count of 0s148
834Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution148
835Top K Frequent Words LeetCode Solution148
836Regular Expression Matching148
837Subarray Product Less Than K LeetCode Solution148
838Level order Traversal in Spiral Form148
839Partition List Leetcode Solution148
840Design a Stack With Increment Operation Leetcode Solution148
841Find All Possible Recipes from Given Supplies LeetCode Solution148
842Valid Number148
843Sort Colors148
844Count items common to both the lists but with different prices148
845Find the Only Repetitive Element Between 1 to N-1148
846Sort Array By Parity II Leetcode Solution148
847Subsequence of Size K With the Largest Even Sum LeetCode Solution148
848Check if a given array can represent Preorder Traversal of Binary Search Tree148
849Clone Graph LeetCode Solution148
850Check whether a given Binary Tree is Complete or not148
851Count Distinct Elements in Every Window of Size K148
852Minimum Number of Taps to Open to Water a Garden LeetCode Solution147
853Count Negative Numbers in a Sorted Matrix LeetCode Solution147
854Permutation Coefficient147
855Insert into a Binary Search Tree Leetcode Solution147
856Priority Queue using doubly linked list147
857Maximum Nesting Depth of the Parentheses Leetcode Solution147
858Form Minimum Number From Given Sequence147
859Friends Pairing Problem147
860Subset with sum divisible by m147
861Brightest Position on Street LeetCode Solution146
862Guess Number Higher or Lower LeetCode Solution146
863Matrix Chain Multiplication146
864Minimum Sum Path in a Triangle146
865Union and Intersection of two Linked Lists146
866K’th Largest Element in BST when modification to BST is not allowed146
867GCDs of given index ranges in an array146
868Repeated Substring Pattern LeetCode Solution146
869Distinct adjacent elements in an array146
870Given an Array of Pairs Find all Symmetric Pairs in it146
871Sum of nearest smaller and greater number146
872Tree Traversal (Preorder, Inorder & Postorder)146
873Binary Search Tree Search and Insertion146
874Spiral Matrix II Leetcode Solution145
875Number of Days Between Two Dates LeetCode Solution145
876Sorted Array to Balanced BST145
877Diagonal Traverse LeetCode Solution145
878Daily Temperatures Leetcode Solution145
879Three way partitioning of an array around a given range145
880An Interesting Method to generate Binary Numbers from 1 to n145
881Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution145
882Sequences of given length where every element is more than or equal to twice of previous145
883Minimum Swaps to Make Strings Equal Leetcode Solution145
884Lemonade Change Leetcode Solution144
885Find Maximum Sum Possible Equal Sum of Three Stacks144
886Design Browser History LeetCode Solution144
887Check if stack elements are pairwise consecutive144
888Range sum queries without updates144
889Check if an Array is Stack Sortable144
890Guess Number Higher or Lower II144
891Count ways to reach the nth stair using step 1, 2 or 3144
892Robot Bounded In Circle LeetCode Solution144
893Minimum sum of multiplications of n numbers144
894Delete And Earn144
895LCS (Longest Common Subsequence) of three strings144
896Spiral Matrix III LeetCode Solution143
897Missing Element in Sorted Array LeetCode Solution143
898Check if the given array can represent Level Order Traversal of Binary Search Tree143
899Diagonal Traversal LeetCode Solution143
900Destination City Leetcode Solution143
901Find distance between two nodes of a Binary Tree143
902Water Bottles Leetcode Solution143
903Rearrange Spaces Between Words Leetcode Solution143
904Least Number of Unique Integers after K Removals Leetcode Solution143
905Maximum Score After Splitting a String Leetcode Solution143
907Rearrange an Array Such that arr[i] is equal to i143
908Special Positions in a Binary Matrix Leetcode Solution142
909Palindrome Partitioning Leetcode Solution142
910Trim a Binary Search Tree142
911Shortest Word Distance Leetcode Solution142
912Time Based Key-Value Store LeetCode Solution142
913Vertical sum in a given binary tree142
914Construct Complete Binary Tree from its Linked List Representation142
915A program to check if a binary tree is BST or not142
916Queries for GCD of all numbers of an array except elements in a given range142
917Balanced Expression with Replacement142
918Identify and Mark Unmatched Parenthesis in an Expression142
919Set Matrix Zeroes Leetcode Solution142
920Strongly Connected Component141
921Number of Distinct Islands Leetcode Solution141
922Construct the Rectangle Leetcode Solution141
923Alien Dictionary141
924Convert Sorted List to Binary Search Tree141
925All Unique Triplets that Sum up to a Given Value141
926Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i141
927Split Array Into Consecutive Subsequences141
928Remove Duplicates from Sorted List II LeetCode Solution141
929Construct BST from its given Level Order Traversal141
930Iterative Postorder Traversal Using Two Stacks141
931BFS for Disconnected Graph141
932Binary array after M range toggle operations141
933Range LCM Queries141
934Insert Delete GetRandom141
9353 Sum140
936Merge Two Sorted Lists Leetcode140
937Find Common Characters Leetcode Solution140
938Averages of Levels in Binary Tree140
939Count Subarrays with Same Even and Odd Elements140
940Queue using Stacks140
941Merging Intervals140
942Longest Palindromic Subsequence140
943Find all permuted rows of a given row in a matrix140
944Reverse Nodes in K-Group140
945Collect maximum points in a grid using two traversals140
946Intersection of Two Linked Lists LeetCode Solution140
947Lexicographical Numbers Leetcode Solution140
948Infix to Postfix140
949Difference Array | Range update query in O(1)140
950Count Submatrices With All Ones LeetCode Solution140
951Binary Tree Longest Consecutive Sequence LeetCode Solution140
952Maximum Frequency Stack Leetcode Solution140
953Number of Equivalent Domino Pairs Leetcode Solution140
954Can Make Arithmetic Progression From Sequence Leetcode Solution139
955Check if any two intervals overlap among a given set of intervals139
956Word Break139
957Find the Difference Leetcode Solution139
958Count pair with Given Sum139
959Maximize Sum of Array after K Negations Leetcode Solution138
960Minimum Height Trees LeetCode Solution138
961Analyze User Website Visit Pattern LeetCode Solution138
962Product of Array Except Self LeetCode Solution138
963Shuffle 2n integers as without using extra space138
964Stone Game II Leetcode138
965Print Fibonacci sequence using 2 variables138
966Symmetric Tree137
967Create Maximum Number137
968Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution137
969Palindrome Partitioning137
970Largest area rectangular sub-matrix with equal number of 1’s and 0’s137
971Height of a generic tree from parent array137
972Find postorder traversal of BST from preorder traversal137
973Valid Boomerang Leetcode Solution137
974Sliding Window Maximum137
975Maximum Product Subarray137
976Three Consecutive Odds Leetcode Solution137
977Maximum Product of Indexes of Next Greater on Left and Right137
978Longest Nice Substring LeetCode Solution137
979Unique Paths II137
980My Calendar I LeetCode Solution136
981Maximum Subarray Sum Excluding Certain Elements136
982Largest divisible pairs subset136
983Minesweeper LeetCode Solution136
984K Closest Points to Origin Leetcode Solution136
985Level order traversal using two Queues136
986Maximum weight transformation of a given string136
987Count Primes in Ranges136
988Asteroid Collision LeetCode Solution136
989Kth Smallest Element in a BST Leetcode Solution136
990Level Order Traversal of Binary Tree136
991Boolean Parenthesization Problem136
992Breadth First Search (BFS) for a Graph136
993Number Of Longest Increasing Subsequence136
994Newman-Conway Sequence136
995The Painter’s Partition Problem136
996Dividing Array into Pairs With Sum Divisible by K136
997Maximum subsequence sum such that no three are consecutive136
998Morris Inorder Traversal135
999Find the First Circular Tour that visits all the Petrol Pumps135
1000First missing positive135
1001Double the first element and move zero to end135
1002Graph Valid Tree LeetCode Solution135
1003Friends Of Appropriate Ages LeetCode Solution135
1004Median of Two Sorted Arrays135
1005Pattern Occurrences using Stack135
1006Depth First Search (DFS) for a Graph135
1007Find Maximum of Minimum for Every Window Size in a Given Array135
1008Find Duplicate Subtrees135
1009Longest subsequence such that difference between adjacents is one135
1010Largest Substring Between Two Equal Characters Leetcode Solution135
1011Next Greater Element III LeetCode Solution135
1012Segment Tree135
1013Binary Search Tree Delete Operation135
1014Length of Longest Fibonacci Subsequence135
1015String Matching in an Array Leetcode Solution134
1016The Maze III LeetCode Solution134
1017Partition Equal Subset Sum134
1018Sign of the Product of an Array LeetCode Solution134
1019Insertion in a Binary Tree134
1020Decrypt String from Alphabet to Integer Mapping Leetcode Solution134
1021Maximum Number of Ways to Partition an Array LeetCode Solution134
1022Maximum Length of Repeated Subarray134
1023Build an Array With Stack Operations Leetcode Solution134
1024Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’134
1025Shortest Completing Word Leetcode Solution134
1026Serialize and Deserialize Binary Tree134
1027Climbing stairs133
1028Make The String Great Leetcode Solution133
1029Design Hit Counter LeetCode Solution133
1030Boundary Traversal of binary tree133
1031Kill Process LeetCode Solution133
1032Compute nCr % p133
1033Rearrange array such that even positioned are greater than odd133
1034Count subarrays where second highest lie before highest133
1035Validate Binary Search Tree133
1036Construction of Longest Increasing Subsequence (N log N)133
1037K maximum sums of overlapping contiguous sub-arrays133
1038Largest Number Leetcode Solution133
1039Balanced Binary Tree132
1040Scramble String LeetCode Solution132
1041Defanging an IP Address LeetCode Solution132
1042Add two numbers132
1043Advantages of BST over Hash Table132
1044Super Ugly Number132
1045Maximum Sum of 3 Non-Overlapping Subarrays132
1046Invalid Transactions LeetCode Solution132
1047Ugly Number II LeetCode Solution132
1048Find number of pairs in an array such that their XOR is 0132
1049Construct Binary Tree from given Parent Array representation132
1050Move all negative elements to end in order with extra space allowed131
1051Find a Peak Element II LeetCode Solution131
1052Binary Tree Right Side View LeetCode Solution131
1053Recover Binary Search Tree Leetcode Solution131
1054Ugly Numbers131
1055Implement Trie (Prefix Tree) Leetcode Solution131
1056Binary Search Tree131
1057Maximum difference between frequency of two elements such that element having greater frequency is also greater131
1058Bitwise AND of Numbers Range LeetCode Solution131
1059Custom Sort String Leetcode Solution131
1060Generate Parentheses Leetcode Solution131
1061Minimum Index Sum of Two Lists130
1062Largest BST Subtree LeetCode Solution130
1063Number of palindromic paths in a matrix130
1064Path Sum II LeetCode Solution130
1065Iterative Depth First Traversal of Graph130
1066Employee Importance LeetCode Solution130
1067Find whether a subarray is in form of a mountain or not129
1068Binary Tree Data Structure129
1069Minimum Size Subarray Sum129
1070Count minimum steps to get the given desired array129
1071Remove Duplicates from Sorted Array II Leetcode Solution129
1072Find Smallest Range Containing Elements from k Lists129
1073Maximum length subsequence with difference between adjacent elements as either 0 or 1129
1074Number of Students Doing Homework at a Given Time Leetcode Solution129
1075Available Captures for Rook Leetcode Solution129
1076Find Peak Element129
1077Count pairs from two sorted arrays whose sum is equal to a given value x129
1078Serialize and Deserialize Binary Tree LeetCode Solution129
1079Rearrange array such that even index elements are smaller and odd index elements are greater129
1080Regular Expression Matching Regular Expression Matching LeetCode Solution129
1081Kth Smallest Element in a Sorted Matrix LeetCode Solution129
1082Distinct Subsequences129
1083Longest Bitonic Subsequence128
1084Constant time range add operation on an array128
1085Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution128
1086Clone a Binary Tree with Random Pointers128
1087Increasing Triplet Subsequence LeetCode Solution128
1088Remove Palindromic Subsequences Leetcode Solution128
1089Lowest Common Ancestor128
1090Smallest Common Region Leetcode Solution128
1091Remove duplicates from sorted array128
1092Combination Sum IV LeetCode Solution128
1093Number of Closed Islands Leetcode Solution128
1094Search in Sorted Rotated Array128
1095Populating Next Right Pointers in Each Node Leetcode Solution128
1096Maximize Distance to Closest Person LeetCode Solution128
1097Kth Smallest Product of Two Sorted Arrays LeetCode Solution128
1098Print all triplets in sorted array that form AP127
1099Types of Binary Tree127
1100Find the minimum distance between two numbers127
1101Number of siblings of a given Node in n-ary Tree127
1102Root to Leaf path with target sum Leetcode Solutions127
1103Next Permutation Leetcode Solution127
1104Subarrays with K Different Integers Leetcode Solution127
1105Path Sum126
1106Find Three Element From Different Three Arrays Such That a + b + c = sum126
1107Day of the Year Leetcode Solution126
1108Divisible Pairs Counting126
1109Print Next Greater Number of Q queries126
1110Find maximum difference between nearest left and right smaller elements126
1111Reformat The String Leetcode Solution125
1112Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution125
1113Sum of Even Numbers After Queries125
1114Minimum Score Triangulation of Polygon Leetcode Solution125
1115Third Maximum Number Leetcode Solution125
1116Write Code to Determine if Two Trees are Identical125
1117Cells with Odd Values in a Matrix LeetCode Solution125
1118Count Largest Group Leetcode Solution124
1119Thousand Separator Leetcode Solution124
1120Print Right View of a Binary Tree124
1121Mean of Array After Removing Some Elements Leetcode Solution124
1122Topological Sorting124
1123Maximum Product Subarray124
1124Consecutive Characters LeetCode Solution124
1125Bottom View of a Binary Tree124
1126Minimum Absolute Difference in BST Leetcode Solution124
1127Convert BST into a Min-Heap without using array124
1128Level of Each node in a Tree from source node124
1129Moser-de Bruijn Sequence124
1130Prime Palindrome LeetCode Solution123
1131Diameter of N-Ary Tree LeetCode Solution123
1132Palindrome Permutation LeetCode Solution123
1133Subset Sum Problem in O(sum) space123
1134Products of ranges in an array123
1135Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution123
1136Cutting a Rod123
1137Longest Subarray of 1’s After Deleting One Element LeetCode Solution123
1138Search Insert Position123
1139Queries for Number of Distinct Elements in a Subarray122
1140Search an Element in Sorted Rotated Array122
1141Closest Binary Search Tree Value Leetcode Solution122
1142Swap Nodes In Pairs122
1143Check Array Formation Through Concatenation Leetcode Solution122
1144Maximum Binary Tree122
1145Golomb sequence122
1146Valid Tic-Tac-Toe State LeetCode Solution122
1147Bus Routes Leetcode Solution121
1148Minimum sum of squares of character counts in a given string after removing k characters121
1149Kth Smallest Number in Multiplication Table Leetcode Solution121
1150Construct K Palindrome Strings LeetCode Solution121
1151Find a sorted subsequence of size 3 in linear time121
1152Merge two BSTs with limited extra space121
1153Minimum Sideway Jumps LeetCode Solution121
1154Iterative method to find ancestors of a given binary tree121
1155Print modified array after executing the commands of addition and subtraction121
1156Binary Tree to Binary Search Tree Conversion120
1157Factorial Trailing Zeroes LeetCode Solution120
1158Transform a BST to Greater sum Tree120
1159Find the smallest binary digit multiple of given number120
1160Longest Increasing Consecutive Subsequence120
1161Find maximum length Snake sequence120
1162Possible Bipartition LeetCode Solution120
1163Find Largest Value in Each Tree Row LeetCode Solution119
1164Red-Black Tree Introduction119
1165Longest Repeated Subsequence119
1166Maximize sum of consecutive differences in a circular array119
1167Search Suggestions System LeetCode Solution119
1168Maximum Product of Splitted Binary Tree LeetCode Solution119
1169Minimum Cost to Move Chips to The Same Position LeetCode Solution119
1170Count even length binary sequences with same sum of first and second half bits119
1171Palindromic Substrings Leetcode Solution119
1172Swapping Nodes in a Linked List Leetcode Solution119
1173Number of Orders in the Backlog Leetcode Solution118
1174Delete Nodes and Return Forest Leetcode Solution118
1175Compare Strings by Frequency of the Smallest Character Leetcode Solution118
1176Priority Queue118
1177Decision Tree118
1178Decrease Elements To Make Array Zigzag LeetCode Solution118
1179Count Pairs Whose Products Exist in Array118
1180Rotate Array118
1181Graph and its representation118
1182Minimum Moves to Equal Array Elements LeetCode Solution118
1183Maximum sum bitonic subarray118
1184K’th Largest element in BST using constant extra space118
1185Reverse a Path in BST using Queue117
1186Lowest Common Ancestor in Binary Search Tree117
1187Contiguous Array LeetCode Solution117
1188Matchsticks to Square Leetcode Solution117
1189How to print maximum number of A’s using given four keys117
1190Web Crawler LeetCode Solution117
1191Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution117
1192Queue Reconstruction by Height117
1193Valid Triangle Number117
1194Maximum sum of pairs with specific difference116
1195Kth Smallest Element in a BST116
1196Convert Sorted Array to Binary Search Tree LeetCode Solutions116
1197First Bad Version116
1198Closest Leaf in a Binary Tree LeetCode Solution116
1199Maximum number of segments of lengths a, b and c116
1200Array Queries for multiply replacements and product115
1201Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution115
1202Guess The Word115
1203Given a binary tree, how do you remove all the half nodes?115
1204Minimum Swaps To Make Sequences Increasing LeetCode Solution115
1205Sum of Left Leaves LeetCode Solution115
1206Integer Break LeetCode Solution115
1207Moving Stones Until Consecutive Leetcode Solution115
1208Concatenation of Array LeetCode Solution115
1209Replace two consecutive equal values with one greater114
1210Lowest Common Ancestor of a Binary Tree Leetcode Solution114
1211Divide Two Integers Leetcode Solution114
1212Range Sum Query using Sparse Table114
1213Champagne Tower LeetCode Solution113
1214Reformat Date LeetCode Solution113
1215Largest Plus Sign Leetcode Solution113
1216Perfect Squares LeetCode Solution113
1217Power of Two113
1218Path Crossing Leetcode Solution113
1219Arithmetic Slices II – Subsequence LeetCode Solution113
1220Maximum Depth Of Binary Tree113
1221Valid Perfect Square LeetCode Solution113
1222Mean of range in array112
1223Print modified array after multiple array range increment operations112
1224The kth Factor of n Leetcode Solution112
1225LRU Cache Leetcode Solution112
1226Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution112
1227Write a function to get the intersection point of two Linked Lists112
1228Parallel Courses II LeetCode Solution112
1229Longest Common Prefix Using Word by Word Matching112
1230Merge Sort112
1231Check Completeness of a Binary Tree LeetCode Solution112
1232Flatten 2D Vector LeetCode Solution112
1233New 21 Game112
1234Maximum Value at a Given Index in a Bounded Array LeetCode Solution111
1235Maximize Elements Using Another Array111
1236Symmetric Tree LeetCode Solution Leetcode Solution111
1237Print n terms of Newman-Conway Sequence111
1238Queries on Probability of Even or Odd Number in given Ranges111
1239Sliding Window Median Leetcode Solution111
1240Maximum sum of a path in a Right Number Triangle111
1241BST to a Tree with Sum of all Smaller Keys111
1242Find Minimum in Rotated Sorted Array II LeetCode Solution111
1243Range Queries for Longest Correct Bracket Subsequence111
1244Bold Words in String LeetCode Solution111
1245Check if each internal node of a BST has exactly one child110
1246Check for Identical BSTs without building the trees110
1247Graph Cloning110
1248Design Skiplist LeetCode Solution110
1249Check if all levels of two Binary Tree are anagrams or not110
1250Maximum Product Subarray110
1251Contiguous Array109
1252Maximum Array from Two given Arrays Keeping Order Same109
1253Find minimum number of merge operations to make an array palindrome109
1254Count Subsets Having Distinct Even Numbers109
1255Missing Number109
1256Image Overlap LeetCode Solution108
1257Smallest Range II Leetcode Solution108
1258Count and Toggle Queries on a Binary Array108
1259Excel Sheet Column Title LeetCode Solution108
1260Min Cost Climbing Stairs LeetCode Solution107
1261Number of elements less than or equal to a given number in a given subarray107
1262Minimum Remove to Make Valid Parentheses LeetCode Solution107
1263Koko Eating Bananas LeetCode Solution107
1264Merge k Sorted Lists Leetcode Solution107
1265Print Ancestors of a Given Binary Tree Node Without Recursion107
1266Verify Preorder Serialization of a Binary Tree106
1267Palindrome Partitioning106
1268Check If a String Can Break Another String Leetcode Solution106
1269Find k-th smallest element in BST (Order Statistics in BST)106
1270Next greater element105
1271Peeking Iterator LeetCode Solution105
1272Different Ways to Add Parentheses Leetcode Solution105
1273Check if two nodes are on the same path in a Tree105
1274Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1275Orderly Queue LeetCode Solution103
1276Merge Sorted Array103
1277Longest Substring Without Repeating Characters Leetcode Solution102
1278Check in binary array the number represented by a subarray is odd or even102
1279Newman–Shanks–Williams prime102
1280Check if X can give change to every person in the Queue101
1281Largest Submatrix With Rearrangements LeetCode Solution101
1282Arranging Coins Leetcode Solution101
1283Encoded String With Shortest Length LeetCode Solution100
1284Maximum Sum Increasing Subsequence99
1285Find maximum average subarray of k length98
1286Minimum Total Space Wasted With K Resizing Operations LeetCode Solution98
1287Minimum Number of People to Teach LeetCode Solution97
1288Queries for Decimal Values of Subarrays of a Binary Array97
1289Number of indexes with equal elements in given range97
1290Range Minimum Query (Square Root Decomposition and Sparse Table)97
1291Array Nesting Leetcode Solution97
1292Maximum product of an increasing subsequence96
1293Binary Tree to Binary Search Tree Conversion using STL set95
1294Find the Winner of the Circular Game LeetCode Solution95
1295Check given array of size n can represent BST of n levels or not94
1296Convert a BST to a Binary Tree such that sum of all greater keys is added to every key94
1297Continuous Subarray Sum LeetCode Solution94
1298Convert to Base -2 LeetCode Solution94
1299Random Pick Index LeetCode Solution94
1300Add Two Numbers II Leetcode Solution94
1301Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1302Vertical Order Traversal of Binary Tree LeetCode Solution93
1303Palindrome Number LeetCode Solution93
1304Insert Delete GetRandom O(1) Leetcode Solution93
1305Jump Game IV LeetCode Solution93
1306Queries on XOR of greatest odd divisor of the range93
1307Reach a Number LeetCode Solution92
1308Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution91
1309Design Underground System Leetcode Solution89
1310Detect Capital Leetcode Solution86
1311Print Maximum Length Chain of Pairs86
1312Design A Leaderboard Leetcode Solution85
1313Substring with Concatenation of All Words Leetcode Solution82
1314Minimum Swaps to Group All 1’s Together Leetcode Solution80
1315Top K Frequent Elements LeetCode Solution79
1316Count Sub Islands LeetCode Solution78
1317Minimum Path Sum Leetcode Solution78
1318Best Meeting Point LeetCode Solution76
1319Binary Tree Inorder Traversal LeetCode Solution76
1320Shifting Letters LeetCode Solution75
1321Decode String Leetcode Solution74
1322Find the Town Judge LeetCode Solution74
1323Longest Common Subsequence LeetCode Solution74
1324Odd Even Linked List Leetcode Solution73
1325Maximum Population Year LeetCode Solution73
1326Find the Town Judge LeetCode Solution72
1327Sum Root to Leaf Numbers LeetCode Solution71
1328Shortest Unsorted Continuous Subarray LeetCode Solution71
1329Design Add and Search Words Data Structure LeetCode Solution68
1330Rectangle Overlap LeetCode Solution67
1331Maximum Population Year LeetCode Solution66
1332Score of Parenthesis LeetCode Solution65
1333Range Sum Query 2D – Immutable LeetCode Solution65
1334Stone Game IV LeetCode Solution65
1335Insert into a Sorted Circular Linked List LeetCode Solution65
1336Flatten Binary Tree to Linked List LeetCode Solution64
1337Reveal Cards In Increasing Order Leetcode Solution62
1338Is Graph Bipartite? LeetCode Solution62
1339Valid Triangle Number LeetCode Solution60
1340Divide Chocolate LeetCode Solution52
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution47
1342Range Sum of BST LeetCode Solution45
1343Sort Colors LeetCode Solution42
1344Reverse Integer Leetcode Solution41
1345Find K Closest Elements LeetCode Solution38
1346Excel Sheet Column Number LeetCode Solution36
1347Rotate String LeetCode Solution36
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution35
1349Maximum Size Subarray Sum Equals k Leetcode Solution18
1350H-Index Leetcode Solution15
1351High Five LeetCode Solution14
Translate »