Implement Rand10() Using Rand7() Leetcode Solution

Difficulty Level Medium
Frequently asked in ByteDance LinkedIn Microsoft Uber Yandex
Math Probability and Statistics RandomizedViews 27

Problem Statement:

Implement Rand10() Using Rand7() Leetcode Solution –  Given the API rand7() that generates a uniform random integer in the range [1, 7], write a function rand10() that produces a uniform random integer in the range [1, 10]. You can only call the API rand7(), and you shouldn’t call any other API. Please do not use a language’s built-in random API.

Each test case will have one internal argument n, the number of times your implemented function rand10() will be called while testing. Note that this is not an argument passed to rand10().

Example:

Example 1:

Input: n = 3
Output: [3, 8, 10]

Explanation:

Implement Rand10() Using Rand7() Leetcode SolutionPin

Example 2:

Input: n = 2
Output: [2,8]

Approach:

Idea:

  1. First, we declare 2 variables, n and m, setting them initially to be rand7() and 7.
  2. Then we make sure that n is only in the 1 - 5 range and, if not, we regenerate it and assign n - 5 to m, that thus would be in the 1 - 2 range. Note that in this way n and m have the same probability of still being each specific number in their own range.
  3. In the second loop, we make sure that m has a 1 - 6 value, with similar logic of regenerating numbers until we need them.
  4. Finally, we return n or n + 5, depending if m is even or odd, respectively.

Code:

C++ Program of Implement Rand10() Using Rand7() :

class Solution {
public:
    int rand10() {
        int n, m;
        n = rand7(), m = 7;
        
    while (n > 5) {
            m = n - 5;
            n = rand7();
        }
       
    while (m == 7) m = rand7();
        return (m % 2 ? 5 : 0) + n;
    }
};

Java Program of Implement Rand10() Using Rand7() :

class Solution extends SolBase {
    public int rand10() {
        int n, m;
        n = rand7();
        m = 7;
        
    while (n > 5) {
            m = n - 5;
            n = rand7();
        }
       
    while (m == 7) m = rand7();
        if (m % 2 == 0) return n;
        else return n+5;
    }
}

Complexity Analysis for Implement Rand10() Using Rand7() Leetcode Solution:

Time Complexity:

The Time Complexity of the code is  O(1) in the average case but in the worst case.

Space Complexity:

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

Question to practice randomized problems:

