Contains Duplicate LeetCode Solution

Frequently asked in Adobe Amazon Apple Atlassian Facebook Intel Microsoft Oracle Uber Yahoo
Categories - EasyViews 23

Problem Statement:

Contains Duplicate LeetCode Solution says that- Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Example 1:


 nums = [1,2,3,1]



Example 2:


 nums = [1,2,3,4]



Example 3:


 nums = [1,1,1,3,3,4,3,2,4,2]





  • 1 <= nums.length <= 105
  • -109 <= nums[i] <= 109


 Algorithm –

Idea –

  • In order to find the Contains Duplicate. What will we do in this question? At first, we will focus on the duplicate element, and after seeing the duplicate element. we will simply return True and if the array doesn’t contain duplicates then we will Return False.
  • At first, we will create one HashSet after that we will traverse the whole array and check for the condition that if the element is present in the set then we will return True else we will add that element into the Set.

Approach –

  • Create one Hash-set for an efficient solution.
  • Iterate the whole loop from 0 to len(nums).
  • Check for the Condition that if the element is present in the set then we will return True.
  • Else if not Present then we will add that element into the set.
  • After traversing the whole array if it doesn’t return True, then finally we will return False after iterating the whole array.
  • Hence we will check the Contain Duplicate.

Image of Contain Duplicate-

Contains Duplicate LeetCode SolutionPin


