Binary Search LeetCode Solution


Frequently asked in Adobe Amazon Apple Bloomberg Google Infosys Microsoft Samsung SAP TCS Yahoo Yandex
Categories - Easy Goldmann SachsViews

Problem Statement

Binary Search LeetCode Solution says that – Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.

You must write an algorithm with O(log n) runtime complexity.

Example 1:

Input:

 nums = [-1,0,3,5,9,12], target = 9

Output:

 4

Explanation:

 9 exists in nums and its index is 4

Example 2:

Input:

 nums = [-1,0,3,5,9,12], target = 2

Output:

 -1

Explanation:

 2 does not exist in nums so return -1

Constraints:

  • 1 <= nums.length <= 104
  • -104 < nums[i], target < 104
  • All the integers in nums are unique.
  • nums is sorted in ascending order.

ALGORITHM –

IDEA  –

  • In order to use Binary Search for finding the target element . First we will use Binary Search algorithm first we will find the middle element of an array and if middle element is equal to target element Then basically we will return index of that element.
  • If middle element is smaller than than target element then we will check in second half only.
  • Else we will Check in the first- half and this process continue until low > high.

APPROACH –

  • At first we will use Binary Search algorithm and we will take two variable low = 0 and high = length of array -1.
  • After that we will use while condition while(low <= high) and within that condition we will find middle element each time.
  • If middle element is Equal to Target then we will return the middle element index.
  • Else if middle less than Target then we will check in second half only i.e. low = mid+1.
  • Else we will check in first half i.e high = mid-1.
  • At last return the index of element and if its not found then we will return -1.

Image of the solution –

Binary Search LeetCode SolutionPin

class Solution {
    public int search(int[] nums, int target) {
        
        
        int low = 0;
        int high = nums.length-1;
        while(low <= high){
            
            int mid = (low+high)/2;
            if(nums[mid] == target){
                return mid;
                    
            } 
            
            else if(nums[mid] < target){
                low = mid+1;
            }
            else
                high = mid-1;
        }
        
        return -1;
        
        
    }
}
class Solution:
    def search(self, nums: List[int], target: int) -> int:
        low = 0
        high = len(nums)-1
        
        while(low <= high):
            mid = (low+high)//2
            if nums[mid] == target:
                return mid
            
            elif nums[mid] < target:
                low = mid+1
            
            else:
                high = mid-1
        return -1

Time Complexity – O(LOGN), As we have used binary search in this question.

Space Complexity – O(1), As we have not taken any extra space.