Insert Delete GetRandom O(1) Leetcode Solution

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Palindrome using Recursion2625
3Java program to find the number of Nodes in a Binary Tree2543
4Reverse a string without affecting special characters2527
5Delete a node of a linked list at given position2022
6Quick Sort1771
7Insert nodes in a linked list in a sorted way (Ascending Order)1713
8Find elements pair from array whose sum equal to number1690
9Sort Elements by Frequency of Occurrences1673
10Write a program to print all permutations of a given string1656
11Find Minimum Distance Between Two Numbers in an Array1520
12Create a Doubly Linked List1484
13Reverse an Array1466
14Smallest window in a string containing all characters of another string1440
15Recursively remove all adjacent duplicates1410
16Find a Triplet That Sum to a Given Value1393
17First Repeating Element1387
18Sum of numbers in String1365
19Arrange Even and Odd number such that Odd comes after Even1357
20Smallest Positive Number Missing in an Unsorted Array1326
21Check if the Elements of an Array are Consecutive1294
22Detect a loop in the Linked List1273
23Largest Sum Contiguous Subarray1264
24Quick Sort on SIngly Linked List1260
25Recursive function to do substring search1252
26Print all Possible Combinations of R Elements in a given Array of size N1250
27Subarray with Given Sum1248
28Find the Maximum Repeating Number in Array1206
29Find the First and Second Smallest Elements1156
30Binary Tree Level order traversal in Java1156
31Check if two linked lists are identical1144
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1115
34Find Leaders in an Array1094
35Swap nodes in the linked list1087
36Find the second most frequent character1036
37Find the Number Occurring Odd Number of Times in an Array1036
38Arrange given Numbers to Form the Biggest Number II1027
39Given a string find its first non-repeating character1017
40Find Triplet in Array With a Given Sum1002
41Given a sorted array and a number x, find the pair in array whose sum is closest to x995
42A Program to check if strings are rotations of each other or not992
43Total number of occurrences of a given item in the linked list991
44Print all possible words from phone digits975
45Find the Missing Number966
46Rearrange Positive and Negative Numbers Alternatively in Array953
47Longest Palindromic Substring947
48Segregate even and odd nodes in a linked list937
49Print Longest common subsequence927
50Transform one string to another using minimum number of given operations916
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome899
53Rearrange given Array in Maximum Minimum Form879
54Iterative Implementation of Quick Sort869
55Insertion Sort858
56Count Possible Triangles857
57Multiplication of Two Matrices843
58Count of Triplets With Sum Less than Given Value830
59Rotate a Linked List828
60Check if the linked list is palindrome828
61Stock Buy Sell to Maximize Profit827
62Concatenation of two strings808
63Tug of War799
64Print all duplicates in the input string798
65Count Number of Substrings with K Distinct Character’s797
66Find Nearest Greater and Smaller Element785
67Reverse String Without Temporary Variable778
68Remove ‘b’ and ‘ac’ from a given string771
69The Celebrity Problem771
70Find Pythagorean Triplets from Array770
71Find all Common Elements in Given Three Sorted Arrays765
72Remove all duplicates in an unsorted linked list741
73Find the subarray whose sum is equal to a given number X739
74Find the Row with Maximum Number of 1’s739
75Remove Minimum Characters so that Two Strings Become Anagrams738
76Find the Peak Element from an Array735
77Addition of Two Matrices731
78Find Smallest Missing Number in a Sorted Array727
79Generate all Binary Strings Without Consecutive 1’s727
80A Product Array Puzzle724
81Maximum Sum of Non Consecutive Elements710
82Implement Two Stacks in an Array708
83Lexicographic rank of string701
84Check if Two given Matrices are Identical693
85Maximum Product Subarray II687
86Multiplication of Previous and Next682
87Subtraction of Two Matrices674
88Merge K Sorted Arrays and Print Sorted Output670
89Move All the Zeros to the End of the Given Array668
90Divide a string in N equal parts667
91Online Algorithm for Checking Palindrome in a Stream666
92Form Minimum Number from Given Sequence of D’s and I’s665
93Check whether two strings are anagram of each other660
94Remove recurring digits in a given number657
95Sort a stack using a temporary stack654
96Maximum Circular Subarray Sum651
97Sort a linked list that is sorted alternating ascending and descending645
98Subarray and Subsequence640
99Find the Minimum Element in a Sorted and Rotated Array638
100Move last element of the Linked List at first place635
101First Circular Tour to Visit all the Petrol Bunks633
1023Sum Leetcode Solution632
103Compare two strings(linked lists)630
104Maximum Element in an Array which is Increasing and then Decreasing629
105Palindrome Permutations of a String628
106Largest Subarray with Equal Number of 0’s and 1’s627
107Palindromes in a given range624
108Flattening a linked list623
109Pangram Checking619
110Minimum insertions to form a shortest palindrome619
111Majority Element618
112Run length encoding618
113Print all permutations with repetition616
114Elements Appear more than N/K times in Array611
115Minimum Characters to be Added at Front to Make String Palindrome610
116Most repeating character in a string607
117Two Sum Leetcode Solution605
118Repeated Subsequence of Length Two or More604
119Rotate string to get lexicographically minimum string603
120Merge a linked list into another at alternate positions596
121Remove all duplicates in a sorted linked list596
122Rearrange a given linked list in-place594
123Minimum number of Merge Operations to make an Array Palindrome594
124Print all anagrams together in a sequence of words593
125Reorder an Array According to the Given Indexes582
126Pancake Sorting Problem582
127Smallest Palindrome after Replacement569
128Remove duplicates from a string568
129Longest Palindrome can be Formed by Removing or Rearranging Characters568
130Merge Overlapping Intervals II568
131Transpose of a Matrix568
132Clone a Linked List with next and random pointer566
133Remove Extra Spaces from a String565
134Removing Spaces from a String using stringstream562
135Maximum Sum Increasing Subsequence560
136Check if a given string is a rotation of a palindrome560
137Size of The Subarray With Maximum Sum558
138Partition Problem554
139Check whether Strings are K Distance Apart or Not549
140Generate all Binary Strings from Given Pattern547
141Length of Longest valid Substring543
142Delete Last Occurrence542
143Check if Two given Strings are Isomorphic to each other541
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized537
145Insert Node in the Sorted Linked List533
146Program to Toggle all Characters in a String532
147Given string is interleaving of two other strings or not527
148Maximum difference between two elements such as larger element comes after smaller525
149Check length of a String is Equal to the Number Appended at its Last517
150Count Minimum Steps to Get the given Array515
151Number of Smaller Elements on Right Side512
152Check if all Rows of a Matrix are Circular Rotations of Each Other509
153Longest Common Prefix using Divide and Conquer508
154Find Pair with Given Difference507
155Merge sort better than quick sort for linked lists506
156Compare Two Version Numbers503
157Print all interleavings of given two strings501
158Find nth node of the Linked list from the end500
159Sort 0s 1s and 2s in an Array499
160Print Reverse of a string (Recursion)497
161Median of Two Sorted Arrays LeetCode Solution496
162Find a Fixed Point in a Given Array496
163Reverse words in a given string494
164Reorder Array Using Given Indexes494
165Find the Subarray of given length with Least Average486
166Merge two sorted linked lists such that merged list is in reverse order486
167Split linked list using alternate nodes485
168Print all Palindromic Partitions of a String477
169Print string of odd length in ‘X’ format476
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average467
172Swap Kth Node from beginning with Kth Node from End465
173Find Duplicates in an Array in Most Efficient Way460
174Shortest Superstring Problem458
175print all palindromic partitions456
176Check if String Follows Order of Characters by a Pattern or not452
177Sort a String According to Another String449
178Maximum Length of Chain Pairs449
179Flatten a multilevel linked list445
180Sorting a K Sorted Array440
181Program to add two binary digits436
182Recursively print all the sentences that can be formed from list of word lists432
183Caesar Cipher430
184Find a Sorted Subsequence of size 3429
185Find the two Numbers with Odd Occurrences in an Unsorted Array427
186Longest Span with same Sum in two Binary Arrays II427
187Longest Common Prefix Using Binary Search II427
188Reverse a Linked List in groups426
189Kth Non-repeating Character424
190Reverse a Singly Linked List (Iterative/Non-Recursive)423
191Check if String can Become Empty by Recursively Deleting given Substring419
192Longest Common Prefix Word by Word Matching415
193Rearrange a linked list in Zig-Zag412
194Pancake Sorting408
195Permutations of a Given String Using STL408
196Rotate Image by 90 degrees408
197Perfect Reversible String407
198Merging Two Sorted Arrays405
199Find First non-repeating character in a string403
2001`s and 2`s complement of binary number402
201Maximum occurring character in a string397
202List items containing all characters of a given word396
203Increasing Subsequence of Length three with Maximum Product396
204Find the point where a monotonically increasing function becomes positive first time394
205Four Elements that Sum to Given391
206Sort a linked list with 0s, 1s and 2s390
207Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes388
208Longest Common Prefix using Character by Character Matching388
209Count Number of Occurrences in a Sorted Array385
210Palindrome string (number)384
211Delete N nodes after M382
212Valid Parentheses LeetCode Solution382
213Minimum Characters to be Removed to Make a Binary String Alternate381
214Even Substring Count377
215Split a string377
216Recursive Implementation of atoi()374
217Sorting the array of strings373
218Print Shortest Path to Print a String on Screen370
219Convert a String that is Repetition of a Substring of Length K370
220Check if a Linked list of Strings form a Palindrome367
221Maximum Subarray Leetcode Solution366
222Nth Character in Concatenated Decimal String365
223Convert string1 to string2 in one edit364
224Count the number of words361
225wildcard character matching361
226Reverse a singly linked list recursively361
227Print All Distinct Elements of the Array361
228Reverse a String using Stack360
229Find the first Repeating Number in a Given Array359
230Matrix Chain Multiplication using Dynamic Programming358
231Lower Case To Upper Case355
232Can we reverse a linked list in less than O(n) time ?352
233Binary Tree to Doubly linked list350
234Longest Common Subsequence with Permutations347
235Sort Elements by Frequency II346
236Find the Lost Element From a Duplicated Array344
237Split Four Distinct Strings343
238Merge Two Sorted Arrays341
239Roman to Integer Leetcode Solution338
240Find middle of the Linked List338
241Count the Pairs at Same Distance as in English Alphabets337
242Toeplitz Matrix333
243Move all negative elements to one side of array330
244N queen problem329
245Palindrome Permutation328
246Word Search Leetcode Solution326
247Next Greater Element in an Array325
248Sudoku Solver323
249First non Repeating Element320
250Find All Pairs With a Given Difference318
251Searching a node in a Binary Search Tree318
252Reverse Bits317
253Count Pairs With Given Sum317
254String(represents an integer) to value316
255Print all Possible Ways to Break a String in Bracket Form316
256Number of Islands LeetCode Solution315
257Find Nth Node315
258Change Gender of a given String313
259Fibonacci numbers313
260Reverse a String313
261Types of Binary Tree312
262Repeated Substring Pattern312
263Triplet from three linked lists with given sum312
264Sort an array of strings311
265Delete a Tree311
266Reverse a linked list309
267Min Stack309
268Meeting Rooms II LeetCode Solution308
269Number of sub-strings which recursively add up to 9308
270Delete a node under given conditions308
271How to Efficiently Implement k Stacks in a Single Array?308
272Most Frequent Element in an Array307
273Longest Palindromic Substring LeetCode Solution305
274Cuckoo sequence program305
275Dijkstra Algorithm305
276Longest Common Extension302
277House Robber Leetcode Solution300
278Max stack299
279Binary Tree299
280Remove spaces from a string298
281Subset Leetcode294
282Best Time to Buy and Sell Stock  II Leetcode Solution293
283Word Search292
284Shuffle a given Array291
285KMP Algorithm290
286Minimize the maximum difference between the heights289
287Expression Evaluation289
288Sliding Window Technique289
289Remove middle points in a linked list of line segments288
290Find, second, frequent, character288
291Number Of 1 bits287
292Plus One Leetcode Solution287
293Combination Sum Leetcode Solution286
294Search Insert Position Leetcode Solution285
295Reverse words in a string284
296Pair of Positive Negative Values in an Array284
297Evaluation of Postfix Expression283
298Min Stack Leetcode Solution280
299Valid Palindrome Leetcode Solution279
300Set Matrix Zeroes279
301Subarray with 0 sum279
302Rabin Karp Algorithm278
303Backspace String Compare277
304Common elements in all rows of a given matrix274
305Sort linked which is sorted on absolute values273
306Merge Sorted Arrays Leetcode Solution272
307Clone a linked list with next and random pointer (Hashing)272
308Reversing a Queue271
309Sqrt(x) Leetcode Solution270
310Delete middle element of a stack270
311Implementation of Deque using Doubly Linked List268
312Contains Duplicate268
313Tower Of Hanoi268
314Find Top K (or Most Frequent) Numbers in a Stream267
315Count Odd Numbers in an Interval Range Leetcode Solution266
316String Compression266
317Count subarrays with equal number of 1’s and 0’s266
318How to Delete a Linked List265
319Count of index pairs with equal elements in an array265
320Product of array except self265
321Contains Duplicate II Leetcode Solution265
322Page Replacement Algorithms in Operating Systems265
323Combination Sum264
324Intersection of Two Arrays II Leetcode Solution264
325Reverse individual words264
326Pascal Triangle Leetcode263
327Minimum swaps required to bring all elements less than or equal to k together263
328Segregate even and odd numbers262
329Find sum of non-repeating elements (distinct) elements in an array261
330Group Words With Same Set of Characters261
331Integer to Roman Leetcode Solution261
332Bellman Ford Algorithm260
333Single Number Leetcode Solution260
334Smallest Subarray with k Distinct Numbers259
335Postfix to Infix Conversion259
336Sorting array using Stacks259
337Minimum Value to Get Positive Step by Step Sum Leetcode Solution259
338Second Most Repeated Word in a Sequence259
339Sort elements by frequency259
340Sum of minimum and maximum elements of all subarrays of size k258
341Arithmetic Expression Evaluation258
342Count subarrays having total distinct elements same as original array257
343Next Permutation257
344K-th Smallest Element in a Sorted Matrix256
345Top K Frequent Words256
346Add Binary Leetcode Solution256
347Given two unsorted arrays find all pairs whose sum is x255
348Maximum Number of Balloons Leetcode Solution255
349Convex Hull Algorithm254
350Minimum operation to make all elements equal in array254
351Construct Binary Tree from Given Inorder and Preorder Traversals254
352Longest Substring Without Repeating Characters LeetCode Solution253
353Design a stack that supports getMin() in O(1) time and O(1) extra space252
354Longest Common Prefix Leetcode Solution252
355Special Number252
356First element occurring k times in an array252
357Scramble String252
358Pow(x, n) Leetcode Solution252
359Palindrome Linked List Leetcode Solution251
360Find Lucky Integer in an Array Leetcode Solution250
361Majority Element Leetcode Solution250
362Find duplicates in a given array when elements are not limited to a range250
363Evaluate Division249
364Kruskal Algorithm248
365Permutations Leetcode Solution248
366Running Sum of 1d Array Leetcode Solution247
367Check if two arrays are equal or not246
368Third Maximum Number Leetcode Solution246
369Maximum possible difference of two subsets of an array245
370Fizz Buzz Leetcode245
371Huffman Coding244
372Spiral Matrix LeetCode Solution244
373Prefix to Infix Conversion244
374Minimum Path Sum244
375Reversing the First K elements of a Queue244
376Number of Good Pairs Leetcode Solution243
377Maximal Square243
378Maximum Distance Between two Occurrences of Same Element in Array243
379Reverse a Number Using Stack243
380Maximum Subarray243
381Find the Town Judge Leetcode Solution242
382Range Sum Query 2D – Immutable Leetcode Solution242
383Smallest Element Repeated Exactly K Times242
384Convert String To Int242
385Minimum Steps to reach target by a Knight241
386Unique Paths241
387Group Anagrams241
388Find Numbers with Even Number of Digits Leetcode Solution241
389Count Primes Leetcode Solutions241
390Palindrome Substring Queries241
391Single Number240
392Find the Closest Palindrome number240
393Swap Nodes in Pairs Leetcode Solutions240
394Zigzag Conversion240
395Minimum Absolute Difference Leetcode Solution240
396Find the first repeating element in an array of integers240
397Find top three repeated in array239
398Find All Numbers Disappeared in an Array Leetcode Solution239
399Find Number of Employees Under every Employee239
400Sorting using trivial hash function239
401Remove Minimum Number of Elements Such That no Common Element Exist in both Array239
402Cumulative Frequency of Count of Each Element in an Unsorted Array239
403Sort Array by Increasing Frequency Leetcode Solution238
404Print All Distinct Elements of a Given Integer Array237
405Fizz Buzz237
406Implement Stack and Queue using Deque236
407Pascal’s Triangle II Leetcode Solution236
408Check if Array Contains Contiguous Integers With Duplicates Allowed236
409Missing Number Leetcode Solution236
410Leetcode Permutations236
411Power of Two Leetcode Solution236
412Count Substrings with equal number of 0s, 1s and 2s235
413How to Implement Stack Using Priority Queue or Heap?235
414Letter Case Permutation235
415Print all subarrays with 0 sum235
416Length of the largest subarray with contiguous elements235
417Expression Contains Redundant Bracket or Not235
418Merge Two Sorted Lists Leetcode Solutions235
419Matrix Diagonal Sum Leetcode Solution235
420Prim’s Algorithm234
421Difference between highest and least frequencies in an array234
422House Robber II Leetcode Solution234
423Sort Integers by The Number of 1 Bit Leetcode Solution234
424Decode String234
425Subarray Sum Equals k234
426Bipartite Graph234
427Unique Paths Leetcode Solution234
428LRU Cache Implementation233
429Happy Number Leetcode Solution233
430Maximum Depth of Binary Tree Leetcode Solution233
431Top K Frequent Elements233
432Sort a stack using recursion233
433Subset sum problem232
434Reverse Integer232
435Count pairs from two linked lists whose sum is equal to a given value231
436Coin Change 2 Leetcode Solution231
437Find Median from data Stream231
438Subarrays with distinct elements231
439Search in Rotated Sorted Array Leetcode Solution231
440Find all pairs (a, b) in an array such that a % b = k231
441Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution230
442Find Winner on a Tic Tac Toe Game Leetcode Solution230
443Pair with given product229
444Check If N and Its Double Exist Leetcode Solution229
445Find elements which are present in first array and not in second229
446Nth Catalan Number229
447Monotonic Array LeetCode Solution229
448Reverse a Stack Using Recursion228
449Find the Difference Leetcode Solution228
450How Many Numbers Are Smaller Than the Current Number Leetcode Solution228
451Capacity To Ship Packages Within D Days Leetcode Solution228
452Max Consecutive Ones Leetcode Solution228
453Intersection of Two Arrays227
454Find The Duplicate Number227
455Integer to English words227
456Valid Parenthesis String227
457Fibonacci Number LeetCode Solution226
458Text Justification LeetCode Solution226
459Edit Distance226
460Count and Say226
461Priority Queue Using Singly Linked List226
462Find distinct elements common to all rows of a matrix226
463Subarray Sum Equals K LeetCode Solution226
464Longest subarray not having more than K distinct elements225
465Best Time to Buy and Sell Stock III Leetcode Solution225
466Find Index of Closing Bracket for a Given Opening Bracket in an Expression225
467Reverse a String225
468Find Minimum In Rotated Sorted Array225
469Sum of Subarray Ranges Leetcode Solution225
470Find four elements that sum to a given value (Hashmap)225
471Rearrange a binary string as alternate x and y occurrences225
472Trapping Rain Water Leetcode Solution225
473Subtract the Product and Sum of Digits of an Integer Leetcode Solution225
474Find any one of the multiple repeating elements in read only array225
475Floyd Warshall Algorithm224
476Remove Duplicates from Sorted Array Leetcode Solution224
477Longest Common Prefix using Trie224
478Design Parking System Leetcode Solution224
479Check if a given array contains duplicate elements within k distance from each other224
480Reverse Vowels of a String Leetcode Solution224
481Target Sum223
482The K Weakest Rows in a Matrix Leetcode Solution223
483Kth largest element in an Array Leetcode Solutions223
484MiniMax Algorithm222
485Jump Game Leetcode Solution222
486Find missing elements of a range222
487Find subarray with given sum (Handles Negative Numbers)222
488Generate a String With Characters That Have Odd Counts Leetcode Solution221
489Delete a Node from linked list without head pointer221
490Find Common Characters Leetcode Solution221
491Prefix to Postfix Conversion221
492Count number of triplets with product equal to given number221
493Shuffle the Array Leetcode Solution220
494Degree of an array220
495Shuffle String Leetcode Solution220
496Substring With Concatenation Of All Words220
497Multiply Strings Leetcode Solution220
498Shortest Palindrome220
499Sorting a Queue without Extra Space220
500Word Ladder LeetCode Solution220
501Flood Fill LeetCode219
502Iterative Tower of Hanoi219
503Priority Queue in C++219
504The Stock Span Problem219
505Balanced Binary Tree Leetcode Solution219
506Top View of Binary Tree219
507Implement Stack using Queues219
508Longest Common Prefix using Sorting219
509Recursion218
510Best Time to Buy and Sell Stock LeetCode Solution218
511Slowest Key Leetcode Solution218
512Container with Most Water218
513Merge Two Sorted Linked Lists218
514K-th Distinct Element in an Array218
515Check for Balanced Parentheses in an Expression218
516Excel Sheet Column Number Leetcode Solution218
517Implement a stack using single queue217
518Valid Sudoku217
519Convert array into Zig-Zag fashion217
520Minimum Delete Operations to make all Elements of Array Same217
521Next Greater Element I Leetcode Solution217
522Iterative Inorder Traversal of a Binary Tree217
523Number of Steps to Reduce a Number to Zero Leetcode Solution217
524Kids With the Greatest Number of Candies Leetcode Solution217
525Hamming Distance217
526Postfix to Prefix Conversion217
527Minimum Knight Moves LeetCode Solution217
528Longest Common Subsequence217
529Peak Index in a Mountain Array217
530Arrange given numbers to form the biggest number216
531Find Sum of all unique sub-array sum for a given array216
532Max Area of Island216
533Concatenation of Array LeetCode Solution216
534Reverse Words in a String III LeetCode Solution216
535Find the Duplicate Element216
536Sum of Left Leaves Leetcode Solutions216
537Count and Say Leetcode Solution216
538Move Zeroes LeetCode Solution216
539Linked List Cycle II LeetCode Solution215
540Jewels and Stones Leetcode Solution215
541Next Greater Frequency Element215
542Minimum Moves to Equal Array Elements Leetcode Solution215
543Change the Array into Permutation of Numbers From 1 to N215
544Find First and Last Position of Element in Sorted Array Leetcode Solution215
545Largest Sum Contiguous Subarray215
546How to check if two given sets are disjoint?214
547Check if a queue can be sorted into another queue using a stack214
548Kth Largest Element in a Stream Leetcode Solution214
549Smallest Subarray With all Occurrences of a Most Frequent Element214
550Group Multiple Occurrence of Array Elements Ordered by first Occurrence213
551Merge Overlapping Intervals213
552Largest Perimeter Triangle Leetcode Solution213
553Gold Mine Problem213
554Count the number of nodes at given level in a tree using BFS213
555Isomorphic Strings Leetcode Solution213
556Maximum sum rectangle in a 2D matrix213
557Excel Sheet Column Title Leetcode Solution212
558Zigzag Conversion LeetCode Solution212
559N-th Tribonacci Number Leetcode Solution212
560Is Subsequence Leetcode Solution212
561Find N Unique Integers Sum up to Zero Leetcode Solution212
562Shuffle an Array212
563Minimum number of subsets with distinct elements211
564Minimum Bracket Reversals211
565Delete Node in a Linked List Leetcode Solution211
566Contiguous Array Leetcode211
567Last Stone Weight211
568Valid Anagrams211
569Summary Ranges Leetcode Solution210
570Minimum Cost to Hire K Workers210
571Find if an Expression has Duplicate Parenthesis or Not210
572Smallest Good Base210
573Integer to Roman210
574Convert a normal BST to Balanced BST210
575Koko Eating Bananas Leetcode Solution210
576Mobile Numeric Keypad Problem209
577Maximum path sum in a triangle209
578Implementation of Deque using circular array209
579Number of Provinces Leetcode Solution208
580Shortest Path in a Grid with Obstacles Elimination LeetCode Solution208
581Decode Ways208
582Distribute Candies to People Leetcode Solution208
583Length of Last Word Leetcode Solution208
584Best Time to Buy and Sell Stock208
5853Sum Closest LeetCode Solution208
586Iterative Method to find Height of Binary Tree207
587Find Words That Can Be Formed by Characters Leetcode Solution207
588Maximum difference between first and last indexes of an element in array207
589Island Perimeter Leetcode Solution207
590Frog Jump Leetcode Solution207
591Longest Increasing Subsequence207
592Build Array From Permutation Leetcode Solution207
593Maximum Distance in Array207
594Relative Sort Array Leetcode Solution207
595Word Pattern206
596Maximum Number of Occurrences of a Substring Leetcode Solution206
597First negative integer in every window of size k206
598Trapping Rain Water LeetCode Solution206
599Delete consecutive same words in a sequence206
600Rotate Image LeetCode Solution206
601Non-overlapping sum of two sets206
602Remove Linked List Elements Leetcode Solution205
60301 Matrix LeetCode Solution205
604Sort Characters By Frequency LeetCode Solution205
605Minimum Operations to convert X to Y205
606Remove All Occurrences of a Substring LeetCode Solution205
607Combinations Leetcode Solution205
608LRU Cache LeetCode Solution205
609Minimum number of distinct elements after removing m items204
610GCD Of Two Numbers204
611Minimum insertions to form a palindrome with permutations allowed204
612Assign Cookies Leetcode Solution204
613Bubble sort using two Stacks204
614Sieve of Eratosthenes204
615The Knapsack Problem204
616Count all subsequences having product less than K204
617XOR Operation in an Array Leetcode Solution204
618Isomorphic Strings203
619Maximum Number of Chocolates to be Distributed Equally Among k Students203
620Reverse a stack without using extra space in O(n)203
621Sum of f(a[i], a[j]) over all pairs in an array of n integers203
622Find minimum difference between any two elements203
623Permutation in String Leetcode Solution203
624Rotate List Leetcode Solution203
625Find the smallest positive integer value that cannot be represented as sum of any subset of a given array203
626Form minimum number from given sequence202
627Find Largest d in Array such that a + b + c = d202
628Stone Game LeetCode202
629K Empty Slots202
630Insert Interval Leetcode Solution201
631How to Create Mergable Stack?201
632Longest Increasing Path in a Matrix LeetCode Solution201
633Find the Duplicate Number LeetCode Solution201
634Convert Sorted Array to Binary Search Tree Leetcode Solution201
635Unique Binary Search Trees201
636Tracking current Maximum Element in a Stack201
637Convert an array to reduced form201
638Same Tree LeetCode Solution200
639Applications of Breadth First Search and Depth First Search200
640Defanging an IP Address Leetcode Solution200
641Reorganize String200
642Optimal Account Balancing LeetCode Solution200
643Convert a Number to Hexadecimal Leetcode Solution199
644Distance Between Bus Stops Leetcode Solution199
645Count Good Nodes in Binary Tree Leetcode Solution199
646Employee Free Time LeetCode Solution199
647Word Wrap Problem199
648Find Pair with Greatest Product in Array199
649Merge Two Balanced Binary Search Trees198
650Minimum Depth of Binary Tree Leetcode Solution198
651Printing brackets in Matrix Chain Multiplication Problem198
652Find pairs with given sum such that elements of pair are in different rows198
653First Unique Character in a String LeetCode Solution198
654License Key Formatting Leetcode Solution198
655Find the node with minimum value in a Binary Search Tree198
656Largest subarray with equal number of 0s and 1s198
657Replace Elements with Greatest Element on Right Side Leetcode Solution197
658Longest Substring with At Most K Distinct Characters LeetCode Solution197
659Letter Combinations of a Phone Number197
660Painting Fence Algorithm197
661Maximum Consecutive Numbers Present in an Array197
662Coin Change Problem197
663K Empty Slots LeetCode196
664Moving Average from Data Stream Leetcode Solution196
665Kth Missing Positive Number Leetcode Solution196
666Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
667Flipping an Image LeetCode Solution196
668Find the Distance Value Between Two Arrays Leetcode Solution196
669House Robber196
670Segregate 0s and 1s in an Array196
671Reservoir Sampling196
672Sort Array By Parity LeetCode Solution196
673Robot Room Cleaner Leetcode Solution196
674Reducing Dishes LeetCode Solution196
675Check If It Is a Straight Line Leetcode Solution196
676Strobogrammatic Number LeetCode Solution195
677Partition Labels LeetCode Solution195
678Maximum Product of Two Elements in an Array Leetcode Solution195
679k-th missing element in increasing sequence which is not present in a given sequence195
680Distance of nearest cell having 1 in a binary matrix195
681Count quadruples from four sorted arrays whose sum is equal to a given value x195
682Valid Palindrome195
683Longest Span with same Sum in two Binary arrays195
684Print the Fibonacci numbers in reverse order195
685String Compression LeetCode Solution195
686String to Integer (atoi) LeetCode Solution195
687Find unique character in a string194
688Queries for counts of array elements with values in given range194
689Longest Substring with At Least K Repeating Characters LeetCode Solution194
690Valid Palindrome II Leetcode Solution194
691Find Leaves of Binary Tree LeetCode Solution194
692Dynamic Programming Basics194
693Partition Array Into Three Parts With Equal Sum Leetcode Solution194
694Power of Four Leetcode Solution194
695Generate all possible sorted arrays from alternate elements of two given sorted arrays193
696Sum of All Odd Length Subarrays Leetcode Solution193
697Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
698Numbers with prime frequencies greater than or equal to k193
699Find Maximum Level sum in Binary Tree193
700Reverse Only Letters LeetCode Solution193
701Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest192
702Remove Invalid Parentheses Leetcode Solution192
703Find the Smallest Divisor given a Threshold Leetcode Solution192
704Binary Tree Maximum Path Sum LeetCode Solution192
705Check If Two String Arrays are Equivalent Leetcode Solution192
706Unique Paths II Leetcode Solution192
707Find whether an array is subset of another array192
708Path With Maximum Minimum Value LeetCode Solution192
709To Lower Case Leetcode Solution192
710Elements to be added so that all elements of a range are present in array191
711Maximum Number of Coins You Can Get Leetcode Solution191
712Edit Distance LeetCode Solution191
713Increasing Decreasing String Leetcode Solution191
714Remove brackets from an algebraic string containing + and – operators191
715Snakes and Ladders LeetCode Solution191
716Find the largest multiple of 3191
717Wiggle Sort191
718Sort Array by Increasing Frequency Leetcode Solution190
719Inorder Successor of a node in Binary Tree190
720Bulb Switcher LeetCode Solution190
721Valid Perfect Square Leetcode Solution190
722Subset Sum Leetcode190
723Check for Palindrome after every character replacement Query190
724Stack Permutations (Check if an array is stack permutation of other)190
725Merge Two Binary Trees LeetCode Solution190
726Minimum Cost For Tickets Leetcode Solution190
727Keyboard Row Leetcode Solution190
728Permutation Sequence LeetCode Solution190
729Number of Dice Rolls With Target Sum LeetCode Solution190
730Base 7 Leetcode Solution190
731Delete Nth node from the end of the given linked list190
732Factorial Trailing Zeroes Leetcode Solution189
733Populating Next Right Pointers in Each Node189
734Non-decreasing Array LeetCode Solution189
735Find if Path Exists in Graph Leetcode Solution189
736Find Maximum Depth of Nested Parenthesis in a String189
737Growable array based stack189
738Recover Binary Search Tree189
739Race Car LeetCode Solution189
740Binary Tree zigzag level order Traversal189
741Reversing a Queue using Recursion189
742Valid Number189
743Number of NGEs to the Right189
744BFS vs DFS for Binary Tree189
745Lucky Numbers in a Matrix Leetcode Solution189
746Perform String Shifts Leetcode188
747Ugly Number Leetcode Solution188
748String comparison containing wildcards188
749Merge Sorted Array LeetCode Solution188
750Maximum Profit in Job Scheduling Leetcode Solution188
751Tiling Problem188
752Binary Tree Zigzag Level Order Traversal LeetCode Solution188
753Minimum sum of multiplications of n numbers188
754Maximum Length of a Concatenated String with Unique Characters Leetcode Solution188
755Morris Traversal187
756Maximum 69 Number Leetcode Solution187
757Print a Binary Tree in Vertical Order187
758Number of Days Between Two Dates LeetCode Solution187
759Priority Queue using doubly linked list187
760Program for Bridge and Torch problem187
761Restore IP Addresses Leetcode Solution187
762Word Pattern LeetCode Solution187
763Count items common to both the lists but with different prices187
764Evaluate Reverse Polish Notation LeetCode Solution187
765Best Meeting Point LeetCode Solution187
766Add and Search Word – Data structure design LeetCode187
767Construct BST from given Preorder Traversal187
768Student Attendance Record I Leetcode Solution187
769Majority Element II Leetcode Solution187
770Finding K closest element186
771Regular Expression Matching186
772Check If Array Pairs Are Divisible by k LeetCode Solution186
773Jump Game186
774Rank Transform of an Array Leetcode Solution186
775N-Queens LeetCode Solution186
776Split a String in Balanced Strings Leetcode Solution186
777Binomial Coefficient186
778Check if Two Expressions With Brackets are Same186
779Sorted Linked List to Balanced BST185
780Find All Duplicates in an Array LeetCode Solution185
781Find Median from Data Stream LeetCode Solution185
782Hamming Distance Leetcode Solution185
783Find All Possible Recipes from Given Supplies LeetCode Solution185
784Minimum Time Visiting All Points Leetcode Solution185
785Brick Wall LeetCode Solution185
786Maximum Product of Three Numbers LeetCode Solution185
787Top K Frequent Words LeetCode Solution185
788Symmetric Tree Leetcode Solution185
789Minimize Maximum Pair Sum in Array LeetCode Solution184
790Sort an array according to the order defined by another array184
791Partition to K Equal Sum Subsets Leetcode Solution184
792Longest Subarray Having Count of 1s One More than Count of 0s184
793Invert Binary Tree LeetCode Solution184
794Search in a Binary Search Tree Leetcode Solution184
795Largest Rectangle in Histogram LeetCode Solution184
796Maximum Nesting Depth of the Parentheses Leetcode Solution184
797Form Minimum Number From Given Sequence184
798Queue based approach for first non-repeating character in a stream184
799Special Array With X Elements Greater Than or Equal X Leetcode Solution184
800Minimum Distance Between BST Nodes Leetcode Solution184
801Minimum Height Trees184
802Circular Queue183
803Maximum Depth of N-ary Tree Leetcode Solution183
804Linked List Cycle183
805Kth ancestor of a node in binary tree183
806Merge K Sorted Linked Lists183
807Total Numbers With no Repeated Digits in a Range183
808Decompress Run-Length Encoded List Leetcode Solution183
809Maximum Difference Between Increasing Elements LeetCode Solution182
810Balanced Expression with Replacement182
811Nearest Exit from Entrance in Maze LeetCode Solution182
812Nested List Weight Sum II LeetCode Solution182
813Remove Nth Node From End of List Leetcode Solution182
814One Edit Distance LeetCode Solution182
815Number of Islands II LeetCode Solution182
816Largest rectangular sub-matrix whose sum is 0182
817Relative Ranks Leetcode Solution182
818Given an Array of Pairs Find all Symmetric Pairs in it182
819Identify and Mark Unmatched Parenthesis in an Expression182
820Repeated Substring Pattern LeetCode Solution181
821Diagonal Traversal of Binary Tree181
822Final Prices With a Special Discount in a Shop Leetcode Solution181
823A Space Optimized DP solution for 0-1 Knapsack Problem181
824Find all permuted rows of a given row in a matrix180
825Crawler Log Folder Leetcode Solution180
826Last Stone Weight II LeetCode Solution180
827Lemonade Change Leetcode Solution180
828Course Schedule II – LeetCode180
829Transpose Graph180
830Minimum time required to rot all oranges180
831Subarray Product Less Than K LeetCode Solution180
832Minimum Swaps to Make Strings Equal Leetcode Solution179
833Find Maximum Sum Possible Equal Sum of Three Stacks179
834LCS (Longest Common Subsequence) of three strings179
835Insert Delete GetRandom179
836Split Array Into Consecutive Subsequences179
837Sliding Window Maximum179
838Valid Parentheses Leetcode Solution179
839Design Browser History LeetCode Solution179
840Distinct adjacent elements in an array179
841Deletion in a Binary Tree179
842Clone Graph LeetCode Solution179
843Remove Duplicates from Sorted List LeetCode Solution179
844Minimum Jumps to Reach Home LeetCode Solution179
845Iterative Preorder Traversal179
846Reorder Data in Log Files LeetCode Solution179
847Search a 2D Matrix II Leetcode Solution179
848Minimum Number of Taps to Open to Water a Garden LeetCode Solution179
849Missing Element in Sorted Array LeetCode Solution179
850Check if a given array can represent Preorder Traversal of Binary Search Tree179
851Subsequence of Size K With the Largest Even Sum LeetCode Solution179
852Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
853Daily Temperatures Leetcode Solution179
854Permutation Coefficient179
855Alien Dictionary LeetCode Solution178
856Remove Duplicates from Sorted List II178
857Tree Traversal (Preorder, Inorder & Postorder)178
858Guess Number Higher or Lower LeetCode Solution178
859Iterative Postorder Traversal Using Two Stacks178
860Binary Search Tree Search and Insertion178
861Check if an Array is Stack Sortable178
862Find the Only Repetitive Element Between 1 to N-1178
863Sort Array By Parity II Leetcode Solution178
864Sum of nearest smaller and greater number178
865Number Complement Leetcode Solution178
866Spiral Matrix II Leetcode Solution178
867Partition List Leetcode Solution177
868Range LCM Queries177
869Interval Tree177
870Brightest Position on Street LeetCode Solution177
871Count Distinct Elements in Every Window of Size K177
872Get Maximum in Generated Array Leetcode Solution177
873Minimum number of jumps to reach end177
874Count Negative Numbers in a Sorted Matrix LeetCode Solution177
875Minimum Sum Path in a Triangle177
876Check if stack elements are pairwise consecutive177
877An Interesting Method to generate Binary Numbers from 1 to n177
878Least Number of Unique Integers after K Removals Leetcode Solution177
879Matrix Chain Multiplication176
880Path with maximum average value176
881Subset with sum divisible by m176
882Union and Intersection of two Linked Lists176
883Convert BST to Min Heap176
884Minimum swaps to make sequences increasing176
885Dividing Array into Pairs With Sum Divisible by K176
886Design a Stack With Increment Operation Leetcode Solution176
887Median of Two Sorted Arrays176
888Sort Colors176
889Count ways to reach the nth stair using step 1, 2 or 3176
890Friends Pairing Problem176
891Diagonal Traverse LeetCode Solution176
892Find the subarray with least average176
893Can Place Flowers LeetCode Solution176
894Find all triplets with zero sum176
895Maximum Score After Splitting a String Leetcode Solution176
896Insert into a Binary Search Tree Leetcode Solution175
897Maximum size subarray sum equals k175
898Level order Traversal in Spiral Form175
899Water Bottles Leetcode Solution175
900Diagonal Traversal LeetCode Solution175
901Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i175
902Minesweeper LeetCode Solution175
903Time Based Key-Value Store LeetCode Solution175
904Infix to Postfix175
905Delete And Earn175
906GCDs of given index ranges in an array175
907Pattern Occurrences using Stack175
908Sorted Array to Balanced BST175
909Find distance between two nodes of a Binary Tree175
910Check whether a given Binary Tree is Complete or not175
911Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution175
912Sequences of given length where every element is more than or equal to twice of previous175
913Number of Distinct Islands Leetcode Solution174
914A program to check if a binary tree is BST or not174
915All Unique Triplets that Sum up to a Given Value174
916Convert Sorted List to Binary Search Tree173
917Shortest Word Distance Leetcode Solution173
918Set Matrix Zeroes Leetcode Solution173
919Guess Number Higher or Lower II173
920Three way partitioning of an array around a given range173
921Range sum queries without updates173
922Check if any two intervals overlap among a given set of intervals173
923Binary array after M range toggle operations173
924Destination City Leetcode Solution173
925Count Submatrices With All Ones LeetCode Solution173
926Rearrange Spaces Between Words Leetcode Solution172
927Lexicographical Numbers Leetcode Solution172
928Print Fibonacci sequence using 2 variables172
929Product of Array Except Self LeetCode Solution172
930Robot Bounded In Circle LeetCode Solution172
931Rearrange an Array Such that arr[i] is equal to i172
932Find Common Characters Leetcode Solution172
933Difference Array | Range update query in O(1)172
934Binary Tree Longest Consecutive Sequence LeetCode Solution172
935Special Positions in a Binary Matrix Leetcode Solution172
936Construct the Rectangle Leetcode Solution172
937K’th Largest Element in BST when modification to BST is not allowed171
938Check if the given array can represent Level Order Traversal of Binary Search Tree171
939My Calendar I LeetCode Solution171
940Construct Complete Binary Tree from its Linked List Representation171
941Alien Dictionary171
942Count Subarrays with Same Even and Odd Elements171
943Averages of Levels in Binary Tree171
944Longest Palindromic Subsequence171
945Queue using Stacks171
9464Sum171
9473 Sum170
948Spiral Matrix III LeetCode Solution170
949Trim a Binary Search Tree170
950Analyze User Website Visit Pattern LeetCode Solution170
951Three Consecutive Odds Leetcode Solution170
952Merge Two Sorted Lists Leetcode170
953Intersection of Two Linked Lists LeetCode Solution170
954Palindrome Partitioning Leetcode Solution170
955Number of Equivalent Domino Pairs Leetcode Solution169
956Climbing stairs169
957Minimum Height Trees LeetCode Solution169
958Remove Duplicates from Sorted List II LeetCode Solution169
959Sign of the Product of an Array LeetCode Solution169
960Largest area rectangular sub-matrix with equal number of 1’s and 0’s169
961Construct BST from its given Level Order Traversal169
962BFS for Disconnected Graph169
963Vertical sum in a given binary tree169
964Maximum Frequency Stack Leetcode Solution169
965Queries for GCD of all numbers of an array except elements in a given range169
966Word Break169
967Create Maximum Number169
968Depth First Search (DFS) for a Graph168
969Longest subsequence such that difference between adjacents is one168
970Count Primes in Ranges168
971Symmetric Tree168
972Strongly Connected Component168
973Maximize Sum of Array after K Negations Leetcode Solution168
974Largest Substring Between Two Equal Characters Leetcode Solution167
975Maximum Product Subarray167
976Next Permutation Leetcode Solution167
977Reverse Nodes in K-Group167
978Stone Game II Leetcode167
979Combination Sum IV LeetCode Solution167
980Maximum Subarray Sum Excluding Certain Elements167
981Find Maximum of Minimum for Every Window Size in a Given Array167
982Design Hit Counter LeetCode Solution167
983Count pair with Given Sum167
984Merging Intervals167
985Unique Paths II167
986Maximum length subsequence with difference between adjacent elements as either 0 or 1167
987Asteroid Collision LeetCode Solution167
988Count subarrays where second highest lie before highest167
989Serialize and Deserialize Binary Tree167
990Number of palindromic paths in a matrix167
991Kth Smallest Element in a BST Leetcode Solution167
992Can Make Arithmetic Progression From Sequence Leetcode Solution166
993Graph Valid Tree LeetCode Solution166
994K Closest Points to Origin Leetcode Solution166
995Largest Number Leetcode Solution166
996Find number of pairs in an array such that their XOR is 0166
997K maximum sums of overlapping contiguous sub-arrays166
998Maximum Length of Repeated Subarray166
999Height of a generic tree from parent array166
1000Breadth First Search (BFS) for a Graph166
1001String Matching in an Array Leetcode Solution166
1002Valid Boomerang Leetcode Solution166
1003Longest Nice Substring LeetCode Solution166
1004Scramble String LeetCode Solution166
1005Count pairs from two sorted arrays whose sum is equal to a given value x165
1006Find the First Circular Tour that visits all the Petrol Pumps165
1007Collect maximum points in a grid using two traversals165
1008Find the Difference Leetcode Solution165
1009The Maze III LeetCode Solution165
1010Binary Search Tree Delete Operation165
1011Segment Tree165
1012Maximum difference between frequency of two elements such that element having greater frequency is also greater165
1013Balanced Binary Tree164
1014Find postorder traversal of BST from preorder traversal164
1015Shortest Completing Word Leetcode Solution164
1016Generate Parentheses Leetcode Solution164
1017Print Next Greater Number of Q queries164
1018Maximum Product of Indexes of Next Greater on Left and Right164
1019Palindrome Partitioning164
1020Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space164
1021Minimum Index Sum of Two Lists164
1022Remove Duplicates from Sorted Array II Leetcode Solution164
1023Find Duplicate Subtrees164
1024Newman-Conway Sequence164
1025Kth Smallest Element in a Sorted Matrix LeetCode Solution164
1026Length of Longest Fibonacci Subsequence163
1027Maximum Number of Ways to Partition an Array LeetCode Solution163
1028Largest divisible pairs subset163
1029Consecutive Characters LeetCode Solution163
1030Rearrange array such that even positioned are greater than odd163
1031Invalid Transactions LeetCode Solution163
1032The Painter’s Partition Problem163
1033Construct Binary Tree from given Parent Array representation163
1034Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution163
1035Friends Of Appropriate Ages LeetCode Solution163
1036Validate Binary Search Tree163
1037Binary Search Tree163
1038Level Order Traversal of Binary Tree163
1039Move all negative elements to end in order with extra space allowed162
1040Build an Array With Stack Operations Leetcode Solution162
1041Maximum Sum of 3 Non-Overlapping Subarrays162
1042Boundary Traversal of binary tree162
1043Decrypt String from Alphabet to Integer Mapping Leetcode Solution162
1044Bitwise AND of Numbers Range LeetCode Solution162
1045Path Sum II LeetCode Solution162
1046Find a Peak Element II LeetCode Solution162
1047Boolean Parenthesization Problem162
1048Merge Sort162
1049Iterative Depth First Traversal of Graph162
1050Advantages of BST over Hash Table162
1051Insertion in a Binary Tree161
1052Compute nCr % p161
1053Custom Sort String Leetcode Solution161
1054Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’161
1055Double the first element and move zero to end161
1056Make The String Great Leetcode Solution161
1057First missing positive161
1058Available Captures for Rook Leetcode Solution161
1059Next Greater Element III LeetCode Solution161
1060Number Of Longest Increasing Subsequence161
1061Construction of Longest Increasing Subsequence (N log N)161
1062Count minimum steps to get the given desired array160
1063Rearrange array such that even index elements are smaller and odd index elements are greater160
1064Kill Process LeetCode Solution160
1065Subarrays with K Different Integers Leetcode Solution160
1066Morris Inorder Traversal159
1067Find Peak Element159
1068Minimum Size Subarray Sum159
1069Print Right View of a Binary Tree159
1070Add two numbers159
1071Ugly Numbers159
1072Employee Importance LeetCode Solution159
1073Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution159
1074Recover Binary Search Tree Leetcode Solution159
1075Regular Expression Matching Regular Expression Matching LeetCode Solution159
1076Largest BST Subtree LeetCode Solution158
1077Partition Equal Subset Sum158
1078Remove Palindromic Subsequences Leetcode Solution158
1079Super Ugly Number158
1080Smallest Common Region Leetcode Solution158
1081Defanging an IP Address LeetCode Solution158
1082Maximum subsequence sum such that no three are consecutive158
1083Level order traversal using two Queues158
1084Lowest Common Ancestor158
1085Ugly Number II LeetCode Solution157
1086Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution157
1087Find maximum difference between nearest left and right smaller elements157
1088Find whether a subarray is in form of a mountain or not157
1089Remove duplicates from sorted array157
1090Cells with Odd Values in a Matrix LeetCode Solution157
1091Find Three Element From Different Three Arrays Such That a + b + c = sum157
1092Maximum weight transformation of a given string157
1093Binary Tree Right Side View LeetCode Solution157
1094Maximize Distance to Closest Person LeetCode Solution157
1095Number of siblings of a given Node in n-ary Tree156
1096Kth Smallest Product of Two Sorted Arrays LeetCode Solution156
1097Longest Bitonic Subsequence156
1098Palindrome Permutation LeetCode Solution156
1099Populating Next Right Pointers in Each Node Leetcode Solution156
1100Palindromic Substrings Leetcode Solution156
1101Implement Trie (Prefix Tree) Leetcode Solution156
1102Day of the Year Leetcode Solution156
1103Valid Tic-Tac-Toe State LeetCode Solution156
1104Path Sum155
1105Number of Closed Islands Leetcode Solution155
1106Increasing Triplet Subsequence LeetCode Solution155
1107Sum of Even Numbers After Queries155
1108Print all triplets in sorted array that form AP155
1109Find the minimum distance between two numbers155
1110Bus Routes Leetcode Solution155
1111Search in Sorted Rotated Array155
1112Reformat The String Leetcode Solution155
1113Products of ranges in an array155
1114Divisible Pairs Counting154
1115Number of Students Doing Homework at a Given Time Leetcode Solution154
1116Serialize and Deserialize Binary Tree LeetCode Solution154
1117Distinct Subsequences154
1118Binary Tree Data Structure154
1119Clone a Binary Tree with Random Pointers154
1120Iterative method to find ancestors of a given binary tree154
1121Maximum Depth Of Binary Tree153
1122Mean of Array After Removing Some Elements Leetcode Solution153
1123Count Largest Group Leetcode Solution153
1124Search Insert Position153
1125Moser-de Bruijn Sequence153
1126Find Smallest Range Containing Elements from k Lists153
1127Minimum Absolute Difference in BST Leetcode Solution153
1128Prime Palindrome LeetCode Solution153
1129Thousand Separator Leetcode Solution153
1130Longest Subarray of 1’s After Deleting One Element LeetCode Solution152
1131Minimum Score Triangulation of Polygon Leetcode Solution152
1132Level of Each node in a Tree from source node152
1133Minimum sum of squares of character counts in a given string after removing k characters152
1134Longest Increasing Consecutive Subsequence152
1135Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution152
1136Reformat Date LeetCode Solution152
1137Bottom View of a Binary Tree152
1138Longest Repeated Subsequence152
1139Root to Leaf path with target sum Leetcode Solutions152
1140Golomb sequence152
1141Queries for Number of Distinct Elements in a Subarray152
1142Diameter of N-Ary Tree LeetCode Solution152
1143Maximum Product Subarray151
1144Third Maximum Number Leetcode Solution151
1145Maximum Product of Splitted Binary Tree LeetCode Solution151
1146Construct K Palindrome Strings LeetCode Solution151
1147Write Code to Determine if Two Trees are Identical151
1148Swap Nodes In Pairs150
1149Constant time range add operation on an array150
1150Closest Leaf in a Binary Tree LeetCode Solution150
1151Priority Queue150
1152Find Largest Value in Each Tree Row LeetCode Solution150
1153Search an Element in Sorted Rotated Array150
1154Find maximum length Snake sequence150
1155Closest Binary Search Tree Value Leetcode Solution150
1156Minimum Moves to Equal Array Elements LeetCode Solution150
1157Convert BST into a Min-Heap without using array150
1158Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1159Contiguous Array LeetCode Solution150
1160Topological Sorting150
1161Print modified array after executing the commands of addition and subtraction150
1162Rotate Array150
1163Subset Sum Problem in O(sum) space149
1164Search Suggestions System LeetCode Solution149
1165Maximize sum of consecutive differences in a circular array149
1166Count Pairs Whose Products Exist in Array149
1167Kth Smallest Number in Multiplication Table Leetcode Solution149
1168Count even length binary sequences with same sum of first and second half bits149
1169Maximum Binary Tree148
1170Find a sorted subsequence of size 3 in linear time148
1171Cutting a Rod148
1172Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution148
1173Factorial Trailing Zeroes LeetCode Solution148
1174Web Crawler LeetCode Solution148
1175Perfect Squares LeetCode Solution148
1176First Bad Version148
1177Check Array Formation Through Concatenation Leetcode Solution148
1178Decision Tree147
1179Merge two BSTs with limited extra space147
1180Delete Nodes and Return Forest Leetcode Solution147
1181Possible Bipartition LeetCode Solution147
1182Transform a BST to Greater sum Tree147
1183Reverse a Path in BST using Queue147
1184Replace two consecutive equal values with one greater147
1185Red-Black Tree Introduction146
1186Sum of Left Leaves LeetCode Solution146
1187Decrease Elements To Make Array Zigzag LeetCode Solution146
1188Matchsticks to Square Leetcode Solution146
1189Valid Triangle Number146
1190Minimum Sideway Jumps LeetCode Solution146
1191Concatenation of Array LeetCode Solution146
1192Minimum Swaps To Make Sequences Increasing LeetCode Solution146
1193Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1194Given a binary tree, how do you remove all the half nodes?146
1195Binary Tree to Binary Search Tree Conversion146
1196Divide Two Integers Leetcode Solution145
1197Maximum sum bitonic subarray145
1198Maximum sum of a path in a Right Number Triangle145
1199Maximum number of segments of lengths a, b and c145
1200Queries on Probability of Even or Odd Number in given Ranges145
1201K’th Largest element in BST using constant extra space145
1202Path Crossing Leetcode Solution145
1203Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution144
1204New 21 Game144
1205Find the smallest binary digit multiple of given number144
1206Sliding Window Median Leetcode Solution144
1207Number of Orders in the Backlog Leetcode Solution144
1208Maximum Value at a Given Index in a Bounded Array LeetCode Solution144
1209Convert Sorted Array to Binary Search Tree LeetCode Solutions144
1210Integer Break LeetCode Solution143
1211Valid Perfect Square LeetCode Solution143
1212Print n terms of Newman-Conway Sequence143
1213Queue Reconstruction by Height143
1214Lowest Common Ancestor of a Binary Tree Leetcode Solution143
1215Maximum sum of pairs with specific difference143
1216Swapping Nodes in a Linked List Leetcode Solution143
1217Champagne Tower LeetCode Solution143
1218Moving Stones Until Consecutive Leetcode Solution142
1219Guess The Word142
1220Find minimum number of merge operations to make an array palindrome142
1221How to print maximum number of A’s using given four keys142
1222Longest Common Prefix Using Word by Word Matching141
1223Kth Smallest Element in a BST141
1224Find Minimum in Rotated Sorted Array II LeetCode Solution141
1225Array Queries for multiply replacements and product141
1226Range Sum Query using Sparse Table141
1227Graph and its representation141
1228Check if all levels of two Binary Tree are anagrams or not141
1229Maximum Sum Increasing Subsequence141
1230LRU Cache Leetcode Solution140
1231Maximum Array from Two given Arrays Keeping Order Same140
1232The kth Factor of n Leetcode Solution140
1233Lowest Common Ancestor in Binary Search Tree140
1234Range Queries for Longest Correct Bracket Subsequence140
1235Flatten 2D Vector LeetCode Solution140
1236Bold Words in String LeetCode Solution140
1237Maximize Elements Using Another Array139
1238Merge k Sorted Lists Leetcode Solution139
1239Mean of range in array139
1240Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution139
1241Write a function to get the intersection point of two Linked Lists139
1242Contiguous Array139
1243Largest Plus Sign Leetcode Solution138
1244BST to a Tree with Sum of all Smaller Keys138
1245Missing Number138
1246Maximum Product Subarray138
1247Print modified array after multiple array range increment operations138
1248Design Skiplist LeetCode Solution138
1249Arithmetic Slices II – Subsequence LeetCode Solution138
1250Count Subsets Having Distinct Even Numbers137
1251Parallel Courses II LeetCode Solution137
1252Power of Two137
1253Minimum Remove to Make Valid Parentheses LeetCode Solution137
1254Graph Cloning137
1255Find k-th smallest element in BST (Order Statistics in BST)137
1256Different Ways to Add Parentheses Leetcode Solution136
1257Image Overlap LeetCode Solution136
1258Min Cost Climbing Stairs LeetCode Solution136
1259Symmetric Tree LeetCode Solution Leetcode Solution135
1260Check if each internal node of a BST has exactly one child135
1261Minimum Time to Collect All Apples in a Tree LeetCode Solution135
1262Check if two nodes are on the same path in a Tree135
1263Check in binary array the number represented by a subarray is odd or even135
1264Verify Preorder Serialization of a Binary Tree134
1265Check for Identical BSTs without building the trees134
1266Check Completeness of a Binary Tree LeetCode Solution134
1267Next greater element134
1268Koko Eating Bananas LeetCode Solution134
1269Longest Substring Without Repeating Characters Leetcode Solution133
1270Print Ancestors of a Given Binary Tree Node Without Recursion133
1271Count and Toggle Queries on a Binary Array133
1272Smallest Range II Leetcode Solution133
1273Orderly Queue LeetCode Solution132
1274Excel Sheet Column Title LeetCode Solution132
1275Vertical Order Traversal of Binary Tree LeetCode Solution131
1276Merge Sorted Array131
1277Arranging Coins Leetcode Solution130
1278Palindrome Number LeetCode Solution130
1279Array Nesting Leetcode Solution130
1280Largest Submatrix With Rearrangements LeetCode Solution130
1281Number of elements less than or equal to a given number in a given subarray130
1282Palindrome Partitioning129
1283Check if X can give change to every person in the Queue128
1284Peeking Iterator LeetCode Solution128
1285Add Two Numbers II Leetcode Solution127
1286Continuous Subarray Sum LeetCode Solution127
1287Check If a String Can Break Another String Leetcode Solution126
1288Find maximum average subarray of k length126
1289Find the Winner of the Circular Game LeetCode Solution126
1290Newman–Shanks–Williams prime126
1291Maximum product of an increasing subsequence126
1292Queries for Decimal Values of Subarrays of a Binary Array125
1293Insert Delete GetRandom O(1) Leetcode Solution125
1294Range Minimum Query (Square Root Decomposition and Sparse Table)125
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution124
1296Encoded String With Shortest Length LeetCode Solution123
1297Check given array of size n can represent BST of n levels or not123
1298Jump Game IV LeetCode Solution122
1299Number of indexes with equal elements in given range122
1300Convert to Base -2 LeetCode Solution121
1301Binary Tree to Binary Search Tree Conversion using STL set121
1302Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1303Minimum Number of People to Teach LeetCode Solution121
1304Reach a Number LeetCode Solution121
1305Random Pick Index LeetCode Solution121
1306Convert a BST to a Binary Tree such that sum of all greater keys is added to every key119
1307Minimum Total Space Wasted With K Resizing Operations LeetCode Solution118
1308Design A Leaderboard Leetcode Solution116
1309Shifting Letters LeetCode Solution116
1310Design Underground System Leetcode Solution116
1311Queries on XOR of greatest odd divisor of the range115
1312Detect Capital Leetcode Solution112
1313Minimum Swaps to Group All 1’s Together Leetcode Solution111
1314Print Maximum Length Chain of Pairs111
1315Top K Frequent Elements LeetCode Solution110
1316Substring with Concatenation of All Words Leetcode Solution109
1317Minimum Path Sum Leetcode Solution108
1318Count Sub Islands LeetCode Solution108
1319Monotonic Array Leetcode Solution107
1320Odd Even Linked List Leetcode Solution107
1321Decode String Leetcode Solution104
1322Maximum Population Year LeetCode Solution104
1323Binary Tree Inorder Traversal LeetCode Solution104
1324Longest Common Subsequence LeetCode Solution103
1325Find the Town Judge LeetCode Solution103
1326Shortest Unsorted Continuous Subarray LeetCode Solution98
1327Rectangle Overlap LeetCode Solution96
1328Best Meeting Point LeetCode Solution96
1329Flatten Binary Tree to Linked List LeetCode Solution93
1330Maximum Population Year LeetCode Solution93
1331Sum Root to Leaf Numbers LeetCode Solution93
1332Find the Town Judge LeetCode Solution93
1333Design Add and Search Words Data Structure LeetCode Solution92
1334Insert into a Sorted Circular Linked List LeetCode Solution92
1335Stone Game IV LeetCode Solution90
1336Reveal Cards In Increasing Order Leetcode Solution89
1337Score of Parenthesis LeetCode Solution89
1338Is Graph Bipartite? LeetCode Solution89
1339Valid Triangle Number LeetCode Solution88
1340Range Sum Query 2D – Immutable LeetCode Solution88
1341Divide Chocolate LeetCode Solution82
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution71
1344Reverse Integer Leetcode Solution69
1345Rotate String LeetCode Solution67
1346Find K Closest Elements LeetCode Solution66
1347Sort Colors LeetCode Solution65
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution63
1349Excel Sheet Column Number LeetCode Solution60
1350Maximum Size Subarray Sum Equals k Leetcode Solution53
1351H-Index Leetcode Solution47
1352Camelcase Matching Leetcode Solution46
1353Valid Anagram Leetcode Solution46
1354Most Stones Removed with Same Row or Column LeetCode Solution45
1355Sliding Window Maximum LeetCode Solution44
1356Container With Most Water LeetCode Solution44
1357High Five LeetCode Solution43
1358Find Peak Element LeetCode Solution43
1359Group Anagrams LeetCode Solution43
1360Next Permutation LeetCode Solution42
1361Binary Search LeetCode Solution41
1362Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution41
1363Paint House LeetCode Solution40
1364Flatten Binary Tree to Linked List LeetCode Solution38
1365Group Shifted Strings Leetcode Solution37
1366Minimum Number of Arrows to Burst Balloons LeetCode Solution37
1367Sentence Screen Fitting LeetCode Solution37
1368Split Linked List in Parts Leetcode Solution37
1369Valid Triangle Number LeetCode Solution36
1370Next Greater Element I Leetcode Solution36
1371Isomorphic Strings LeetCode Solution35
1372Unique Binary Search Trees LeetCode Solution35
1373The Number of Weak Characters in the Game LeetCode Solution35
1374Peak Index in a Mountain Array LeetCode Solution34
1375Count Good Nodes in Binary Tree LeetCode Solution34
1376Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution34
1377Closest Binary Search Tree Value II LeetCode Solution33
1378Swim in Rising Water LeetCode Solution33
1379Best Time to Buy and Sell Stock IV LeetCode Solution32
1380Minimum Increment to Make Array Unique Leetcode Solution31
1381Single Element in a Sorted Array LeetCode Solution31
1382Break a Palindrome LeetCode Solution30
1383Find First and Last Position of Element in Sorted Array LeetCode Solution30
1384Max Sum of Two Non-Overlapping Subarrays LeetCode Solution30
1385Lowest Common Ancestor of a Binary Search Tree Leetcode Solution29
1386Remove All Ones With Row and Column Flips Leetcode Solution28
1387All Possible Full Binary Trees LeetCode Solution28
1388Contains Duplicate LeetCode Solution28
1389Implement Rand10() Using Rand7() Leetcode Solution27
1390Greatest Sum Divisible by Three LeetCode Solution27
1391Validate Stack Sequences LeetCode Solution27
1392Detect Squares LeetCode Solution26
1393Trapping Rain Water II LeetCode Solution26
1394Stone Game IV LeetCode Solution25
1395Reverse Nodes in k-Group LeetCode Solution25
1396Implement strStr() LeetCode Solution25
1397Invert Binary Tree LeetCode Solution24
1398Fibonacci Number LeetCode Solution22
1399Design Bounded Blocking Queue LeetCode Solution22
1400Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution21
1401Total Hamming Distance LeetCode Solution20
1402Unique Paths III LeetCode Solution19
1403Candy LeetCode Solution18
Translate »