class Solution {
    public boolean containsDuplicate(int[] nums) {
         Set<Integer> s = new HashSet<Integer>();
     for(int i : nums){
       if (s.contains(i)){
                           return true;
        return false;

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        s = set()
        for i in nums:
            if i in s:
                return True
        return False

Complexity Analysis for Contains Duplicate LeetCode Solution:

Time complexity: O(N), As we have traversed through the whole array only one time.

Space complexity: O(N), As we have created one Hash set.



Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Java program to find the number of Nodes in a Binary Tree2542
3Reverse a string without affecting special characters2526
4Palindrome using Recursion2492
5Delete a node of a linked list at given position2022
6Quick Sort1769
7Insert nodes in a linked list in a sorted way (Ascending Order)1709
8Find elements pair from array whose sum equal to number1689
9Sort Elements by Frequency of Occurrences1672
10Write a program to print all permutations of a given string1656
11Find Minimum Distance Between Two Numbers in an Array1518
12Create a Doubly Linked List1484
13Reverse an Array1465
14Smallest window in a string containing all characters of another string1439
15Recursively remove all adjacent duplicates1409
16Find a Triplet That Sum to a Given Value1392
17First Repeating Element1387
18Sum of numbers in String1364
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 Consecutive1291
22Detect a loop in the Linked List1272
23Largest Sum Contiguous Subarray1263
24Quick Sort on SIngly Linked List1258
25Recursive function to do substring search1248
26Print all Possible Combinations of R Elements in a given Array of size N1247
27Subarray with Given Sum1247
28Find the Maximum Repeating Number in Array1205
29Find the First and Second Smallest Elements1155
30Binary Tree Level order traversal in Java1155
31Check if two linked lists are identical1143
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1115
34Find Leaders in an Array1093
35Swap nodes in the linked list1085
36Find the second most frequent character1036
37Find the Number Occurring Odd Number of Times in an Array1034
38Arrange given Numbers to Form the Biggest Number II1027
39Given a string find its first non-repeating character1016
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 digits974
45Find the Missing Number965
46Rearrange Positive and Negative Numbers Alternatively in Array953
47Longest Palindromic Substring946
48Segregate even and odd nodes in a linked list936
49Print Longest common subsequence926
50Transform one string to another using minimum number of given operations915
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome897
53Rearrange given Array in Maximum Minimum Form879
54Iterative Implementation of Quick Sort868
55Insertion Sort858
56Count Possible Triangles856
57Multiplication of Two Matrices841
58Count of Triplets With Sum Less than Given Value830
59Rotate a Linked List828
60Check if the linked list is palindrome827
61Stock Buy Sell to Maximize Profit827
62Concatenation of two strings807
63Print all duplicates in the input string798
64Tug of War798
65Count Number of Substrings with K Distinct Character’s795
66Find Nearest Greater and Smaller Element782
67Reverse String Without Temporary Variable778
68The Celebrity Problem771
69Remove ‘b’ and ‘ac’ from a given string771
70Find Pythagorean Triplets from Array769
71Find all Common Elements in Given Three Sorted Arrays763
72Remove all duplicates in an unsorted linked list740
73Find the Row with Maximum Number of 1’s739
74Remove Minimum Characters so that Two Strings Become Anagrams738
75Find the subarray whose sum is equal to a given number X737
76Find the Peak Element from an Array735
77Addition of Two Matrices730
78Find Smallest Missing Number in a Sorted Array726
79Generate all Binary Strings Without Consecutive 1’s726
80A Product Array Puzzle723
81Maximum Sum of Non Consecutive Elements710
82Implement Two Stacks in an Array707
83Lexicographic rank of string701
84Check if Two given Matrices are Identical692
85Maximum Product Subarray II687
86Multiplication of Previous and Next681
87Subtraction of Two Matrices674
88Merge K Sorted Arrays and Print Sorted Output668
89Divide a string in N equal parts667
90Move All the Zeros to the End of the Given Array666
91Form Minimum Number from Given Sequence of D’s and I’s665
92Online Algorithm for Checking Palindrome in a Stream665
93Check whether two strings are anagram of each other657
94Remove recurring digits in a given number657
95Sort a stack using a temporary stack652
96Maximum Circular Subarray Sum649
97Sort a linked list that is sorted alternating ascending and descending645
98Subarray and Subsequence639
99Find the Minimum Element in a Sorted and Rotated Array637
100Move last element of the Linked List at first place634
101First Circular Tour to Visit all the Petrol Bunks633
102Compare two strings(linked lists)629
1033Sum Leetcode Solution628
104Largest Subarray with Equal Number of 0’s and 1’s627
105Maximum Element in an Array which is Increasing and then Decreasing627
106Palindrome Permutations of a String627
107Flattening a linked list623
108Palindromes in a given range623
109Minimum insertions to form a shortest palindrome619
110Pangram Checking619
111Majority Element618
112Run length encoding616
113Print all permutations with repetition616
114Elements Appear more than N/K times in Array611
115Minimum Characters to be Added at Front to Make String Palindrome609
116Most repeating character in a string606
117Two Sum Leetcode Solution603
118Rotate string to get lexicographically minimum string602
119Repeated Subsequence of Length Two or More601
120Merge a linked list into another at alternate positions596
121Remove all duplicates in a sorted linked list595
122Rearrange a given linked list in-place594
123Minimum number of Merge Operations to make an Array Palindrome593
124Print all anagrams together in a sequence of words592
125Reorder an Array According to the Given Indexes581
126Pancake Sorting Problem579
127Merge Overlapping Intervals II568
128Longest Palindrome can be Formed by Removing or Rearranging Characters567
129Smallest Palindrome after Replacement567
130Remove duplicates from a string566
131Transpose of a Matrix566
132Clone a Linked List with next and random pointer566
133Remove Extra Spaces from a String565
134Removing Spaces from a String using stringstream561
135Maximum Sum Increasing Subsequence560
136Check if a given string is a rotation of a palindrome560
137Size of The Subarray With Maximum Sum558
138Partition Problem552
139Check whether Strings are K Distance Apart or Not548
140Generate all Binary Strings from Given Pattern546
141Length of Longest valid Substring542
142Delete Last Occurrence541
143Check if Two given Strings are Isomorphic to each other538
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized535
145Insert Node in the Sorted Linked List533
146Program to Toggle all Characters in a String530
147Given string is interleaving of two other strings or not526
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 Array514
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 Difference506
155Merge sort better than quick sort for linked lists505
156Compare Two Version Numbers503
157Print all interleavings of given two strings499
158Find nth node of the Linked list from the end498
159Print Reverse of a string (Recursion)496
160Median of Two Sorted Arrays LeetCode Solution495
161Find a Fixed Point in a Given Array495
162Sort 0s 1s and 2s in an Array494
163Reorder Array Using Given Indexes493
164Reverse words in a given string492
165Find the Subarray of given length with Least Average485
166Split linked list using alternate nodes484
167Merge two sorted linked lists such that merged list is in reverse order484
168Print all Palindromic Partitions of a String477
169Print string of odd length in ‘X’ format473
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average466
172Swap Kth Node from beginning with Kth Node from End464
173Find Duplicates in an Array in Most Efficient Way459
174Shortest Superstring Problem458
175print all palindromic partitions455
176Check if String Follows Order of Characters by a Pattern or not452
177Maximum Length of Chain Pairs449
178Sort a String According to Another String448
179Flatten a multilevel linked list445
180Sorting a K Sorted Array440
181Program to add two binary digits435
182Recursively print all the sentences that can be formed from list of word lists431
183Find a Sorted Subsequence of size 3429
184Caesar Cipher428
185Longest Common Prefix Using Binary Search II427
186Reverse a Linked List in groups426
187Longest Span with same Sum in two Binary Arrays II426
188Find the two Numbers with Odd Occurrences in an Unsorted Array425
189Kth Non-repeating Character422
190Reverse a Singly Linked List (Iterative/Non-Recursive)421
191Check if String can Become Empty by Recursively Deleting given Substring418
192Longest Common Prefix Word by Word Matching414
193Rearrange a linked list in Zig-Zag412
194Rotate Image by 90 degrees407
195Permutations of a Given String Using STL407
196Pancake Sorting405
197Perfect Reversible String405
198Find First non-repeating character in a string402
199Merging Two Sorted Arrays402
2001`s and 2`s complement of binary number399
201List items containing all characters of a given word396
202Maximum occurring character in a string396
203Increasing Subsequence of Length three with Maximum Product395
204Find the point where a monotonically increasing function becomes positive first time393
205Sort a linked list with 0s, 1s and 2s390
206Four Elements that Sum to Given390
207Longest Common Prefix using Character by Character Matching387
208Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes387
209Palindrome string (number)384
210Count Number of Occurrences in a Sorted Array384
211Delete N nodes after M381
212Valid Parentheses LeetCode Solution380
213Minimum Characters to be Removed to Make a Binary String Alternate379
214Even Substring Count377
215Split a string376
216Recursive Implementation of atoi()374
217Sorting the array of strings373
218Convert a String that is Repetition of a Substring of Length K370
219Check if a Linked list of Strings form a Palindrome367
220Print Shortest Path to Print a String on Screen367
221Maximum Subarray Leetcode Solution364
222Nth Character in Concatenated Decimal String361
223Convert string1 to string2 in one edit361
224Print All Distinct Elements of the Array360
225Count the number of words360
226Reverse a String using Stack359
227Reverse a singly linked list recursively359
228Find the first Repeating Number in a Given Array358
229Matrix Chain Multiplication using Dynamic Programming358
230wildcard character matching358
231Lower Case To Upper Case355
232Can we reverse a linked list in less than O(n) time ?351
233Binary Tree to Doubly linked list349
234Longest Common Subsequence with Permutations347
235Sort Elements by Frequency II345
236Find the Lost Element From a Duplicated Array344
237Split Four Distinct Strings343
238Merge Two Sorted Arrays341
239Find middle of the Linked List337
240Count the Pairs at Same Distance as in English Alphabets336
241Roman to Integer Leetcode Solution336
242Toeplitz Matrix333
243Palindrome Permutation328
244N queen problem327
245Word Search Leetcode Solution325
246Next Greater Element in an Array325
247Move all negative elements to one side of array323
248Find All Pairs With a Given Difference318
249Searching a node in a Binary Search Tree318
250First non Repeating Element318
251Reverse Bits316
252Print all Possible Ways to Break a String in Bracket Form316
253Sudoku Solver316
254String(represents an integer) to value315
255Count Pairs With Given Sum315
256Find Nth Node315
257Number of Islands LeetCode Solution314
258Reverse a String313
259Types of Binary Tree312
260Change Gender of a given String312
261Repeated Substring Pattern312
262Triplet from three linked lists with given sum312
263Delete a Tree311
264Fibonacci numbers310
265Sort an array of strings309
266Reverse a linked list308
267Meeting Rooms II LeetCode Solution308
268Number of sub-strings which recursively add up to 9308
269Min Stack308
270How to Efficiently Implement k Stacks in a Single Array?308
271Delete a node under given conditions307
272Most Frequent Element in an Array305
273Cuckoo sequence program304
274Longest Palindromic Substring LeetCode Solution304
275Dijkstra Algorithm303
276Longest Common Extension302
277Binary Tree299
278Remove spaces from a string298
279Max stack296
280House Robber Leetcode Solution296
281Best Time to Buy and Sell Stock  II Leetcode Solution293
282Subset Leetcode293
283Word Search292
284KMP Algorithm290
285Shuffle a given Array290
286Find, second, frequent, character288
287Expression Evaluation288
288Remove middle points in a linked list of line segments288
289Minimize the maximum difference between the heights287
290Plus One Leetcode Solution287
291Combination Sum Leetcode Solution285
292Number Of 1 bits284
293Search Insert Position Leetcode Solution284
294Reverse words in a string284
295Pair of Positive Negative Values in an Array282
296Evaluation of Postfix Expression282
297Sliding Window Technique281
298Subarray with 0 sum279
299Set Matrix Zeroes279
300Min Stack Leetcode Solution278
301Rabin Karp Algorithm278
302Backspace String Compare276
303Valid Palindrome Leetcode Solution276
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
308Sqrt(x) Leetcode Solution270
309Reversing a Queue269
310Delete middle element of a stack269
311Contains Duplicate266
312Implementation of Deque using Doubly Linked List266
313String Compression266
314Contains Duplicate II Leetcode Solution265
315Count of index pairs with equal elements in an array265
316Count subarrays with equal number of 1’s and 0’s265
317Tower Of Hanoi265
318Intersection of Two Arrays II Leetcode Solution264
319Reverse individual words264
320Product of array except self264
321Find Top K (or Most Frequent) Numbers in a Stream264
322How to Delete a Linked List263
323Minimum swaps required to bring all elements less than or equal to k together263
324Combination Sum263
325Pascal Triangle Leetcode263
326Count Odd Numbers in an Interval Range Leetcode Solution263
327Page Replacement Algorithms in Operating Systems262
328Segregate even and odd numbers260
329Group Words With Same Set of Characters260
330Integer to Roman Leetcode Solution260
331Smallest Subarray with k Distinct Numbers259
332Bellman Ford Algorithm258
333Postfix to Infix Conversion258
334Second Most Repeated Word in a Sequence258
335Minimum Value to Get Positive Step by Step Sum Leetcode Solution258
336Single Number Leetcode Solution258
337Sorting array using Stacks258
338Sum of minimum and maximum elements of all subarrays of size k257
339Sort elements by frequency257
340Find sum of non-repeating elements (distinct) elements in an array257
341Top K Frequent Words256
342Next Permutation256
343Add Binary Leetcode Solution255
344Arithmetic Expression Evaluation255
345K-th Smallest Element in a Sorted Matrix255
346Count subarrays having total distinct elements same as original array254
347Minimum operation to make all elements equal in array254
348Given two unsorted arrays find all pairs whose sum is x254
349Construct Binary Tree from Given Inorder and Preorder Traversals253
350First element occurring k times in an array252
351Scramble String252
352Maximum Number of Balloons Leetcode Solution252
353Pow(x, n) Leetcode Solution251
354Convex Hull Algorithm251
355Palindrome Linked List Leetcode Solution251
356Special Number251
357Longest Common Prefix Leetcode Solution251
358Find Lucky Integer in an Array Leetcode Solution250
359Longest Substring Without Repeating Characters LeetCode Solution250
360Find duplicates in a given array when elements are not limited to a range250
361Majority Element Leetcode Solution249
362Design a stack that supports getMin() in O(1) time and O(1) extra space249
363Evaluate Division248
364Kruskal Algorithm248
365Permutations Leetcode Solution248
366Third Maximum Number Leetcode Solution246
367Running Sum of 1d Array Leetcode Solution244
368Maximum possible difference of two subsets of an array244
369Check if two arrays are equal or not244
370Number of Good Pairs Leetcode Solution243
371Reverse a Number Using Stack243
372Spiral Matrix LeetCode Solution243
373Prefix to Infix Conversion243
374Fizz Buzz Leetcode243
375Reversing the First K elements of a Queue243
376Maximum Distance Between two Occurrences of Same Element in Array243
377Minimum Path Sum242
378Maximum Subarray242
379Huffman Coding242
380Unique Paths241
381Find Numbers with Even Number of Digits Leetcode Solution241
382Maximal Square241
383Smallest Element Repeated Exactly K Times241
384Range Sum Query 2D – Immutable Leetcode Solution241
385Single Number240
386Find the Closest Palindrome number240
387Swap Nodes in Pairs Leetcode Solutions240
388Minimum Steps to reach target by a Knight240
389Find the Town Judge Leetcode Solution240
390Group Anagrams240
391Count Primes Leetcode Solutions240
392Find Number of Employees Under every Employee239
393Convert String To Int239
394Remove Minimum Number of Elements Such That no Common Element Exist in both Array239
395Find the first repeating element in an array of integers239
396Minimum Absolute Difference Leetcode Solution239
397Sorting using trivial hash function239
398Find top three repeated in array239
399Palindrome Substring Queries238
400Zigzag Conversion238
401Sort Array by Increasing Frequency Leetcode Solution238
402Cumulative Frequency of Count of Each Element in an Unsorted Array237
403Find All Numbers Disappeared in an Array Leetcode Solution237
404Implement Stack and Queue using Deque236
405Leetcode Permutations236
406Check if Array Contains Contiguous Integers With Duplicates Allowed236
407Pascal’s Triangle II Leetcode Solution236
408Print All Distinct Elements of a Given Integer Array235
409Merge Two Sorted Lists Leetcode Solutions235
410Expression Contains Redundant Bracket or Not235
411Count Substrings with equal number of 0s, 1s and 2s235
412Power of Two Leetcode Solution235
413Print all subarrays with 0 sum235
414How to Implement Stack Using Priority Queue or Heap?234
415Length of the largest subarray with contiguous elements234
416Matrix Diagonal Sum Leetcode Solution234
417Decode String234
418Difference between highest and least frequencies in an array234
419Bipartite Graph234
420Missing Number Leetcode Solution234
421Sort Integers by The Number of 1 Bit Leetcode Solution234
422Letter Case Permutation233
423Fizz Buzz233
424Subarray Sum Equals k233
425Prim’s Algorithm233
426House Robber II Leetcode Solution233
427Happy Number Leetcode Solution232
428Maximum Depth of Binary Tree Leetcode Solution232
429Sort a stack using recursion232
430LRU Cache Implementation232
431Find Median from data Stream231
432Top K Frequent Elements231
433Unique Paths Leetcode Solution231
434Count pairs from two linked lists whose sum is equal to a given value231
435Subarrays with distinct elements231
436Reverse Integer231
437Find all pairs (a, b) in an array such that a % b = k231
438Search in Rotated Sorted Array Leetcode Solution231
439Subset sum problem231
440Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution230
441Find Winner on a Tic Tac Toe Game Leetcode Solution230
442Coin Change 2 Leetcode Solution229
443Pair with given product228
444Find the Difference Leetcode Solution228
445Max Consecutive Ones Leetcode Solution228
446Find elements which are present in first array and not in second228
447Capacity To Ship Packages Within D Days Leetcode Solution228
448Monotonic Array LeetCode Solution228
449Nth Catalan Number228
450Check If N and Its Double Exist Leetcode Solution228
451Reverse a Stack Using Recursion228
452How Many Numbers Are Smaller Than the Current Number Leetcode Solution227
453Find The Duplicate Number227
454Integer to English words226
455Subarray Sum Equals K LeetCode Solution226
456Count and Say226
457Find distinct elements common to all rows of a matrix226
458Text Justification LeetCode Solution226
459Edit Distance225
460Longest subarray not having more than K distinct elements225
461Find Minimum In Rotated Sorted Array225
462Valid Parenthesis String225
463Find Index of Closing Bracket for a Given Opening Bracket in an Expression225
464Sum of Subarray Ranges Leetcode Solution225
465Fibonacci Number LeetCode Solution225
466Trapping Rain Water Leetcode Solution225
467Find four elements that sum to a given value (Hashmap)224
468Reverse Vowels of a String Leetcode Solution224
469Best Time to Buy and Sell Stock III Leetcode Solution224
470Remove Duplicates from Sorted Array Leetcode Solution224
471Floyd Warshall Algorithm224
472Priority Queue Using Singly Linked List224
473Find any one of the multiple repeating elements in read only array224
474Subtract the Product and Sum of Digits of an Integer Leetcode Solution223
475Longest Common Prefix using Trie223
476Check if a given array contains duplicate elements within k distance from each other223
477Reverse a String223
478Target Sum223
479Kth largest element in an Array Leetcode Solutions223
480Design Parking System Leetcode Solution222
481Rearrange a binary string as alternate x and y occurrences222
482The K Weakest Rows in a Matrix Leetcode Solution222
483Prefix to Postfix Conversion221
484MiniMax Algorithm221
485Jump Game Leetcode Solution221
486Generate a String With Characters That Have Odd Counts Leetcode Solution221
487Delete a Node from linked list without head pointer221
488Count number of triplets with product equal to given number221
489Shuffle String Leetcode Solution220
490Find subarray with given sum (Handles Negative Numbers)220
491Find Common Characters Leetcode Solution220
492Sorting a Queue without Extra Space220
493Find missing elements of a range220
494Shuffle the Array Leetcode Solution220
495Word Ladder LeetCode Solution220
496The Stock Span Problem219
497Degree of an array219
498Intersection of Two Arrays219
499Substring With Concatenation Of All Words219
500Flood Fill LeetCode219
501Iterative Tower of Hanoi218
502Top View of Binary Tree218
503Multiply Strings Leetcode Solution218
504Check for Balanced Parentheses in an Expression218
505Balanced Binary Tree Leetcode Solution218
506K-th Distinct Element in an Array218
507Merge Two Sorted Linked Lists218
508Shortest Palindrome218
509Best Time to Buy and Sell Stock LeetCode Solution218
510Postfix to Prefix Conversion217
511Minimum Delete Operations to make all Elements of Array Same217
513Priority Queue in C++217
514Kids With the Greatest Number of Candies Leetcode Solution217
515Iterative Inorder Traversal of a Binary Tree217
516Longest Common Prefix using Sorting217
517Implement a stack using single queue217
518Next Greater Element I Leetcode Solution217
519Excel Sheet Column Number Leetcode Solution217
520Number of Steps to Reduce a Number to Zero Leetcode Solution216
521Longest Common Subsequence216
522Container with Most Water216
523Slowest Key Leetcode Solution216
524Concatenation of Array LeetCode Solution216
525Peak Index in a Mountain Array216
526Count and Say Leetcode Solution216
527Reverse Words in a String III LeetCode Solution216
528Move Zeroes LeetCode Solution216
529Valid Sudoku216
530Minimum Knight Moves LeetCode Solution216
531Find the Duplicate Element216
532Next Greater Frequency Element215
533Minimum Moves to Equal Array Elements Leetcode Solution215
534Arrange given numbers to form the biggest number215
535Implement Stack using Queues215
536Sum of Left Leaves Leetcode Solutions215
537Max Area of Island215
538Find Sum of all unique sub-array sum for a given array214
539Hamming Distance214
540Find First and Last Position of Element in Sorted Array Leetcode Solution214
541Linked List Cycle II LeetCode Solution214
542Convert array into Zig-Zag fashion214
543Kth Largest Element in a Stream Leetcode Solution213
544Merge Overlapping Intervals213
545Jewels and Stones Leetcode Solution213
546Largest Sum Contiguous Subarray213
547Smallest Subarray With all Occurrences of a Most Frequent Element213
548How to check if two given sets are disjoint?213
549Check if a queue can be sorted into another queue using a stack212
550Largest Perimeter Triangle Leetcode Solution212
551Change the Array into Permutation of Numbers From 1 to N212
552Isomorphic Strings Leetcode Solution212
553Is Subsequence Leetcode Solution212
554Group Multiple Occurrence of Array Elements Ordered by first Occurrence212
555Excel Sheet Column Title Leetcode Solution212
556Gold Mine Problem211
557Zigzag Conversion LeetCode Solution211
558Shuffle an Array211
559Contiguous Array Leetcode211
560Find N Unique Integers Sum up to Zero Leetcode Solution211
561Valid Anagrams210
562Minimum Cost to Hire K Workers210
563Minimum number of subsets with distinct elements210
564Delete Node in a Linked List Leetcode Solution210
565Koko Eating Bananas Leetcode Solution210
566Convert a normal BST to Balanced BST210
567Last Stone Weight210
568N-th Tribonacci Number Leetcode Solution210
569Maximum sum rectangle in a 2D matrix209
570Count the number of nodes at given level in a tree using BFS209
571Minimum Bracket Reversals209
572Find if an Expression has Duplicate Parenthesis or Not209
573Summary Ranges Leetcode Solution209
574Shortest Path in a Grid with Obstacles Elimination LeetCode Solution208
5753Sum Closest LeetCode Solution208
576Mobile Numeric Keypad Problem208
577Number of Provinces Leetcode Solution208
578Maximum path sum in a triangle208
579Best Time to Buy and Sell Stock208
580Integer to Roman208
581Implementation of Deque using circular array208
582Smallest Good Base208
583Length of Last Word Leetcode Solution208
584Distribute Candies to People Leetcode Solution208
585Decode Ways207
586Find Words That Can Be Formed by Characters Leetcode Solution207
587Maximum Distance in Array207
588Relative Sort Array Leetcode Solution207
589Frog Jump Leetcode Solution206
590Build Array From Permutation Leetcode Solution206
591Non-overlapping sum of two sets206
592First negative integer in every window of size k206
593Trapping Rain Water LeetCode Solution206
594Longest Increasing Subsequence206
595Island Perimeter Leetcode Solution205
596Word Pattern205
597Sort Characters By Frequency LeetCode Solution205
598Rotate Image LeetCode Solution205
599Maximum Number of Occurrences of a Substring Leetcode Solution205
600Combinations Leetcode Solution205
601Minimum Operations to convert X to Y205
602Delete consecutive same words in a sequence205
603LRU Cache LeetCode Solution205
604Maximum difference between first and last indexes of an element in array205
60501 Matrix LeetCode Solution205
606Remove All Occurrences of a Substring LeetCode Solution205
607Iterative Method to find Height of Binary Tree204
608XOR Operation in an Array Leetcode Solution204
609Remove Linked List Elements Leetcode Solution204
610Assign Cookies Leetcode Solution204
611Sieve of Eratosthenes204
612Count all subsequences having product less than K203
613The Knapsack Problem203
614Find the smallest positive integer value that cannot be represented as sum of any subset of a given array203
615Minimum insertions to form a palindrome with permutations allowed203
616Minimum number of distinct elements after removing m items203
617Isomorphic Strings202
618Reverse a stack without using extra space in O(n)202
619Find Largest d in Array such that a + b + c = d202
620Find minimum difference between any two elements202
621GCD Of Two Numbers202
622Bubble sort using two Stacks201
623Maximum Number of Chocolates to be Distributed Equally Among k Students201
624Rotate List Leetcode Solution201
625Sum of f(a[i], a[j]) over all pairs in an array of n integers201
626Stone Game LeetCode201
627Convert Sorted Array to Binary Search Tree Leetcode Solution201
628Permutation in String Leetcode Solution201
629Insert Interval Leetcode Solution201
630Tracking current Maximum Element in a Stack201
631How to Create Mergable Stack?200
632Form minimum number from given sequence200
633Find the Duplicate Number LeetCode Solution200
634Defanging an IP Address Leetcode Solution200
635Reorganize String200
636Same Tree LeetCode Solution200
637Unique Binary Search Trees200
638K Empty Slots200
639Applications of Breadth First Search and Depth First Search200
640Distance Between Bus Stops Leetcode Solution199
641Convert an array to reduced form199
642Longest Increasing Path in a Matrix LeetCode Solution199
643Optimal Account Balancing LeetCode Solution199
644Count Good Nodes in Binary Tree Leetcode Solution199
645Minimum Depth of Binary Tree Leetcode Solution198
646First Unique Character in a String LeetCode Solution198
647License Key Formatting Leetcode Solution198
648Employee Free Time LeetCode Solution198
649Find pairs with given sum such that elements of pair are in different rows198
650Printing brackets in Matrix Chain Multiplication Problem198
651Painting Fence Algorithm197
652Letter Combinations of a Phone Number197
653Replace Elements with Greatest Element on Right Side Leetcode Solution197
654Longest Substring with At Most K Distinct Characters LeetCode Solution197
655Find Pair with Greatest Product in Array197
656Word Wrap Problem197
657Coin Change Problem196
658Merge Two Balanced Binary Search Trees196
659Sort Array By Parity LeetCode Solution196
660Convert a Number to Hexadecimal Leetcode Solution196
661Reducing Dishes LeetCode Solution196
662House Robber196
663Check If It Is a Straight Line Leetcode Solution196
664Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
665Longest Span with same Sum in two Binary arrays195
666Moving Average from Data Stream Leetcode Solution195
667Robot Room Cleaner Leetcode Solution195
668Find the node with minimum value in a Binary Search Tree195
669Print the Fibonacci numbers in reverse order195
670Segregate 0s and 1s in an Array195
671Strobogrammatic Number LeetCode Solution195
672K Empty Slots LeetCode195
673Largest subarray with equal number of 0s and 1s195
674Maximum Consecutive Numbers Present in an Array195
675Kth Missing Positive Number Leetcode Solution194
676String Compression LeetCode Solution194
677Dynamic Programming Basics194
678Partition Labels LeetCode Solution194
679Find Leaves of Binary Tree LeetCode Solution194
680Reservoir Sampling194
681Valid Palindrome194
682Queries for counts of array elements with values in given range194
683Flipping an Image LeetCode Solution194
684Find Maximum Level sum in Binary Tree193
685Valid Palindrome II Leetcode Solution193
686String to Integer (atoi) LeetCode Solution193
687Partition Array Into Three Parts With Equal Sum Leetcode Solution193
688Distance of nearest cell having 1 in a binary matrix193
689Sum of All Odd Length Subarrays Leetcode Solution193
690k-th missing element in increasing sequence which is not present in a given sequence193
691Maximum Product of Two Elements in an Array Leetcode Solution193
692Longest Substring with At Least K Repeating Characters LeetCode Solution193
693Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
694Power of Four Leetcode Solution193
695Generate all possible sorted arrays from alternate elements of two given sorted arrays192
696Find the Distance Value Between Two Arrays Leetcode Solution192
697Check If Two String Arrays are Equivalent Leetcode Solution192
698Reverse Only Letters LeetCode Solution192
699Numbers with prime frequencies greater than or equal to k192
700Find unique character in a string192
701Remove brackets from an algebraic string containing + and – operators191
702Count quadruples from four sorted arrays whose sum is equal to a given value x191
703Remove Invalid Parentheses Leetcode Solution191
704Maximum Number of Coins You Can Get Leetcode Solution191
705Path With Maximum Minimum Value LeetCode Solution191
706Find whether an array is subset of another array191
707To Lower Case Leetcode Solution191
708Find the Smallest Divisor given a Threshold Leetcode Solution191
709Increasing Decreasing String Leetcode Solution191
710Binary Tree Maximum Path Sum LeetCode Solution191
711Sort Array by Increasing Frequency Leetcode Solution190
712Number of Dice Rolls With Target Sum LeetCode Solution190
713Wiggle Sort190
714Inorder Successor of a node in Binary Tree190
715Merge Two Binary Trees LeetCode Solution190
716Find the largest multiple of 3190
717Unique Paths II Leetcode Solution190
718Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest190
719Permutation Sequence LeetCode Solution190
720Delete Nth node from the end of the given linked list190
721Recover Binary Search Tree189
722Edit Distance LeetCode Solution189
723Snakes and Ladders LeetCode Solution189
724Subset Sum Leetcode189
725Find if Path Exists in Graph Leetcode Solution189
726BFS vs DFS for Binary Tree189
727Populating Next Right Pointers in Each Node189
728Stack Permutations (Check if an array is stack permutation of other)189
729Non-decreasing Array LeetCode Solution189
730Bulb Switcher LeetCode Solution189
731Race Car LeetCode Solution189
732Base 7 Leetcode Solution189
733Factorial Trailing Zeroes Leetcode Solution189
734Valid Perfect Square Leetcode Solution189
735Lucky Numbers in a Matrix Leetcode Solution189
736Tiling Problem188
737Merge Sorted Array LeetCode Solution188
738Perform String Shifts Leetcode188
739Elements to be added so that all elements of a range are present in array188
740Binary Tree zigzag level order Traversal188
741Ugly Number Leetcode Solution188
742Maximum Length of a Concatenated String with Unique Characters Leetcode Solution188
743Reversing a Queue using Recursion188
744Number of NGEs to the Right188
745Valid Number188
746Minimum sum of multiplications of n numbers187
747Program for Bridge and Torch problem187
748Restore IP Addresses Leetcode Solution187
749Student Attendance Record I Leetcode Solution187
750Majority Element II Leetcode Solution187
751Best Meeting Point LeetCode Solution187
752Minimum Cost For Tickets Leetcode Solution187
753String comparison containing wildcards187
754Keyboard Row Leetcode Solution187
755Binary Tree Zigzag Level Order Traversal LeetCode Solution187
756Maximum 69 Number Leetcode Solution187
757Evaluate Reverse Polish Notation LeetCode Solution187
758Add and Search Word – Data structure design LeetCode187
759Find Maximum Depth of Nested Parenthesis in a String187
760Growable array based stack186
761Check if Two Expressions With Brackets are Same186
762Print a Binary Tree in Vertical Order186
763Rank Transform of an Array Leetcode Solution186
764Word Pattern LeetCode Solution186
765Split a String in Balanced Strings Leetcode Solution186
766Regular Expression Matching186
767Construct BST from given Preorder Traversal186
768Morris Traversal186
769N-Queens LeetCode Solution186
770Priority Queue using doubly linked list185
771Check for Palindrome after every character replacement Query185
772Symmetric Tree Leetcode Solution185
773Maximum Product of Three Numbers LeetCode Solution185
774Finding K closest element185
775Maximum Profit in Job Scheduling Leetcode Solution185
776Hamming Distance Leetcode Solution185
777Find All Possible Recipes from Given Supplies LeetCode Solution185
778Jump Game185
779Sorted Linked List to Balanced BST185
780Brick Wall LeetCode Solution185
781Number of Days Between Two Dates LeetCode Solution185
782Find Median from Data Stream LeetCode Solution185
783Binomial Coefficient185
784Minimize Maximum Pair Sum in Array LeetCode Solution184
785Partition to K Equal Sum Subsets Leetcode Solution184
786Longest Subarray Having Count of 1s One More than Count of 0s184
787Find All Duplicates in an Array LeetCode Solution184
788Count items common to both the lists but with different prices184
789Special Array With X Elements Greater Than or Equal X Leetcode Solution184
790Top K Frequent Words LeetCode Solution184
791Check If Array Pairs Are Divisible by k LeetCode Solution184
792Sort an array according to the order defined by another array183
793Linked List Cycle183
794Total Numbers With no Repeated Digits in a Range183
795Merge K Sorted Linked Lists183
796Minimum Distance Between BST Nodes Leetcode Solution183
797Largest Rectangle in Histogram LeetCode Solution183
798Maximum Depth of N-ary Tree Leetcode Solution183
799Search in a Binary Search Tree Leetcode Solution183
800Decompress Run-Length Encoded List Leetcode Solution183
801Form Minimum Number From Given Sequence183
802Minimum Time Visiting All Points Leetcode Solution183
803Number of Islands II LeetCode Solution182
804Minimum Height Trees182
805Queue based approach for first non-repeating character in a stream182
806One Edit Distance LeetCode Solution182
807Remove Nth Node From End of List Leetcode Solution182
808Largest rectangular sub-matrix whose sum is 0182
809Maximum Nesting Depth of the Parentheses Leetcode Solution182
810Nested List Weight Sum II LeetCode Solution182
811Kth ancestor of a node in binary tree182
812Invert Binary Tree LeetCode Solution182
813Maximum Difference Between Increasing Elements LeetCode Solution182
814Nearest Exit from Entrance in Maze LeetCode Solution182
815Identify and Mark Unmatched Parenthesis in an Expression181
816Balanced Expression with Replacement181
817Circular Queue181
818Final Prices With a Special Discount in a Shop Leetcode Solution181
819Repeated Substring Pattern LeetCode Solution181
820Given an Array of Pairs Find all Symmetric Pairs in it181
821Lemonade Change Leetcode Solution180
822Last Stone Weight II LeetCode Solution180
823Relative Ranks Leetcode Solution180
824Diagonal Traversal of Binary Tree180
825Minimum time required to rot all oranges180
826Transpose Graph180
827Clone Graph LeetCode Solution179
828Minimum Jumps to Reach Home LeetCode Solution179
829Crawler Log Folder Leetcode Solution179
830Missing Element in Sorted Array LeetCode Solution179
831Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
832Minimum Number of Taps to Open to Water a Garden LeetCode Solution179
833LCS (Longest Common Subsequence) of three strings179
834Daily Temperatures Leetcode Solution179
835Search a 2D Matrix II Leetcode Solution179
836Permutation Coefficient179
837Minimum Swaps to Make Strings Equal Leetcode Solution179
838Subarray Product Less Than K LeetCode Solution179
839Deletion in a Binary Tree179
840Reorder Data in Log Files LeetCode Solution179
841Check if a given array can represent Preorder Traversal of Binary Search Tree179
842Course Schedule II – LeetCode179
843Sliding Window Maximum178
844Remove Duplicates from Sorted List II178
845Binary Search Tree Search and Insertion178
846A Space Optimized DP solution for 0-1 Knapsack Problem178
847Find all permuted rows of a given row in a matrix178
848Tree Traversal (Preorder, Inorder & Postorder)178
849Number Complement Leetcode Solution178
850Distinct adjacent elements in an array178
851Find the Only Repetitive Element Between 1 to N-1178
852Remove Duplicates from Sorted List LeetCode Solution178
853Sort Array By Parity II Leetcode Solution178
854Check if an Array is Stack Sortable178
855Insert Delete GetRandom178
856Find Maximum Sum Possible Equal Sum of Three Stacks178
857Subsequence of Size K With the Largest Even Sum LeetCode Solution178
858Split Array Into Consecutive Subsequences178
859Design Browser History LeetCode Solution178
860Minimum number of jumps to reach end177
861Get Maximum in Generated Array Leetcode Solution177
862Guess Number Higher or Lower LeetCode Solution177
863An Interesting Method to generate Binary Numbers from 1 to n177
864Check if stack elements are pairwise consecutive177
865Iterative Preorder Traversal177
866Alien Dictionary LeetCode Solution177
867Spiral Matrix II Leetcode Solution177
868Partition List Leetcode Solution176
869Minimum swaps to make sequences increasing176
870Minimum Sum Path in a Triangle176
871Matrix Chain Multiplication176
872Sum of nearest smaller and greater number176
873Sort Colors176
874Count Distinct Elements in Every Window of Size K176
875Path with maximum average value176
876Union and Intersection of two Linked Lists176
877Valid Parentheses Leetcode Solution176
878Subset with sum divisible by m176
879Interval Tree176
880Find the subarray with least average176
881Brightest Position on Street LeetCode Solution175
882Dividing Array into Pairs With Sum Divisible by K175
883Water Bottles Leetcode Solution175
884Range LCM Queries175
885Count ways to reach the nth stair using step 1, 2 or 3175
886Friends Pairing Problem175
887Time Based Key-Value Store LeetCode Solution175
888Diagonal Traversal LeetCode Solution175
889Iterative Postorder Traversal Using Two Stacks175
890Find all triplets with zero sum175
891Design a Stack With Increment Operation Leetcode Solution175
892Sorted Array to Balanced BST175
893Can Place Flowers LeetCode Solution175
894Convert BST to Min Heap175
895Sequences of given length where every element is more than or equal to twice of previous175
896Least Number of Unique Integers after K Removals Leetcode Solution175
897Pattern Occurrences using Stack174
898Number of Distinct Islands Leetcode Solution174
899Infix to Postfix174
900GCDs of given index ranges in an array174
901Count Negative Numbers in a Sorted Matrix LeetCode Solution174
902Level order Traversal in Spiral Form174
903Check whether a given Binary Tree is Complete or not174
904Diagonal Traverse LeetCode Solution174
905Find distance between two nodes of a Binary Tree174
906Delete And Earn174
907Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution174
908Minesweeper LeetCode Solution174
909Maximum size subarray sum equals k174
910Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i173
911Range sum queries without updates173
912Set Matrix Zeroes Leetcode Solution173
913Insert into a Binary Search Tree Leetcode Solution173
914Maximum Score After Splitting a String Leetcode Solution173
915Destination City Leetcode Solution173
916Median of Two Sorted Arrays173
917Guess Number Higher or Lower II173
918All Unique Triplets that Sum up to a Given Value173
919Shortest Word Distance Leetcode Solution173
920Robot Bounded In Circle LeetCode Solution172
921A program to check if a binary tree is BST or not172
922Binary array after M range toggle operations172
923Rearrange an Array Such that arr[i] is equal to i172
924Lexicographical Numbers Leetcode Solution172
925Check if any two intervals overlap among a given set of intervals172
926Binary Tree Longest Consecutive Sequence LeetCode Solution172
927Difference Array | Range update query in O(1)171
928Convert Sorted List to Binary Search Tree171
929Construct the Rectangle Leetcode Solution171
930Product of Array Except Self LeetCode Solution171
931Three way partitioning of an array around a given range171
932Find Common Characters Leetcode Solution171
933Count Submatrices With All Ones LeetCode Solution171
934Alien Dictionary171
935Special Positions in a Binary Matrix Leetcode Solution171
936Check if the given array can represent Level Order Traversal of Binary Search Tree171
937Averages of Levels in Binary Tree171
938My Calendar I LeetCode Solution171
939Longest Palindromic Subsequence170
940Queue using Stacks170
941Count Subarrays with Same Even and Odd Elements170
942Construct Complete Binary Tree from its Linked List Representation170
943Analyze User Website Visit Pattern LeetCode Solution170
944Trim a Binary Search Tree170
945Rearrange Spaces Between Words Leetcode Solution170
946Palindrome Partitioning Leetcode Solution170
947Three Consecutive Odds Leetcode Solution170
948K’th Largest Element in BST when modification to BST is not allowed170
949Spiral Matrix III LeetCode Solution170
9503 Sum170
951Word Break169
952Merge Two Sorted Lists Leetcode169
953Create Maximum Number169
954Intersection of Two Linked Lists LeetCode Solution169
955Remove Duplicates from Sorted List II LeetCode Solution169
956Number of Equivalent Domino Pairs Leetcode Solution169
957Maximum Frequency Stack Leetcode Solution169
958Vertical sum in a given binary tree169
959Minimum Height Trees LeetCode Solution169
960Climbing stairs168
961Symmetric Tree168
963Strongly Connected Component168
964Queries for GCD of all numbers of an array except elements in a given range168
965BFS for Disconnected Graph168
966Largest area rectangular sub-matrix with equal number of 1’s and 0’s168
967Maximize Sum of Array after K Negations Leetcode Solution168
968Sign of the Product of an Array LeetCode Solution167
969Asteroid Collision LeetCode Solution167
970Unique Paths II167
971Count Primes in Ranges167
972Depth First Search (DFS) for a Graph167
973Print Fibonacci sequence using 2 variables167
974Count subarrays where second highest lie before highest167
975Maximum Product Subarray167
976Kth Smallest Element in a BST Leetcode Solution167
977Longest subsequence such that difference between adjacents is one167
978Construct BST from its given Level Order Traversal167
979Reverse Nodes in K-Group167
980Merging Intervals166
981Longest Nice Substring LeetCode Solution166
982Breadth First Search (BFS) for a Graph166
983Count pair with Given Sum166
984Combination Sum IV LeetCode Solution166
985Design Hit Counter LeetCode Solution166
986Number of palindromic paths in a matrix166
987Serialize and Deserialize Binary Tree166
988Maximum Subarray Sum Excluding Certain Elements166
989Stone Game II Leetcode166
990Find number of pairs in an array such that their XOR is 0165
991Largest Number Leetcode Solution165
992The Maze III LeetCode Solution165
993Next Permutation Leetcode Solution165
994Valid Boomerang Leetcode Solution165
995Scramble String LeetCode Solution165
996String Matching in an Array Leetcode Solution165
997Maximum Length of Repeated Subarray165
998Binary Search Tree Delete Operation165
999Find the First Circular Tour that visits all the Petrol Pumps165
1000K maximum sums of overlapping contiguous sub-arrays165
1001Can Make Arithmetic Progression From Sequence Leetcode Solution165
1002Find Maximum of Minimum for Every Window Size in a Given Array165
1003Largest Substring Between Two Equal Characters Leetcode Solution164
1004Count pairs from two sorted arrays whose sum is equal to a given value x164
1005Remove Duplicates from Sorted Array II Leetcode Solution164
1006K Closest Points to Origin Leetcode Solution164
1007Maximum Product of Indexes of Next Greater on Left and Right164
1008Print Next Greater Number of Q queries164
1009Height of a generic tree from parent array164
1010Maximum length subsequence with difference between adjacent elements as either 0 or 1164
1011Palindrome Partitioning164
1012Find the Difference Leetcode Solution164
1013Maximum difference between frequency of two elements such that element having greater frequency is also greater164
1014Newman-Conway Sequence164
1015Segment Tree163
1016Kth Smallest Element in a Sorted Matrix LeetCode Solution163
1017Graph Valid Tree LeetCode Solution163
1018Level Order Traversal of Binary Tree163
1019Minimum Index Sum of Two Lists163
1020Generate Parentheses Leetcode Solution163
1021Consecutive Characters LeetCode Solution163
1022The Painter’s Partition Problem163
1023Balanced Binary Tree163
1024Length of Longest Fibonacci Subsequence163
1025Shuffle 2n integers as without using extra space163
1026Shortest Completing Word Leetcode Solution163
1027Move all negative elements to end in order with extra space allowed162
1028Validate Binary Search Tree162
1029Collect maximum points in a grid using two traversals162
1030Largest divisible pairs subset162
1031Find postorder traversal of BST from preorder traversal162
1032Maximum Number of Ways to Partition an Array LeetCode Solution162
1033Find Duplicate Subtrees162
1034Boolean Parenthesization Problem162
1035Merge Sort162
1036Boundary Traversal of binary tree162
1037Rearrange array such that even positioned are greater than odd162
1038Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution162
1039Friends Of Appropriate Ages LeetCode Solution162
1040Decrypt String from Alphabet to Integer Mapping Leetcode Solution162
1041Maximum Sum of 3 Non-Overlapping Subarrays162
1042Invalid Transactions LeetCode Solution162
1043Next Greater Element III LeetCode Solution161
1044Make The String Great Leetcode Solution161
1045First missing positive161
1046Build an Array With Stack Operations Leetcode Solution161
1047Available Captures for Rook Leetcode Solution161
1048Path Sum II LeetCode Solution161
1049Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’161
1050Custom Sort String Leetcode Solution161
1051Construction of Longest Increasing Subsequence (N log N)161
1052Number Of Longest Increasing Subsequence161
1053Find a Peak Element II LeetCode Solution161
1054Bitwise AND of Numbers Range LeetCode Solution160
1055Advantages of BST over Hash Table160
1056Kill Process LeetCode Solution160
1057Construct Binary Tree from given Parent Array representation160
1058Iterative Depth First Traversal of Graph160
1059Insertion in a Binary Tree160
1060Compute nCr % p160
1061Binary Search Tree160
1062Minimum Size Subarray Sum159
1063Ugly Numbers159
1064Rearrange array such that even index elements are smaller and odd index elements are greater159
1065Print Right View of a Binary Tree159
1066Recover Binary Search Tree Leetcode Solution159
1067Double the first element and move zero to end159
1068Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution159
1069Subarrays with K Different Integers Leetcode Solution159
1070Count minimum steps to get the given desired array159
1071Add two numbers159
1072Morris Inorder Traversal158
1073Remove Palindromic Subsequences Leetcode Solution158
1074Employee Importance LeetCode Solution158
1075Largest BST Subtree LeetCode Solution158
1076Find Peak Element158
1077Partition Equal Subset Sum158
1078Maximum subsequence sum such that no three are consecutive158
1079Defanging an IP Address LeetCode Solution158
1080Maximum weight transformation of a given string157
1081Level order traversal using two Queues157
1082Regular Expression Matching Regular Expression Matching LeetCode Solution157
1083Find maximum difference between nearest left and right smaller elements157
1084Smallest Common Region Leetcode Solution157
1085Implement Trie (Prefix Tree) Leetcode Solution156
1086Number of siblings of a given Node in n-ary Tree156
1087Longest Bitonic Subsequence156
1088Palindrome Permutation LeetCode Solution156
1089Cells with Odd Values in a Matrix LeetCode Solution156
1090Remove duplicates from sorted array156
1091Binary Tree Right Side View LeetCode Solution156
1092Lowest Common Ancestor156
1093Ugly Number II LeetCode Solution156
1094Super Ugly Number156
1095Find whether a subarray is in form of a mountain or not156
1096Path Sum155
1097Search in Sorted Rotated Array155
1098Maximize Distance to Closest Person LeetCode Solution155
1099Number of Closed Islands Leetcode Solution155
1100Palindromic Substrings Leetcode Solution155
1101Bus Routes Leetcode Solution155
1102Populating Next Right Pointers in Each Node Leetcode Solution155
1103Kth Smallest Product of Two Sorted Arrays LeetCode Solution155
1104Increasing Triplet Subsequence LeetCode Solution155
1105Print all triplets in sorted array that form AP155
1106Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution155
1107Valid Tic-Tac-Toe State LeetCode Solution155
1108Sum of Even Numbers After Queries154
1109Clone a Binary Tree with Random Pointers154
1110Iterative method to find ancestors of a given binary tree154
1111Divisible Pairs Counting154
1112Find Three Element From Different Three Arrays Such That a + b + c = sum154
1113Find the minimum distance between two numbers154
1114Reformat The String Leetcode Solution154
1115Products of ranges in an array154
1116Binary Tree Data Structure153
1117Number of Students Doing Homework at a Given Time Leetcode Solution153
1118Distinct Subsequences153
1119Moser-de Bruijn Sequence153
1120Day of the Year Leetcode Solution153
1121Thousand Separator Leetcode Solution153
1122Search Insert Position152
1123Bottom View of a Binary Tree152
1124Longest Subarray of 1’s After Deleting One Element LeetCode Solution152
1125Find Smallest Range Containing Elements from k Lists152
1126Count Largest Group Leetcode Solution152
1127Level of Each node in a Tree from source node152
1128Mean of Array After Removing Some Elements Leetcode Solution152
1129Serialize and Deserialize Binary Tree LeetCode Solution152
1130Root to Leaf path with target sum Leetcode Solutions152
1131Minimum Absolute Difference in BST Leetcode Solution152
1132Longest Repeated Subsequence151
1133Third Maximum Number Leetcode Solution151
1134Maximum Product Subarray151
1135Longest Increasing Consecutive Subsequence151
1136Write Code to Determine if Two Trees are Identical151
1137Reformat Date LeetCode Solution151
1138Convert BST into a Min-Heap without using array150
1139Maximum Product of Splitted Binary Tree LeetCode Solution150
1140Minimum Moves to Equal Array Elements LeetCode Solution150
1141Diameter of N-Ary Tree LeetCode Solution150
1142Queries for Number of Distinct Elements in a Subarray150
1143Construct K Palindrome Strings LeetCode Solution150
1144Prime Palindrome LeetCode Solution150
1145Minimum sum of squares of character counts in a given string after removing k characters150
1146Closest Leaf in a Binary Tree LeetCode Solution150
1147Golomb sequence150
1148Maximum Depth Of Binary Tree150
1149Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution150
1150Find maximum length Snake sequence150
1151Constant time range add operation on an array150
1152Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1153Topological Sorting150
1154Kth Smallest Number in Multiplication Table Leetcode Solution149
1155Minimum Score Triangulation of Polygon Leetcode Solution149
1156Rotate Array149
1157Search Suggestions System LeetCode Solution149
1158Contiguous Array LeetCode Solution149
1159Swap Nodes In Pairs149
1160Priority Queue149
1161Print modified array after executing the commands of addition and subtraction149
1162Search an Element in Sorted Rotated Array149
1163Web Crawler LeetCode Solution148
1164Subset Sum Problem in O(sum) space148
1165Count even length binary sequences with same sum of first and second half bits148
1166Find Largest Value in Each Tree Row LeetCode Solution148
1167Cutting a Rod148
1168Reverse a Path in BST using Queue147
1169Decision Tree147
1170Possible Bipartition LeetCode Solution147
1171Closest Binary Search Tree Value Leetcode Solution147
1172Find a sorted subsequence of size 3 in linear time147
1173Delete Nodes and Return Forest Leetcode Solution147
1174Maximize sum of consecutive differences in a circular array147
1175Check Array Formation Through Concatenation Leetcode Solution147
1176Factorial Trailing Zeroes LeetCode Solution147
1177Replace two consecutive equal values with one greater146
1178Count Pairs Whose Products Exist in Array146
1179Matchsticks to Square Leetcode Solution146
1180Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution146
1181Red-Black Tree Introduction146
1182Minimum Sideway Jumps LeetCode Solution146
1183Concatenation of Array LeetCode Solution146
1184Transform a BST to Greater sum Tree146
1185Binary Tree to Binary Search Tree Conversion146
1186Given a binary tree, how do you remove all the half nodes?146
1187Minimum Swaps To Make Sequences Increasing LeetCode Solution146
1188Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1189Maximum Binary Tree146
1190Maximum sum of a path in a Right Number Triangle145
1191Sum of Left Leaves LeetCode Solution145
1192K’th Largest element in BST using constant extra space145
1193Valid Triangle Number145
1194Decrease Elements To Make Array Zigzag LeetCode Solution145
1195First Bad Version144
1196Maximum number of segments of lengths a, b and c144
1197Find the smallest binary digit multiple of given number144
1198Maximum sum bitonic subarray144
1199Divide Two Integers Leetcode Solution144
1200Merge two BSTs with limited extra space144
1201Maximum Value at a Given Index in a Bounded Array LeetCode Solution144
1202Perfect Squares LeetCode Solution144
1203Number of Orders in the Backlog Leetcode Solution144
1204Path Crossing Leetcode Solution144
1205Queue Reconstruction by Height143
1206Print n terms of Newman-Conway Sequence143
1207Swapping Nodes in a Linked List Leetcode Solution143
1208Maximum sum of pairs with specific difference143
1209Valid Perfect Square LeetCode Solution143
1210Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution143
1211Sliding Window Median Leetcode Solution143
1212Lowest Common Ancestor of a Binary Tree Leetcode Solution143
1213Guess The Word142
1214How to print maximum number of A’s using given four keys142
1215Convert Sorted Array to Binary Search Tree LeetCode Solutions142
1216Find minimum number of merge operations to make an array palindrome142
1217Queries on Probability of Even or Odd Number in given Ranges142
1218Integer Break LeetCode Solution142
1219New 21 Game141
1220Range Sum Query using Sparse Table141
1221Moving Stones Until Consecutive Leetcode Solution141
1222Array Queries for multiply replacements and product141
1223Graph and its representation141
1224Flatten 2D Vector LeetCode Solution140
1225Check if all levels of two Binary Tree are anagrams or not140
1226Champagne Tower LeetCode Solution140
1227Kth Smallest Element in a BST140
1228Find Minimum in Rotated Sorted Array II LeetCode Solution140
1229Lowest Common Ancestor in Binary Search Tree140
1230Maximum Array from Two given Arrays Keeping Order Same139
1231LRU Cache Leetcode Solution139
1232Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution139
1233Longest Common Prefix Using Word by Word Matching139
1234Merge k Sorted Lists Leetcode Solution139
1235Largest Plus Sign Leetcode Solution138
1236Range Queries for Longest Correct Bracket Subsequence138
1237Bold Words in String LeetCode Solution138
1238BST to a Tree with Sum of all Smaller Keys138
1239Missing Number138
1240The kth Factor of n Leetcode Solution138
1241Mean of range in array138
1242Write a function to get the intersection point of two Linked Lists138
1243Contiguous Array138
1244Design Skiplist LeetCode Solution138
1245Maximum Product Subarray138
1246Maximum Sum Increasing Subsequence138
1247Maximize Elements Using Another Array138
1248Count Subsets Having Distinct Even Numbers137
1249Print modified array after multiple array range increment operations137
1250Minimum Remove to Make Valid Parentheses LeetCode Solution137
1251Find k-th smallest element in BST (Order Statistics in BST)137
1252Min Cost Climbing Stairs LeetCode Solution136
1253Parallel Courses II LeetCode Solution136
1254Arithmetic Slices II – Subsequence LeetCode Solution136
1255Different Ways to Add Parentheses Leetcode Solution135
1256Image Overlap LeetCode Solution135
1257Check in binary array the number represented by a subarray is odd or even135
1258Power of Two135
1259Graph Cloning135
1260Minimum Time to Collect All Apples in a Tree LeetCode Solution134
1261Verify Preorder Serialization of a Binary Tree134
1262Check for Identical BSTs without building the trees134
1263Check if each internal node of a BST has exactly one child134
1264Check Completeness of a Binary Tree LeetCode Solution134
1265Koko Eating Bananas LeetCode Solution134
1266Print Ancestors of a Given Binary Tree Node Without Recursion133
1267Check if two nodes are on the same path in a Tree133
1268Smallest Range II Leetcode Solution133
1269Symmetric Tree LeetCode Solution Leetcode Solution133
1270Next greater element132
1271Longest Substring Without Repeating Characters Leetcode Solution132
1272Orderly Queue LeetCode Solution132
1273Count and Toggle Queries on a Binary Array131
1274Excel Sheet Column Title LeetCode Solution131
1275Merge Sorted Array131
1276Arranging Coins Leetcode Solution130
1277Vertical Order Traversal of Binary Tree LeetCode Solution130
1278Number of elements less than or equal to a given number in a given subarray129
1279Largest Submatrix With Rearrangements LeetCode Solution129
1280Palindrome Partitioning129
1281Palindrome Number LeetCode Solution128
1282Array Nesting Leetcode Solution128
1283Peeking Iterator LeetCode Solution127
1284Find the Winner of the Circular Game LeetCode Solution126
1285Add Two Numbers II Leetcode Solution126
1286Newman–Shanks–Williams prime126
1287Maximum product of an increasing subsequence126
1288Check if X can give change to every person in the Queue126
1289Check If a String Can Break Another String Leetcode Solution126
1290Insert Delete GetRandom O(1) Leetcode Solution125
1291Queries for Decimal Values of Subarrays of a Binary Array125
1292Find maximum average subarray of k length125
1293Range Minimum Query (Square Root Decomposition and Sparse Table)125
1294Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution124
1295Continuous Subarray Sum LeetCode Solution124
1296Check given array of size n can represent BST of n levels or not123
1297Encoded String With Shortest Length LeetCode Solution123
1298Jump Game IV LeetCode Solution122
1299Reach a Number LeetCode Solution121
1300Minimum Number of People to Teach LeetCode Solution121
1301Random Pick Index LeetCode Solution121
1302Binary Tree to Binary Search Tree Conversion using STL set121
1303Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1304Convert to Base -2 LeetCode Solution121
1305Number of indexes with equal elements in given range120
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
1309Design Underground System Leetcode Solution116
1310Shifting Letters LeetCode Solution115
1311Queries on XOR of greatest odd divisor of the range115
1312Detect Capital Leetcode Solution111
1313Print Maximum Length Chain of Pairs111
1314Minimum Swaps to Group All 1’s Together Leetcode Solution110
1315Top K Frequent Elements LeetCode Solution110
1316Count Sub Islands LeetCode Solution108
1317Substring with Concatenation of All Words Leetcode Solution108
1318Minimum Path Sum Leetcode Solution108
1319Odd Even Linked List Leetcode Solution107
1320Monotonic Array Leetcode Solution106
1321Decode String Leetcode Solution103
1322Longest Common Subsequence LeetCode Solution103
1323Maximum Population Year LeetCode Solution103
1324Find the Town Judge LeetCode Solution102
1325Binary Tree Inorder Traversal LeetCode Solution102
1326Shortest Unsorted Continuous Subarray LeetCode Solution98
1327Rectangle Overlap LeetCode Solution96
1328Best Meeting Point LeetCode Solution96
1329Sum Root to Leaf Numbers LeetCode Solution93
1330Maximum Population Year LeetCode Solution93
1331Find the Town Judge LeetCode Solution92
1332Insert into a Sorted Circular Linked List LeetCode Solution92
1333Design Add and Search Words Data Structure LeetCode Solution92
1334Flatten Binary Tree to Linked List LeetCode Solution92
1335Stone Game IV LeetCode Solution90
1336Is Graph Bipartite? LeetCode Solution88
1337Valid Triangle Number LeetCode Solution88
1338Range Sum Query 2D – Immutable LeetCode Solution88
1339Reveal Cards In Increasing Order Leetcode Solution88
1340Score of Parenthesis LeetCode Solution87
1341Divide Chocolate LeetCode Solution82
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution70
1344Reverse Integer Leetcode Solution69
1345Rotate String LeetCode Solution66
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 Solution62
1349Excel Sheet Column Number LeetCode Solution60
1350Maximum Size Subarray Sum Equals k Leetcode Solution51
1351H-Index Leetcode Solution47
1352Camelcase Matching Leetcode Solution45
1353Valid Anagram Leetcode Solution45
1354Most Stones Removed with Same Row or Column LeetCode Solution44
1355Container With Most Water LeetCode Solution43
1356Sliding Window Maximum LeetCode Solution43
1357High Five LeetCode Solution43
1358Group Anagrams LeetCode Solution42
1359Next Permutation LeetCode Solution41
1360Find Peak Element LeetCode Solution41
1361Binary Search LeetCode Solution40
1362Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution40
1363Paint House LeetCode Solution39
1364Minimum Number of Arrows to Burst Balloons LeetCode Solution36
1365Sentence Screen Fitting LeetCode Solution36
1366Valid Triangle Number LeetCode Solution36
1367Flatten Binary Tree to Linked List LeetCode Solution36
1368Unique Binary Search Trees LeetCode Solution35
1369Next Greater Element I Leetcode Solution35
1370Group Shifted Strings Leetcode Solution35
1371Isomorphic Strings LeetCode Solution35
1372The Number of Weak Characters in the Game LeetCode Solution35
1373Split Linked List in Parts Leetcode Solution35
1374Count Good Nodes in Binary Tree LeetCode Solution34
1375Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution33
1376Peak Index in a Mountain Array LeetCode Solution33
1377Swim in Rising Water LeetCode Solution32
1378Best Time to Buy and Sell Stock IV LeetCode Solution31
1379Single Element in a Sorted Array LeetCode Solution31
1380Closest Binary Search Tree Value II LeetCode Solution31
1381Find First and Last Position of Element in Sorted Array LeetCode Solution29
1382Max Sum of Two Non-Overlapping Subarrays LeetCode Solution29
1383Minimum Increment to Make Array Unique Leetcode Solution29
1384All Possible Full Binary Trees LeetCode Solution28
1385Lowest Common Ancestor of a Binary Search Tree Leetcode Solution27
1386Validate Stack Sequences LeetCode Solution27
1387Detect Squares LeetCode Solution26
1388Break a Palindrome LeetCode Solution25
1389Implement Rand10() Using Rand7() Leetcode Solution25
1390Trapping Rain Water II LeetCode Solution25
1391Implement strStr() LeetCode Solution25
1392Greatest Sum Divisible by Three LeetCode Solution24
1393Stone Game IV LeetCode Solution24
1394Reverse Nodes in k-Group LeetCode Solution23
1395Invert Binary Tree LeetCode Solution23
1396Contains Duplicate LeetCode Solution23
1397Remove All Ones With Row and Column Flips Leetcode Solution22
1398Fibonacci Number LeetCode Solution21
1399Design Bounded Blocking Queue LeetCode Solution21
1400Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution20
1401Total Hamming Distance LeetCode Solution19
1402Candy LeetCode Solution18
1403Unique Paths III LeetCode Solution14
Translate »