Similar question – https://www.tutorialcup.com/interview/linked-list/finding-middle-linkedlist.htm

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2831
2Java program to find the number of Nodes in a Binary Tree2510
3Reverse a string without affecting special characters2470
4Delete a node of a linked list at given position1984
5Palindrome using Recursion1884
6Insert nodes in a linked list in a sorted way (Ascending Order)1669
7Find elements pair from array whose sum equal to number1655
8Sort Elements by Frequency of Occurrences1643
9Quick Sort1627
10Write a program to print all permutations of a given string1615
11Find Minimum Distance Between Two Numbers in an Array1480
12Create a Doubly Linked List1456
13Reverse an Array1417
14Smallest window in a string containing all characters of another string1402
15Find a Triplet That Sum to a Given Value1366
16Recursively remove all adjacent duplicates1363
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1328
19Sum of numbers in String1325
20Smallest Positive Number Missing in an Unsorted Array1293
21Check if the Elements of an Array are Consecutive1262
22Detect a loop in the Linked List1247
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1226
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1212
27Recursive function to do substring search1208
28Find the Maximum Repeating Number in Array1161
29Binary Tree Level order traversal in Java1132
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1113
32Maximum Subarray Sum using Divide and Conquer1111
33Remove characters from first string which are in second1077
34Find Leaders in an Array1066
35Swap nodes in the linked list1044
36Find the Number Occurring Odd Number of Times in an Array1009
37Arrange given Numbers to Form the Biggest Number II999
38Find the second most frequent character998
39Given a string find its first non-repeating character977
40Find Triplet in Array With a Given Sum969
41Total number of occurrences of a given item in the linked list960
42Given a sorted array and a number x, find the pair in array whose sum is closest to x959
43A Program to check if strings are rotations of each other or not958
44Print all possible words from phone digits940
45Find the Missing Number932
46Rearrange Positive and Negative Numbers Alternatively in Array928
47Longest Palindromic Substring911
48Segregate even and odd nodes in a linked list895
49Print Longest common subsequence891
50Union and Intersection of Two Linked Lists880
51Transform one string to another using minimum number of given operations875
52Check rearranged string can form a palindrome857
53Rearrange given Array in Maximum Minimum Form852
54Iterative Implementation of Quick Sort841
55Count Possible Triangles829
56Multiplication of Two Matrices811
57Check if the linked list is palindrome803
58Count of Triplets With Sum Less than Given Value802
59Rotate a Linked List802
60Stock Buy Sell to Maximize Profit797
61Insertion Sort773
62Concatenation of two strings769
63Tug of War767
64Count Number of Substrings with K Distinct Character’s764
65Print all duplicates in the input string762
66Find Nearest Greater and Smaller Element751
67The Celebrity Problem745
68Find Pythagorean Triplets from Array744
69Remove ‘b’ and ‘ac’ from a given string739
70Reverse String Without Temporary Variable739
71Find all Common Elements in Given Three Sorted Arrays735
72Remove all duplicates in an unsorted linked list717
73Find the Row with Maximum Number of 1’s712
74Find the Peak Element from an Array707
75Find the subarray whose sum is equal to a given number X705
76Remove Minimum Characters so that Two Strings Become Anagrams698
77Addition of Two Matrices693
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s686
81Implement Two Stacks in an Array682
82Maximum Sum of Non Consecutive Elements679
83Maximum Product Subarray II665
84Lexicographic rank of string662
85Check if Two given Matrices are Identical655
86Multiplication of Previous and Next653
87Subtraction of Two Matrices644
88Merge K Sorted Arrays and Print Sorted Output639
89Move All the Zeros to the End of the Given Array638
90Divide a string in N equal parts634
91Form Minimum Number from Given Sequence of D’s and I’s629
92Online Algorithm for Checking Palindrome in a Stream629
93Check whether two strings are anagram of each other624
94Remove recurring digits in a given number622
95Maximum Circular Subarray Sum617
96Sort a linked list that is sorted alternating ascending and descending617
97Sort a stack using a temporary stack615
98Find the Minimum Element in a Sorted and Rotated Array611
99Move last element of the Linked List at first place610
100Subarray and Subsequence607
101First Circular Tour to Visit all the Petrol Bunks605
102Largest Subarray with Equal Number of 0’s and 1’s602
103Compare two strings(linked lists)601
104Flattening a linked list600
105Maximum Element in an Array which is Increasing and then Decreasing599
106Palindrome Permutations of a String595
107Elements Appear more than N/K times in Array588
108Palindromes in a given range585
109Run length encoding584
110Majority Element584
111Print all permutations with repetition583
112Pangram Checking581
113Minimum insertions to form a shortest palindrome581
114Minimum Characters to be Added at Front to Make String Palindrome573
115Rearrange a given linked list in-place572
116Remove all duplicates in a sorted linked list571
117Merge a linked list into another at alternate positions571
118Most repeating character in a string569
119Rotate string to get lexicographically minimum string569
120Minimum number of Merge Operations to make an Array Palindrome568
121Repeated Subsequence of Length Two or More566
122Print all anagrams together in a sequence of words561
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem548
125Merge Overlapping Intervals II546
126Two Sum Leetcode Solution546
127Clone a Linked List with next and random pointer544
1283Sum Leetcode Solution543
129Size of The Subarray With Maximum Sum534
130Transpose of a Matrix533
131Remove Extra Spaces from a String530
132Removing Spaces from a String using stringstream529
133Remove duplicates from a string527
134Partition Problem527
135Check if a given string is a rotation of a palindrome526
136Longest Palindrome can be Formed by Removing or Rearranging Characters525
137Maximum Sum Increasing Subsequence524
138Smallest Palindrome after Replacement524
139Check whether Strings are K Distance Apart or Not515
140Generate all Binary Strings from Given Pattern515
141Length of Longest valid Substring510
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized509
143Insert Node in the Sorted Linked List507
144Delete Last Occurrence506
145Check if Two given Strings are Isomorphic to each other502
146Maximum difference between two elements such as larger element comes after smaller495
147Program to Toggle all Characters in a String493
148Given string is interleaving of two other strings or not491
149Count Minimum Steps to Get the given Array487
150Merge sort better than quick sort for linked lists484
151Number of Smaller Elements on Right Side483
152Check length of a String is Equal to the Number Appended at its Last481
153Check if all Rows of a Matrix are Circular Rotations of Each Other480
154Find Pair with Given Difference480
155Longest Common Prefix using Divide and Conquer477
156Find nth node of the Linked list from the end477
157Print all interleavings of given two strings468
158Find a Fixed Point in a Given Array468
159Sort 0s 1s and 2s in an Array468
160Compare Two Version Numbers465
161Reverse words in a given string462
162Merge two sorted linked lists such that merged list is in reverse order462
163Reorder Array Using Given Indexes461
164Find the Subarray of given length with Least Average461
165Print Reverse of a string (Recursion)460
166Median of Two Sorted Arrays LeetCode Solution459
167Split linked list using alternate nodes459
168Print string of odd length in ‘X’ format445
169Print all Palindromic Partitions of a String441
170Find K Length Subarray of Maximum Average441
171Swap Kth Node from beginning with Kth Node from End441
172Find Element Using Binary Search in Sorted Array440
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions427
175Flatten a multilevel linked list424
176Shortest Superstring Problem424
177Maximum Length of Chain Pairs423
178Check if String Follows Order of Characters by a Pattern or not420
179Sorting a K Sorted Array418
180Sort a String According to Another String413
181Longest Span with same Sum in two Binary Arrays II404
182Reverse a Linked List in groups402
183Find a Sorted Subsequence of size 3401
184Recursively print all the sentences that can be formed from list of word lists399
185Program to add two binary digits398
186Longest Common Prefix Using Binary Search II396
187Find the two Numbers with Odd Occurrences in an Unsorted Array394
188Reverse a Singly Linked List (Iterative/Non-Recursive)394
189Caesar Cipher390
190Kth Non-repeating Character389
191Rearrange a linked list in Zig-Zag386
192Check if String can Become Empty by Recursively Deleting given Substring385
193Longest Common Prefix Word by Word Matching382
194Pancake Sorting381
195Rotate Image by 90 degrees380
196Permutations of a Given String Using STL373
197Perfect Reversible String372
198Merging Two Sorted Arrays370
199Increasing Subsequence of Length three with Maximum Product368
200Sort a linked list with 0s, 1s and 2s367
2011`s and 2`s complement of binary number367
202Find First non-repeating character in a string366
203Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes366
204Find the point where a monotonically increasing function becomes positive first time366
205Four Elements that Sum to Given363
206List items containing all characters of a given word361
207Delete N nodes after M360
208Longest Common Prefix using Character by Character Matching357
209Count Number of Occurrences in a Sorted Array354
210Palindrome string (number)351
211Split a string349
212Minimum Characters to be Removed to Make a Binary String Alternate344
213Recursive Implementation of atoi()342
214Check if a Linked list of Strings form a Palindrome341
215Sorting the array of strings339
216Print All Distinct Elements of the Array339
217Maximum occurring character in a string337
218Even Substring Count336
219Convert a String that is Repetition of a Substring of Length K336
220Valid Parentheses LeetCode Solution335
221Find the first Repeating Number in a Given Array334
222Reverse a singly linked list recursively334
223Print Shortest Path to Print a String on Screen331
224Can we reverse a linked list in less than O(n) time ?331
225Convert string1 to string2 in one edit330
226Binary Tree to Doubly linked list329
227Nth Character in Concatenated Decimal String328
228wildcard character matching326
229Reverse a String using Stack326
230Sort Elements by Frequency II325
231Lower Case To Upper Case324
232Maximum Subarray Leetcode Solution324
233Merge Two Sorted Arrays319
234Count the number of words318
235Split Four Distinct Strings317
236Find the Lost Element From a Duplicated Array315
237Find middle of the Linked List313
238Matrix Chain Multiplication using Dynamic Programming309
239Longest Common Subsequence with Permutations309
240Count the Pairs at Same Distance as in English Alphabets309
241Next Greater Element in an Array303
242Palindrome Permutation299
243Roman to Integer Leetcode Solution293
244Find Nth Node293
245Searching a node in a Binary Search Tree291
246Find All Pairs With a Given Difference290
247Triplet from three linked lists with given sum286
248Delete a Tree286
249String(represents an integer) to value285
250Reverse a String284
251Word Search Leetcode Solution283
252Reverse Bits282
253Delete a node under given conditions282
254Print all Possible Ways to Break a String in Bracket Form281
255Change Gender of a given String279
256Binary Tree279
257Sort an array of strings277
258How to Efficiently Implement k Stacks in a Single Array?277
259Toeplitz Matrix276
260Count Pairs With Given Sum275
261First non Repeating Element274
262Meeting Rooms II LeetCode Solution273
263Number of sub-strings which recursively add up to 9273
264Repeated Substring Pattern272
265Remove middle points in a linked list of line segments271
266Longest Common Extension271
267N queen problem271
268Move all negative elements to one side of array270
269Remove spaces from a string268
270Longest Palindromic Substring LeetCode Solution266
271Min Stack264
272Shuffle a given Array264
273Dijkstra Algorithm261
274Number of Islands LeetCode Solution260
275Cuckoo sequence program259
276Max stack258
277Find, second, frequent, character258
278House Robber Leetcode Solution258
279Fibonacci numbers257
280Most Frequent Element in an Array256
281Minimize the maximum difference between the heights255
282Clone a linked list with next and random pointer (Hashing)253
283Search Insert Position Leetcode Solution253
284Expression Evaluation252
285KMP Algorithm250
286Sort linked which is sorted on absolute values250
287Sudoku Solver249
288Subset Leetcode249
289Valid Palindrome Leetcode Solution248
290Word Search247
291Plus One Leetcode Solution247
292Reverse words in a string246
293Evaluation of Postfix Expression246
294Number Of 1 bits246
295How to Delete a Linked List245
296Combination Sum Leetcode Solution245
297Min Stack Leetcode Solution244
298Backspace String Compare241
299Set Matrix Zeroes238
300Rabin Karp Algorithm237
301Pair of Positive Negative Values in an Array237
302Sqrt(x) Leetcode Solution237
303Merge Sorted Arrays Leetcode Solution236
304Reversing a Queue236
305Subarray with 0 sum234
306Common elements in all rows of a given matrix233
307Tower Of Hanoi233
308Combination Sum231
309Contains Duplicate II Leetcode Solution230
310Integer to Roman Leetcode Solution230
311Delete middle element of a stack230
312Product of array except self230
313Pascal Triangle Leetcode229
314String Compression228
315Intersection of Two Arrays II Leetcode Solution228
316Minimum swaps required to bring all elements less than or equal to k together227
317Reverse individual words227
318Segregate even and odd numbers226
319Construct Binary Tree from Given Inorder and Preorder Traversals225
320Count subarrays with equal number of 1’s and 0’s225
321Count of index pairs with equal elements in an array225
322Find Top K (or Most Frequent) Numbers in a Stream225
323Add Binary Leetcode Solution224
324Sliding Window Technique224
325Implementation of Deque using Doubly Linked List224
326Bellman Ford Algorithm224
327Contains Duplicate223
328Count Odd Numbers in an Interval Range Leetcode Solution223
329Minimum Value to Get Positive Step by Step Sum Leetcode Solution223
330Single Number Leetcode Solution223
331Find sum of non-repeating elements (distinct) elements in an array222
332Arithmetic Expression Evaluation222
333Sort elements by frequency221
334Postfix to Infix Conversion221
335Palindrome Linked List Leetcode Solution221
336Second Most Repeated Word in a Sequence221
337Pow(x, n) Leetcode Solution220
338Page Replacement Algorithms in Operating Systems219
339Maximum Number of Balloons Leetcode Solution219
340Next Permutation218
341Group Words With Same Set of Characters218
342Kruskal Algorithm218
343Design a stack that supports getMin() in O(1) time and O(1) extra space218
344Sum of minimum and maximum elements of all subarrays of size k216
345K-th Smallest Element in a Sorted Matrix216
346Scramble String216
347Smallest Subarray with k Distinct Numbers216
348Longest Common Prefix Leetcode Solution216
349Find Lucky Integer in an Array Leetcode Solution215
350Convex Hull Algorithm215
351Count subarrays having total distinct elements same as original array215
352Third Maximum Number Leetcode Solution215
353Maximum Subarray215
354Sorting array using Stacks214
355Minimum operation to make all elements equal in array214
356Top K Frequent Words214
357Longest Substring Without Repeating Characters LeetCode Solution214
358Permutations Leetcode Solution214
359Find the Town Judge Leetcode Solution213
360Find Numbers with Even Number of Digits Leetcode Solution212
361Special Number211
362Evaluate Division211
363Majority Element Leetcode Solution210
364Swap Nodes in Pairs Leetcode Solutions210
365Given two unsorted arrays find all pairs whose sum is x210
366Number of Good Pairs Leetcode Solution210
367Huffman Coding209
368Spiral Matrix LeetCode Solution209
369First element occurring k times in an array209
370Minimum Path Sum209
371Prefix to Infix Conversion208
372Check if two arrays are equal or not208
373Reverse a Number Using Stack207
374Count Primes Leetcode Solutions207
375Reversing the First K elements of a Queue207
376Merge Two Sorted Lists Leetcode Solutions207
377Maximal Square207
378Single Number207
379Best Time to Buy and Sell Stock  II Leetcode Solution206
380Missing Number Leetcode Solution206
381Pascal’s Triangle II Leetcode Solution206
382Group Anagrams206
383Running Sum of 1d Array Leetcode Solution205
384Minimum Absolute Difference Leetcode Solution205
385Find duplicates in a given array when elements are not limited to a range205
386Minimum Steps to reach target by a Knight205
387Search in Rotated Sorted Array Leetcode Solution205
388House Robber II Leetcode Solution204
389Sort Array by Increasing Frequency Leetcode Solution204
390Maximum Distance Between two Occurrences of Same Element in Array204
391Palindrome Substring Queries204
392Matrix Diagonal Sum Leetcode Solution203
393Power of Two Leetcode Solution203
394Range Sum Query 2D – Immutable Leetcode Solution202
395Maximum possible difference of two subsets of an array202
396How to Implement Stack Using Priority Queue or Heap?202
397Top K Frequent Elements202
398Convert String To Int202
399Zigzag Conversion202
400Unique Paths202
401Find Minimum In Rotated Sorted Array202
402Find All Numbers Disappeared in an Array Leetcode Solution202
403Find the first repeating element in an array of integers202
404Subarray Sum Equals k201
405Fizz Buzz Leetcode201
406Unique Paths Leetcode Solution201
407Smallest Element Repeated Exactly K Times201
408Expression Contains Redundant Bracket or Not201
409Find the Closest Palindrome number201
410Check if Array Contains Contiguous Integers With Duplicates Allowed201
411Sorting using trivial hash function201
412Sort Integers by The Number of 1 Bit Leetcode Solution200
413Leetcode Permutations200
414How Many Numbers Are Smaller Than the Current Number Leetcode Solution200
415Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
416Letter Case Permutation199
417Find Number of Employees Under every Employee199
418Subset sum problem199
419Decode String199
420Cumulative Frequency of Count of Each Element in an Unsorted Array199
421Find Winner on a Tic Tac Toe Game Leetcode Solution199
422Max Consecutive Ones Leetcode Solution199
423Coin Change 2 Leetcode Solution198
424Monotonic Array LeetCode Solution198
425Difference between highest and least frequencies in an array198
426Happy Number Leetcode Solution198
427Length of the largest subarray with contiguous elements198
428Implement Stack and Queue using Deque197
429Sort a stack using recursion197
430Subarray Sum Equals K LeetCode Solution197
431Nth Catalan Number197
432Reverse Integer197
433Best Time to Buy and Sell Stock III Leetcode Solution197
434Find top three repeated in array197
435Print All Distinct Elements of a Given Integer Array197
436Count Substrings with equal number of 0s, 1s and 2s196
437Fibonacci Number LeetCode Solution196
438Check If N and Its Double Exist Leetcode Solution196
439Print all subarrays with 0 sum196
440LRU Cache Implementation196
441Maximum Depth of Binary Tree Leetcode Solution196
442Remove Duplicates from Sorted Array Leetcode Solution196
443Subarrays with distinct elements195
444Sum of Subarray Ranges Leetcode Solution195
445Reverse Vowels of a String Leetcode Solution195
446Capacity To Ship Packages Within D Days Leetcode Solution195
447Prim’s Algorithm194
448Subtract the Product and Sum of Digits of an Integer Leetcode Solution194
449Find Median from data Stream194
450Find The Duplicate Number194
451Generate a String With Characters That Have Odd Counts Leetcode Solution194
452Reverse a Stack Using Recursion194
453Integer to English words193
454Shuffle the Array Leetcode Solution193
455Kth largest element in an Array Leetcode Solutions193
456Bipartite Graph193
457Merge Two Sorted Linked Lists193
458Reverse Words in a String III LeetCode Solution193
459Delete a Node from linked list without head pointer193
460Edit Distance192
461Find all pairs (a, b) in an array such that a % b = k192
462Target Sum192
463Count and Say192
464Find the Duplicate Element192
465Trapping Rain Water Leetcode Solution192
466Find the Difference Leetcode Solution192
467Count pairs from two linked lists whose sum is equal to a given value192
468Find elements which are present in first array and not in second192
469Find Common Characters Leetcode Solution192
470Longest Common Subsequence191
471Sorting a Queue without Extra Space191
472Remove Minimum Number of Elements Such That no Common Element Exist in both Array191
473Reverse a String191
474The K Weakest Rows in a Matrix Leetcode Solution190
475Excel Sheet Column Number Leetcode Solution190
476Floyd Warshall Algorithm190
477Priority Queue Using Singly Linked List190
478Iterative Tower of Hanoi190
479Balanced Binary Tree Leetcode Solution190
480Fizz Buzz190
481Longest Common Prefix using Trie189
482Reverse a linked list189
483Concatenation of Array LeetCode Solution189
484Text Justification LeetCode Solution189
485Prefix to Postfix Conversion188
486Find First and Last Position of Element in Sorted Array Leetcode Solution188
487Minimum Moves to Equal Array Elements Leetcode Solution188
488Kth Largest Element in a Stream Leetcode Solution188
489Flood Fill LeetCode188
490Longest subarray not having more than K distinct elements188
491Design Parking System Leetcode Solution188
492Degree of an array188
493Merge Overlapping Intervals188
494Next Greater Element I Leetcode Solution188
495Kids With the Greatest Number of Candies Leetcode Solution188
496Valid Parenthesis String187
497Top View of Binary Tree187
498MiniMax Algorithm187
499Word Ladder LeetCode Solution187
500Number of Steps to Reduce a Number to Zero Leetcode Solution187
501Slowest Key Leetcode Solution187
502Find subarray with given sum (Handles Negative Numbers)187
503Pair with given product186
504Priority Queue in C++186
505Find missing elements of a range186
506Find N Unique Integers Sum up to Zero Leetcode Solution186
507Shortest Palindrome186
508Zigzag Conversion LeetCode Solution186
509Find four elements that sum to a given value (Hashmap)186
510The Stock Span Problem186
511Multiply Strings Leetcode Solution186
512Jump Game Leetcode Solution185
513Postfix to Prefix Conversion185
514Convert array into Zig-Zag fashion185
515Count and Say Leetcode Solution185
516Max Area of Island185
517Implement a stack using single queue184
518Check if a given array contains duplicate elements within k distance from each other184
519Length of Last Word Leetcode Solution184
520Count number of triplets with product equal to given number184
521Recursion184
522Rearrange a binary string as alternate x and y occurrences184
523Find Index of Closing Bracket for a Given Opening Bracket in an Expression184
524Mobile Numeric Keypad Problem184
525Find any one of the multiple repeating elements in read only array184
526Find distinct elements common to all rows of a matrix184
527Substring With Concatenation Of All Words184
528Move Zeroes LeetCode Solution184
529Largest Sum Contiguous Subarray183
530Peak Index in a Mountain Array183
531Intersection of Two Arrays183
532Shuffle String Leetcode Solution183
533Implement Stack using Queues183
534Next Greater Frequency Element183
535Longest Common Prefix using Sorting183
536Last Stone Weight182
537Smallest Subarray With all Occurrences of a Most Frequent Element182
538Contiguous Array Leetcode182
539Iterative Inorder Traversal of a Binary Tree182
540Convert a normal BST to Balanced BST181
541Delete Node in a Linked List Leetcode Solution181
542Koko Eating Bananas Leetcode Solution181
543Relative Sort Array Leetcode Solution181
544Sum of Left Leaves Leetcode Solutions181
545Change the Array into Permutation of Numbers From 1 to N181
546Excel Sheet Column Title Leetcode Solution181
547Group Multiple Occurrence of Array Elements Ordered by first Occurrence181
548Assign Cookies Leetcode Solution180
549Linked List Cycle II LeetCode Solution180
550K-th Distinct Element in an Array180
551Minimum Bracket Reversals180
552Best Time to Buy and Sell Stock180
553Valid Sudoku180
554Container with Most Water179
555Integer to Roman179
556Implementation of Deque using circular array179
557Distribute Candies to People Leetcode Solution179
558N-th Tribonacci Number Leetcode Solution179
559Shuffle an Array179
560Find Words That Can Be Formed by Characters Leetcode Solution179
561Minimum Delete Operations to make all Elements of Array Same179
562First negative integer in every window of size k179
563Is Subsequence Leetcode Solution179
564Number of Provinces Leetcode Solution179
565Isomorphic Strings Leetcode Solution179
566Minimum Operations to convert X to Y179
567Island Perimeter Leetcode Solution179
568Check for Balanced Parentheses in an Expression178
569Hamming Distance178
570Build Array From Permutation Leetcode Solution178
571Jewels and Stones Leetcode Solution178
572Largest Perimeter Triangle Leetcode Solution178
573Minimum Knight Moves LeetCode Solution178
574Arrange given numbers to form the biggest number178
575Valid Anagrams177
576Rotate List Leetcode Solution177
577Unique Binary Search Trees177
578Summary Ranges Leetcode Solution177
579Count all subsequences having product less than K177
580Combinations Leetcode Solution177
581Count the number of nodes at given level in a tree using BFS177
582The Knapsack Problem177
583Maximum path sum in a triangle177
584Gold Mine Problem177
585Convert Sorted Array to Binary Search Tree Leetcode Solution177
58601 Matrix LeetCode Solution177
587Trapping Rain Water LeetCode Solution176
588Remove Linked List Elements Leetcode Solution176
589LRU Cache LeetCode Solution176
590Maximum sum rectangle in a 2D matrix176
591Minimum number of subsets with distinct elements175
592Find the smallest positive integer value that cannot be represented as sum of any subset of a given array175
5933Sum Closest LeetCode Solution175
594Decode Ways175
595Shortest Path in a Grid with Obstacles Elimination LeetCode Solution175
596Maximum Distance in Array174
597Minimum number of distinct elements after removing m items174
598Minimum insertions to form a palindrome with permutations allowed174
599Rotate Image LeetCode Solution174
600Find minimum difference between any two elements174
601Find Sum of all unique sub-array sum for a given array174
602Maximum Number of Chocolates to be Distributed Equally Among k Students173
603Sort Characters By Frequency LeetCode Solution173
604Bubble sort using two Stacks173
605Insert Interval Leetcode Solution173
606Distance Between Bus Stops Leetcode Solution173
607How to check if two given sets are disjoint?173
608Same Tree LeetCode Solution173
609Reverse a stack without using extra space in O(n)172
610Find if an Expression has Duplicate Parenthesis or Not172
611Longest Increasing Subsequence172
612Stone Game LeetCode172
613Painting Fence Algorithm172
614Frog Jump Leetcode Solution172
615Sieve of Eratosthenes172
616XOR Operation in an Array Leetcode Solution172
617Minimum Cost to Hire K Workers172
618Defanging an IP Address Leetcode Solution172
619Find the Duplicate Number LeetCode Solution171
620Word Pattern171
621Word Wrap Problem171
622Applications of Breadth First Search and Depth First Search171
623Replace Elements with Greatest Element on Right Side Leetcode Solution171
624License Key Formatting Leetcode Solution171
625Remove All Occurrences of a Substring LeetCode Solution171
626Permutation in String Leetcode Solution171
627Iterative Method to find Height of Binary Tree170
628Best Time to Buy and Sell Stock LeetCode Solution170
629Distance of nearest cell having 1 in a binary matrix170
630K Empty Slots LeetCode170
631Isomorphic Strings170
632Sort Array By Parity LeetCode Solution170
633House Robber170
634Non-overlapping sum of two sets170
635Smallest Good Base170
636Maximum Consecutive Numbers Present in an Array170
637Printing brackets in Matrix Chain Multiplication Problem170
638Moving Average from Data Stream Leetcode Solution169
639Minimum Depth of Binary Tree Leetcode Solution169
640Optimal Account Balancing LeetCode Solution169
641Tracking current Maximum Element in a Stack169
642Segregate 0s and 1s in an Array169
643Longest Substring with At Least K Repeating Characters LeetCode Solution169
644Valid Palindrome II Leetcode Solution168
645Queries for counts of array elements with values in given range168
646Binary Tree Zigzag Level Order Traversal LeetCode Solution168
647Employee Free Time LeetCode Solution168
648Coin Change Problem168
649Best Time to Buy and Sell Stock with Cooldown Leetcode Solution168
650Merge Two Balanced Binary Search Trees168
651Longest Substring with At Most K Distinct Characters LeetCode Solution168
652GCD Of Two Numbers168
653Kth Missing Positive Number Leetcode Solution168
654Wiggle Sort168
655Reorganize String167
656How to Create Mergable Stack?167
657Valid Palindrome167
658Find Maximum Level sum in Binary Tree167
659Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions167
660Count Good Nodes in Binary Tree Leetcode Solution167
661Check If It Is a Straight Line Leetcode Solution167
662Maximum difference between first and last indexes of an element in array167
663Path With Maximum Minimum Value LeetCode Solution167
664Strobogrammatic Number LeetCode Solution167
665Sum of All Odd Length Subarrays Leetcode Solution167
666Delete consecutive same words in a sequence166
667Find Largest d in Array such that a + b + c = d166
668Find the Distance Value Between Two Arrays Leetcode Solution166
669To Lower Case Leetcode Solution166
670Check if a queue can be sorted into another queue using a stack166
671Flipping an Image LeetCode Solution166
672Maximum Number of Occurrences of a Substring Leetcode Solution166
673Remove Invalid Parentheses Leetcode Solution166
674Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest166
675Reducing Dishes LeetCode Solution165
676Check If Two String Arrays are Equivalent Leetcode Solution165
677Increasing Decreasing String Leetcode Solution165
678Inorder Successor of a node in Binary Tree165
679Sum of f(a[i], a[j]) over all pairs in an array of n integers165
680Print the Fibonacci numbers in reverse order165
681Partition Labels LeetCode Solution165
682Letter Combinations of a Phone Number165
683Maximum Number of Coins You Can Get Leetcode Solution165
684K Empty Slots165
685Partition Array Into Three Parts With Equal Sum Leetcode Solution165
686Find pairs with given sum such that elements of pair are in different rows165
687Convert an array to reduced form165
688Lucky Numbers in a Matrix Leetcode Solution165
689Factorial Trailing Zeroes Leetcode Solution164
690Permutation Sequence LeetCode Solution164
691BFS vs DFS for Binary Tree164
692Number of Dice Rolls With Target Sum LeetCode Solution164
693Reverse Only Letters LeetCode Solution164
694Delete Nth node from the end of the given linked list164
695Valid Perfect Square Leetcode Solution164
696Find the Smallest Divisor given a Threshold Leetcode Solution164
697Unique Paths II Leetcode Solution163
698Reversing a Queue using Recursion163
699Dynamic Programming Basics163
700Populating Next Right Pointers in Each Node163
701Recover Binary Search Tree163
702Edit Distance LeetCode Solution163
703Binary Tree zigzag level order Traversal163
704Convert a Number to Hexadecimal Leetcode Solution163
705Find whether an array is subset of another array163
706Form minimum number from given sequence163
707Ugly Number Leetcode Solution163
708Longest Increasing Path in a Matrix LeetCode Solution163
709String to Integer (atoi) LeetCode Solution163
710Maximum Product of Two Elements in an Array Leetcode Solution163
711Power of Four Leetcode Solution163
712Find Leaves of Binary Tree LeetCode Solution163
713Subset Sum Leetcode163
714Robot Room Cleaner Leetcode Solution162
715Merge Two Binary Trees LeetCode Solution162
716Perform String Shifts Leetcode162
717Sort Array by Increasing Frequency Leetcode Solution162
718Construct BST from given Preorder Traversal162
719Reservoir Sampling162
720Find the node with minimum value in a Binary Search Tree161
721Find the largest multiple of 3161
722Decompress Run-Length Encoded List Leetcode Solution161
723Keyboard Row Leetcode Solution161
724Binomial Coefficient161
725Add and Search Word – Data structure design LeetCode161
726Find Pair with Greatest Product in Array160
727Minimum Cost For Tickets Leetcode Solution160
728Hamming Distance Leetcode Solution160
729Tiling Problem160
730Student Attendance Record I Leetcode Solution160
731Finding K closest element160
732Bulb Switcher LeetCode Solution160
733Restore IP Addresses Leetcode Solution160
734Majority Element II Leetcode Solution160
735Kth ancestor of a node in binary tree159
736Snakes and Ladders LeetCode Solution159
737Rank Transform of an Array Leetcode Solution159
738Binary Tree Maximum Path Sum LeetCode Solution159
739Find Maximum Depth of Nested Parenthesis in a String159
740Race Car LeetCode Solution159
741Check if Two Expressions With Brackets are Same159
742Generate all possible sorted arrays from alternate elements of two given sorted arrays159
743Longest Span with same Sum in two Binary arrays159
744Remove brackets from an algebraic string containing + and – operators159
745Minimum Distance Between BST Nodes Leetcode Solution159
746Numbers with prime frequencies greater than or equal to k159
747Find unique character in a string159
748Non-decreasing Array LeetCode Solution159
749Word Pattern LeetCode Solution159
750Maximum 69 Number Leetcode Solution158
751Maximum Depth of N-ary Tree Leetcode Solution158
752Sorted Linked List to Balanced BST158
753Minimum Height Trees158
754String Compression LeetCode Solution158
755Number of Islands II LeetCode Solution158
756Linked List Cycle158
757Maximum Product of Three Numbers LeetCode Solution158
758Diagonal Traversal of Binary Tree158
759Stack Permutations (Check if an array is stack permutation of other)158
760First Unique Character in a String LeetCode Solution158
761Invert Binary Tree LeetCode Solution158
762Morris Traversal158
763Merge K Sorted Linked Lists158
764Queue based approach for first non-repeating character in a stream158
765Largest Rectangle in Histogram LeetCode Solution158
766Minimum time required to rot all oranges158
767Minimize Maximum Pair Sum in Array LeetCode Solution157
768Jump Game157
769Best Meeting Point LeetCode Solution157
770Find if Path Exists in Graph Leetcode Solution157
771Largest subarray with equal number of 0s and 1s157
772Largest rectangular sub-matrix whose sum is 0157
773Final Prices With a Special Discount in a Shop Leetcode Solution157
774Remove Nth Node From End of List Leetcode Solution157
775Transpose Graph157
776Symmetric Tree Leetcode Solution156
777One Edit Distance LeetCode Solution156
778Special Array With X Elements Greater Than or Equal X Leetcode Solution156
779Program for Bridge and Torch problem156
780Total Numbers With no Repeated Digits in a Range156
781Maximum Length of a Concatenated String with Unique Characters Leetcode Solution156
782Elements to be added so that all elements of a range are present in array156
783Maximum Difference Between Increasing Elements LeetCode Solution156
784Check If Array Pairs Are Divisible by k LeetCode Solution156
785Find All Duplicates in an Array LeetCode Solution156
786Evaluate Reverse Polish Notation LeetCode Solution156
787k-th missing element in increasing sequence which is not present in a given sequence156
788Partition to K Equal Sum Subsets Leetcode Solution156
789Growable array based stack156
790Check for Palindrome after every character replacement Query155
791Find Median from Data Stream LeetCode Solution155
792Search in a Binary Search Tree Leetcode Solution155
793Count items common to both the lists but with different prices155
794Search a 2D Matrix II Leetcode Solution155
795Sort an array according to the order defined by another array155
796Interval Tree155
797Longest Subarray Having Count of 1s One More than Count of 0s155
798Split a String in Balanced Strings Leetcode Solution155
799Number of NGEs to the Right155
800Print a Binary Tree in Vertical Order155
801Crawler Log Folder Leetcode Solution155
802N-Queens LeetCode Solution154
803Minimum Time Visiting All Points Leetcode Solution154
804String comparison containing wildcards154
805Merge Sorted Array LeetCode Solution154
806Deletion in a Binary Tree154
807Number Complement Leetcode Solution154
808Nested List Weight Sum II LeetCode Solution154
809Minimum Jumps to Reach Home LeetCode Solution154
810Base 7 Leetcode Solution154
811Nearest Exit from Entrance in Maze LeetCode Solution154
812Valid Number154
813Minimum swaps to make sequences increasing154
814Circular Queue154
815Course Schedule II – LeetCode154
816Count quadruples from four sorted arrays whose sum is equal to a given value x154
817Get Maximum in Generated Array Leetcode Solution153
818A Space Optimized DP solution for 0-1 Knapsack Problem153
819Remove Duplicates from Sorted List II153
820Last Stone Weight II LeetCode Solution153
821Minimum number of jumps to reach end153
822Sort Array By Parity II Leetcode Solution153
823Convert BST to Min Heap153
824Maximum Profit in Job Scheduling Leetcode Solution153
825Reorder Data in Log Files LeetCode Solution153
826Spiral Matrix II Leetcode Solution153
827Maximum size subarray sum equals k152
828Remove Duplicates from Sorted List LeetCode Solution152
829Regular Expression Matching152
830Iterative Preorder Traversal152
831Find Maximum Sum Possible Equal Sum of Three Stacks152
832Find the subarray with least average152
833Subarray Product Less Than K LeetCode Solution152
834Relative Ranks Leetcode Solution152
835Form Minimum Number From Given Sequence152
836Priority Queue using doubly linked list152
837Find all triplets with zero sum152
838Minimum Swaps to Make Strings Equal Leetcode Solution152
839Partition List Leetcode Solution151
840Can Place Flowers LeetCode Solution151
841Maximum Nesting Depth of the Parentheses Leetcode Solution151
842Tree Traversal (Preorder, Inorder & Postorder)151
843Sort Colors151
844Subset with sum divisible by m151
845Number of Days Between Two Dates LeetCode Solution151
846Path with maximum average value151
847Sequences of given length where every element is more than or equal to twice of previous151
848Insert into a Binary Search Tree Leetcode Solution151
849Permutation Coefficient151
850Alien Dictionary LeetCode Solution151
851Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution151
852LCS (Longest Common Subsequence) of three strings151
853Identify and Mark Unmatched Parenthesis in an Expression151
854Brick Wall LeetCode Solution150
855Subsequence of Size K With the Largest Even Sum LeetCode Solution150
856Find the Only Repetitive Element Between 1 to N-1150
857Guess Number Higher or Lower LeetCode Solution150
858Design a Stack With Increment Operation Leetcode Solution150
859Count Distinct Elements in Every Window of Size K150
860Level order Traversal in Spiral Form150
861Sum of nearest smaller and greater number150
862Find All Possible Recipes from Given Supplies LeetCode Solution150
863Binary Search Tree Search and Insertion150
864Check if a given array can represent Preorder Traversal of Binary Search Tree150
865Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution150
866Minimum Sum Path in a Triangle150
867Count Negative Numbers in a Sorted Matrix LeetCode Solution150
868Valid Parentheses Leetcode Solution150
869Top K Frequent Words LeetCode Solution150
870Given an Array of Pairs Find all Symmetric Pairs in it150
871Check whether a given Binary Tree is Complete or not150
872Friends Pairing Problem150
873Minimum Number of Taps to Open to Water a Garden LeetCode Solution150
874GCDs of given index ranges in an array149
875Distinct adjacent elements in an array149
876Union and Intersection of two Linked Lists149
877Range sum queries without updates149
878Range LCM Queries149
879Check if stack elements are pairwise consecutive149
880Missing Element in Sorted Array LeetCode Solution149
881Balanced Expression with Replacement149
882Clone Graph LeetCode Solution149
883Matrix Chain Multiplication149
884Find Common Characters Leetcode Solution149
885Repeated Substring Pattern LeetCode Solution149
886Destination City Leetcode Solution149
887Brightest Position on Street LeetCode Solution149
888Sorted Array to Balanced BST149
889Find distance between two nodes of a Binary Tree149
890K’th Largest Element in BST when modification to BST is not allowed148
891Minimum sum of multiplications of n numbers148
892Time Based Key-Value Store LeetCode Solution148
893Construct Complete Binary Tree from its Linked List Representation148
894Design Browser History LeetCode Solution148
895Three way partitioning of an array around a given range148
896Count ways to reach the nth stair using step 1, 2 or 3148
897Shortest Word Distance Leetcode Solution148
898An Interesting Method to generate Binary Numbers from 1 to n148
899BFS for Disconnected Graph148
900Diagonal Traverse LeetCode Solution148
901Water Bottles Leetcode Solution148
902Check if an Array is Stack Sortable148
903Rearrange an Array Such that arr[i] is equal to i148
904Averages of Levels in Binary Tree147
905Convert Sorted List to Binary Search Tree147
906Diagonal Traversal LeetCode Solution147
907Rearrange Spaces Between Words Leetcode Solution147
908Insert Delete GetRandom147
909Lemonade Change Leetcode Solution147
910Daily Temperatures Leetcode Solution147
911Spiral Matrix III LeetCode Solution147
912Least Number of Unique Integers after K Removals Leetcode Solution147
913Guess Number Higher or Lower II147
914Queries for GCD of all numbers of an array except elements in a given range147
915Delete And Earn147
916Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i147
917Find all permuted rows of a given row in a matrix146
918Vertical sum in a given binary tree146
919Queue using Stacks146
920Robot Bounded In Circle LeetCode Solution146
921Set Matrix Zeroes Leetcode Solution146
922Maximum Score After Splitting a String Leetcode Solution146
923Count Subarrays with Same Even and Odd Elements146
924Special Positions in a Binary Matrix Leetcode Solution146
925Split Array Into Consecutive Subsequences145
926Binary Tree Longest Consecutive Sequence LeetCode Solution145
927Palindrome Partitioning Leetcode Solution145
928Construct the Rectangle Leetcode Solution145
929Merge Two Sorted Lists Leetcode145
930Largest area rectangular sub-matrix with equal number of 1’s and 0’s145
931Alien Dictionary145
932A program to check if a binary tree is BST or not145
933Dividing Array into Pairs With Sum Divisible by K145
934Check if any two intervals overlap among a given set of intervals145
935Check if the given array can represent Level Order Traversal of Binary Search Tree145
936Number of Distinct Islands Leetcode Solution145
937Median of Two Sorted Arrays145
938Maximum Subarray Sum Excluding Certain Elements145
939Iterative Postorder Traversal Using Two Stacks145
940All Unique Triplets that Sum up to a Given Value144
9413 Sum144
942Lexicographical Numbers Leetcode Solution144
943Longest Palindromic Subsequence144
944Print Fibonacci sequence using 2 variables144
945Construct BST from its given Level Order Traversal144
9464Sum144
947Three Consecutive Odds Leetcode Solution144
948Stone Game II Leetcode143
949Maximum Frequency Stack Leetcode Solution143
950Count Submatrices With All Ones LeetCode Solution143
951Difference Array | Range update query in O(1)143
952Create Maximum Number143
953Minimum Height Trees LeetCode Solution143
954Maximum Product Subarray143
955Remove Duplicates from Sorted List II LeetCode Solution143
956Strongly Connected Component143
957Maximize Sum of Array after K Negations Leetcode Solution143
958Sliding Window Maximum143
959Number of Equivalent Domino Pairs Leetcode Solution143
960Analyze User Website Visit Pattern LeetCode Solution143
961Can Make Arithmetic Progression From Sequence Leetcode Solution142
962Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space142
963Binary array after M range toggle operations142
964Collect maximum points in a grid using two traversals142
965Unique Paths II142
966Length of Longest Fibonacci Subsequence142
967Count subarrays where second highest lie before highest142
968Infix to Postfix142
969Trim a Binary Search Tree142
970My Calendar I LeetCode Solution142
971Minesweeper LeetCode Solution141
972Merging Intervals141
973Symmetric Tree141
974Count Primes in Ranges141
975Find Maximum of Minimum for Every Window Size in a Given Array141
976Find postorder traversal of BST from preorder traversal141
977The Painter’s Partition Problem141
978Kth Smallest Element in a BST Leetcode Solution141
979Find the Difference Leetcode Solution141
980Intersection of Two Linked Lists LeetCode Solution141
981Climbing stairs140
982Count pair with Given Sum140
983Word Break140
984Reverse Nodes in K-Group140
985K Closest Points to Origin Leetcode Solution140
986Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution140
987Minimum Index Sum of Two Lists140
988Longest Nice Substring LeetCode Solution140
989Sign of the Product of an Array LeetCode Solution140
990Palindrome Partitioning140
991Boundary Traversal of binary tree140
992Product of Array Except Self LeetCode Solution140
993Valid Boomerang Leetcode Solution140
994Height of a generic tree from parent array140
995Pattern Occurrences using Stack140
996Breadth First Search (BFS) for a Graph139
997Find the First Circular Tour that visits all the Petrol Pumps139
998Maximum Sum of 3 Non-Overlapping Subarrays139
999Asteroid Collision LeetCode Solution139
1000Graph Valid Tree LeetCode Solution139
1001Largest Number Leetcode Solution139
1002Maximum length subsequence with difference between adjacent elements as either 0 or 1139
1003Level Order Traversal of Binary Tree139
1004Largest divisible pairs subset139
1005Newman-Conway Sequence139
1006Binary Search Tree Delete Operation139
1007Segment Tree139
1008Friends Of Appropriate Ages LeetCode Solution139
1009Largest Substring Between Two Equal Characters Leetcode Solution139
1010Number Of Longest Increasing Subsequence139
1011Rearrange array such that even positioned are greater than odd138
1012Find Duplicate Subtrees138
1013Maximum Length of Repeated Subarray138
1014Maximum Number of Ways to Partition an Array LeetCode Solution138
1015Insertion in a Binary Tree138
1016Next Greater Element III LeetCode Solution138
1017The Maze III LeetCode Solution138
1018Compute nCr % p138
1019Shortest Completing Word Leetcode Solution138
1020Double the first element and move zero to end138
1021Find number of pairs in an array such that their XOR is 0138
1022Construct Binary Tree from given Parent Array representation138
1023Longest subsequence such that difference between adjacents is one138
1024Scramble String LeetCode Solution138
1025K maximum sums of overlapping contiguous sub-arrays138
1026Boolean Parenthesization Problem138
1027Construction of Longest Increasing Subsequence (N log N)138
1028Merge Sort138
1029Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’138
1030Maximum subsequence sum such that no three are consecutive138
1031Partition Equal Subset Sum137
1032Number of palindromic paths in a matrix137
1033Ugly Numbers137
1034Iterative Depth First Traversal of Graph137
1035Build an Array With Stack Operations Leetcode Solution137
1036Design Hit Counter LeetCode Solution137
1037Binary Search Tree137
1038Make The String Great Leetcode Solution137
1039Kill Process LeetCode Solution137
1040Maximum weight transformation of a given string137
1041Maximum Product of Indexes of Next Greater on Left and Right137
1042String Matching in an Array Leetcode Solution137
1043Decrypt String from Alphabet to Integer Mapping Leetcode Solution137
1044Depth First Search (DFS) for a Graph137
1045Count minimum steps to get the given desired array136
1046Advantages of BST over Hash Table136
1047Level order traversal using two Queues136
1048Morris Inorder Traversal136
1049First missing positive136
1050Available Captures for Rook Leetcode Solution136
1051Serialize and Deserialize Binary Tree136
1052Add two numbers135
1053Invalid Transactions LeetCode Solution135
1054Find a Peak Element II LeetCode Solution135
1055Balanced Binary Tree135
1056Lowest Common Ancestor135
1057Maximum difference between frequency of two elements such that element having greater frequency is also greater135
1058Custom Sort String Leetcode Solution135
1059Kth Smallest Element in a Sorted Matrix LeetCode Solution135
1060Bitwise AND of Numbers Range LeetCode Solution135
1061Validate Binary Search Tree134
1062Combination Sum IV LeetCode Solution134
1063Path Sum II LeetCode Solution134
1064Count pairs from two sorted arrays whose sum is equal to a given value x134
1065Employee Importance LeetCode Solution134
1066Regular Expression Matching Regular Expression Matching LeetCode Solution134
1067Generate Parentheses Leetcode Solution134
1068Minimum Size Subarray Sum134
1069Ugly Number II LeetCode Solution134
1070Remove Duplicates from Sorted Array II Leetcode Solution134
1071Find Peak Element134
1072Super Ugly Number134
1073Implement Trie (Prefix Tree) Leetcode Solution133
1074Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution133
1075Binary Tree Right Side View LeetCode Solution133
1076Increasing Triplet Subsequence LeetCode Solution133
1077Defanging an IP Address LeetCode Solution133
1078Recover Binary Search Tree Leetcode Solution133
1079Root to Leaf path with target sum Leetcode Solutions133
1080Rearrange array such that even index elements are smaller and odd index elements are greater133
1081Move all negative elements to end in order with extra space allowed133
1082Find whether a subarray is in form of a mountain or not133
1083Consecutive Characters LeetCode Solution132
1084Largest BST Subtree LeetCode Solution132
1085Number of Closed Islands Leetcode Solution132
1086Subarrays with K Different Integers Leetcode Solution132
1087Search in Sorted Rotated Array132
1088Day of the Year Leetcode Solution132
1089Populating Next Right Pointers in Each Node Leetcode Solution132
1090Smallest Common Region Leetcode Solution131
1091Count Largest Group Leetcode Solution131
1092Number of Students Doing Homework at a Given Time Leetcode Solution131
1093Types of Binary Tree131
1094Remove Palindromic Subsequences Leetcode Solution131
1095Longest Bitonic Subsequence131
1096Serialize and Deserialize Binary Tree LeetCode Solution131
1097Find Smallest Range Containing Elements from k Lists131
1098Find maximum difference between nearest left and right smaller elements130
1099Clone a Binary Tree with Random Pointers130
1100Find Three Element From Different Three Arrays Such That a + b + c = sum130
1101Maximize Distance to Closest Person LeetCode Solution130
1102Level of Each node in a Tree from source node130
1103Minimum Absolute Difference in BST Leetcode Solution130
1104Binary Tree Data Structure130
1105Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1106Distinct Subsequences130
1107Number of siblings of a given Node in n-ary Tree130
1108Convert BST into a Min-Heap without using array130
1109Print all triplets in sorted array that form AP130
1110Find the minimum distance between two numbers130
1111Remove duplicates from sorted array130
1112Next Permutation Leetcode Solution130
1113Print Next Greater Number of Q queries129
1114Thousand Separator Leetcode Solution129
1115Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution129
1116Construct K Palindrome Strings LeetCode Solution129
1117Write Code to Determine if Two Trees are Identical129
1118Divisible Pairs Counting129
1119Sum of Even Numbers After Queries129
1120Third Maximum Number Leetcode Solution129
1121Path Sum129
1122Palindrome Permutation LeetCode Solution129
1123Bottom View of a Binary Tree129
1124Cutting a Rod129
1125Minimum Score Triangulation of Polygon Leetcode Solution128
1126Longest Increasing Consecutive Subsequence128
1127Minimum sum of squares of character counts in a given string after removing k characters128
1128Queries for Number of Distinct Elements in a Subarray128
1129Reformat The String Leetcode Solution128
1130Delete Nodes and Return Forest Leetcode Solution128
1131Print Right View of a Binary Tree128
1132Maximum Product Subarray128
1133Mean of Array After Removing Some Elements Leetcode Solution128
1134Iterative method to find ancestors of a given binary tree128
1135Diameter of N-Ary Tree LeetCode Solution128
1136Valid Tic-Tac-Toe State LeetCode Solution128
1137Constant time range add operation on an array128
1138Products of ranges in an array128
1139Maximum Product of Splitted Binary Tree LeetCode Solution127
1140Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1141Prime Palindrome LeetCode Solution127
1142Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution127
1143Swap Nodes In Pairs126
1144Moser-de Bruijn Sequence126
1145Find maximum length Snake sequence126
1146Subset Sum Problem in O(sum) space126
1147Cells with Odd Values in a Matrix LeetCode Solution126
1148Search an Element in Sorted Rotated Array126
1149Search Insert Position126
1150Palindromic Substrings Leetcode Solution126
1151Maximum Binary Tree125
1152Red-Black Tree Introduction125
1153Topological Sorting125
1154Merge two BSTs with limited extra space125
1155Bus Routes Leetcode Solution125
1156Kth Smallest Number in Multiplication Table Leetcode Solution125
1157Transform a BST to Greater sum Tree125
1158Priority Queue125
1159Print modified array after executing the commands of addition and subtraction125
1160Closest Binary Search Tree Value Leetcode Solution124
1161Check Array Formation Through Concatenation Leetcode Solution124
1162Maximize sum of consecutive differences in a circular array124
1163Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution124
1164Possible Bipartition LeetCode Solution123
1165Web Crawler LeetCode Solution123
1166Count even length binary sequences with same sum of first and second half bits123
1167Search Suggestions System LeetCode Solution123
1168Minimum Sideway Jumps LeetCode Solution123
1169Find Largest Value in Each Tree Row LeetCode Solution123
1170K’th Largest element in BST using constant extra space123
1171Minimum Cost to Move Chips to The Same Position LeetCode Solution123
1172Golomb sequence123
1173Given a binary tree, how do you remove all the half nodes?123
1174Decision Tree123
1175Rotate Array123
1176Longest Repeated Subsequence122
1177Factorial Trailing Zeroes LeetCode Solution122
1178Maximum number of segments of lengths a, b and c122
1179Find a sorted subsequence of size 3 in linear time122
1180Contiguous Array LeetCode Solution122
1181Binary Tree to Binary Search Tree Conversion122
1182Find the smallest binary digit multiple of given number122
1183Minimum Moves to Equal Array Elements LeetCode Solution122
1184Compare Strings by Frequency of the Smallest Character Leetcode Solution122
1185Maximum Depth Of Binary Tree121
1186Lowest Common Ancestor in Binary Search Tree121
1187Sum of Left Leaves LeetCode Solution121
1188Reverse a Path in BST using Queue121
1189Graph and its representation121
1190Valid Triangle Number121
1191Matchsticks to Square Leetcode Solution121
1192Decrease Elements To Make Array Zigzag LeetCode Solution121
1193First Bad Version121
1194Swapping Nodes in a Linked List Leetcode Solution121
1195Closest Leaf in a Binary Tree LeetCode Solution121
1196Range Queries for Longest Correct Bracket Subsequence120
1197Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution120
1198Maximum sum bitonic subarray120
1199Maximum sum of pairs with specific difference120
1200Number of Orders in the Backlog Leetcode Solution120
1201Reformat Date LeetCode Solution120
1202Queue Reconstruction by Height120
1203Count Pairs Whose Products Exist in Array120
1204Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1205Concatenation of Array LeetCode Solution119
1206Path Crossing Leetcode Solution119
1207Champagne Tower LeetCode Solution119
1208How to print maximum number of A’s using given four keys119
1209Moving Stones Until Consecutive Leetcode Solution119
1210Lowest Common Ancestor of a Binary Tree Leetcode Solution119
1211Minimum Swaps To Make Sequences Increasing LeetCode Solution118
1212Queries on Probability of Even or Odd Number in given Ranges118
1213BST to a Tree with Sum of all Smaller Keys118
1214Kth Smallest Element in a BST118
1215Divide Two Integers Leetcode Solution118
1216Perfect Squares LeetCode Solution118
1217Write a function to get the intersection point of two Linked Lists118
1218Replace two consecutive equal values with one greater117
1219Check if all levels of two Binary Tree are anagrams or not117
1220LRU Cache Leetcode Solution117
1221Array Queries for multiply replacements and product117
1222Maximum Value at a Given Index in a Bounded Array LeetCode Solution117
1223Maximize Elements Using Another Array117
1224Valid Perfect Square LeetCode Solution117
1225Integer Break LeetCode Solution117
1226Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution117
1227Guess The Word117
1228Power of Two116
1229Mean of range in array116
1230Maximum sum of a path in a Right Number Triangle116
1231Sliding Window Median Leetcode Solution116
1232Flatten 2D Vector LeetCode Solution116
1233Count Subsets Having Distinct Even Numbers116
1234New 21 Game116
1235The kth Factor of n Leetcode Solution115
1236Missing Number115
1237Print modified array after multiple array range increment operations115
1238Maximum Array from Two given Arrays Keeping Order Same115
1239Check Completeness of a Binary Tree LeetCode Solution115
1240Range Sum Query using Sparse Table115
1241Arithmetic Slices II – Subsequence LeetCode Solution115
1242Parallel Courses II LeetCode Solution115
1243Design Skiplist LeetCode Solution115
1244Check if each internal node of a BST has exactly one child114
1245Find minimum number of merge operations to make an array palindrome114
1246Contiguous Array114
1247Find Minimum in Rotated Sorted Array II LeetCode Solution114
1248Bold Words in String LeetCode Solution114
1249Graph Cloning114
1250Longest Common Prefix Using Word by Word Matching114
1251Check for Identical BSTs without building the trees114
1252Find k-th smallest element in BST (Order Statistics in BST)114
1253Largest Plus Sign Leetcode Solution113
1254Merge k Sorted Lists Leetcode Solution113
1255Maximum Product Subarray113
1256Print Ancestors of a Given Binary Tree Node Without Recursion113
1257Symmetric Tree LeetCode Solution Leetcode Solution112
1258Print n terms of Newman-Conway Sequence112
1259Image Overlap LeetCode Solution112
1260Check if two nodes are on the same path in a Tree112
1261Minimum Remove to Make Valid Parentheses LeetCode Solution111
1262Verify Preorder Serialization of a Binary Tree111
1263Excel Sheet Column Title LeetCode Solution111
1264Count and Toggle Queries on a Binary Array111
1265Minimum Time to Collect All Apples in a Tree LeetCode Solution110
1266Number of elements less than or equal to a given number in a given subarray110
1267Smallest Range II Leetcode Solution110
1268Palindrome Partitioning109
1269Next greater element109
1270Check If a String Can Break Another String Leetcode Solution109
1271Min Cost Climbing Stairs LeetCode Solution108
1272Orderly Queue LeetCode Solution108
1273Koko Eating Bananas LeetCode Solution107
1274Different Ways to Add Parentheses Leetcode Solution107
1275Longest Substring Without Repeating Characters Leetcode Solution106
1276Check in binary array the number represented by a subarray is odd or even106
1277Largest Submatrix With Rearrangements LeetCode Solution106
1278Peeking Iterator LeetCode Solution106
1279Check if X can give change to every person in the Queue105
1280Merge Sorted Array105
1281Newman–Shanks–Williams prime105
1282Queries for Decimal Values of Subarrays of a Binary Array104
1283Range Minimum Query (Square Root Decomposition and Sparse Table)104
1284Number of indexes with equal elements in given range102
1285Arranging Coins Leetcode Solution102
1286Encoded String With Shortest Length LeetCode Solution102
1287Maximum product of an increasing subsequence102
1288Array Nesting Leetcode Solution102
1289Find maximum average subarray of k length102
1290Maximum Sum Increasing Subsequence102
1291Check given array of size n can represent BST of n levels or not101
1292Convert a BST to a Binary Tree such that sum of all greater keys is added to every key100
1293Find the Winner of the Circular Game LeetCode Solution99
1294Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1295Convert to Base -2 LeetCode Solution99
1296Minimum Number of People to Teach LeetCode Solution99
1297Continuous Subarray Sum LeetCode Solution98
1298Random Pick Index LeetCode Solution98
1299Binary Tree to Binary Search Tree Conversion using STL set98
1300Jump Game IV LeetCode Solution98
1301Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution98
1302Reach a Number LeetCode Solution97
1303Add Two Numbers II Leetcode Solution97
1304Vertical Order Traversal of Binary Tree LeetCode Solution97
1305Queries on XOR of greatest odd divisor of the range96
1306Palindrome Number LeetCode Solution95
1307Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution95
1308Insert Delete GetRandom O(1) Leetcode Solution95
1309Design Underground System Leetcode Solution91
1310Shifting Letters LeetCode Solution90
1311Print Maximum Length Chain of Pairs89
1312Design A Leaderboard Leetcode Solution88
1313Detect Capital Leetcode Solution88
1314Substring with Concatenation of All Words Leetcode Solution85
1315Minimum Swaps to Group All 1’s Together Leetcode Solution84
1316Top K Frequent Elements LeetCode Solution83
1317Count Sub Islands LeetCode Solution83
1318Minimum Path Sum Leetcode Solution82
1319Binary Tree Inorder Traversal LeetCode Solution81
1320Odd Even Linked List Leetcode Solution79
1321Maximum Population Year LeetCode Solution78
1322Longest Common Subsequence LeetCode Solution78
1323Decode String Leetcode Solution78
1324Find the Town Judge LeetCode Solution77
1325Best Meeting Point LeetCode Solution77
1326Shortest Unsorted Continuous Subarray LeetCode Solution76
1327Find the Town Judge LeetCode Solution76
1328Sum Root to Leaf Numbers LeetCode Solution75
1329Rectangle Overlap LeetCode Solution72
1330Design Add and Search Words Data Structure LeetCode Solution71
1331Maximum Population Year LeetCode Solution71
1332Flatten Binary Tree to Linked List LeetCode Solution69
1333Score of Parenthesis LeetCode Solution68
1334Stone Game IV LeetCode Solution68
1335Insert into a Sorted Circular Linked List LeetCode Solution68
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution65
1338Is Graph Bipartite? LeetCode Solution64
1339Valid Triangle Number LeetCode Solution64
1340Divide Chocolate LeetCode Solution57
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution53
1342Reverse Integer Leetcode Solution47
1343Range Sum of BST LeetCode Solution46
1344Find K Closest Elements LeetCode Solution43
1345Sort Colors LeetCode Solution43
1346Rotate String LeetCode Solution40
1347Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution40
1348Excel Sheet Column Number LeetCode Solution39
1349H-Index Leetcode Solution20
1350Maximum Size Subarray Sum Equals k Leetcode Solution20
1351High Five LeetCode Solution19
1352Camelcase Matching Leetcode Solution18
1353Monotonic Array Leetcode Solution16
1354Valid Anagram Leetcode Solution14
1355Group Shifted Strings Leetcode Solution14
1356Peak Index in a Mountain Array LeetCode Solution12
1357Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution12
1358Unique Binary Search Trees LeetCode Solution11
1359Next Greater Element I Leetcode Solution11
1360Next Permutation LeetCode Solution11
1361Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution11
1362Valid Triangle Number LeetCode Solution10
1363Flatten Binary Tree to Linked List LeetCode Solution10
1364Minimum Number of Arrows to Burst Balloons LeetCode Solution10
1365Closest Binary Search Tree Value II LeetCode Solution10
1366Isomorphic Strings LeetCode Solution9
1367Paint House LeetCode Solution9
1368Sentence Screen Fitting LeetCode Solution8
1369Swim in Rising Water LeetCode Solution7
1370Container With Most Water LeetCode Solution5
1371Binary Search LeetCode Solution
Translate »