Total Hamming Distance LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon Facebook
Bit ManipulationViews 16

Problem Statement:

Total Hamming Distance LeetCode Solution:

Given an integer array nums, return the sum of Hamming distances between all the pairs of the integers in nums.

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Example 1:


 nums = [4,14,2]




In binary representation, the 4 is 0100, 14 is 1110, and 2 is 0010 (just
showing the four bits relevant in this case).
The answer will be:
HammingDistance(4, 14) + HammingDistance(4, 2) + HammingDistance(14, 2) = 2 + 2 + 2 = 6.

Example 2:


 nums = [4,14,4]




  • 1 <= nums.length <= 104
  • 0 <= nums[i] <= 109
  • The answer for the given input will fit in a 32-bit integer.



  1. The first solution that comes to our mind is to brute-force iterate through each pair, then sum all Integer.bitCount(x ^ y) .So This complexity O(N*N) gives TLE.
  2. Now, look into the efficient manner. The total Hamming distance is constructed bit by bit in this approach.
  3. For each bit position 1-32 in a 32-bit integer belonging to the array, we count the number of integers in the array which have that bit set.
  4. Then, if there are n integers in the array and k of them have a particular bit set and (n-k) do not, then that bit contributes n* (n-k) to the hamming distance.
  5. Because for each of the ‘k’ numbers, we have 1 of the (n-k) numbers, that have a different bit and the number of ways to select 1 from k and (n-k) numbers is kC1nkC1=k(nk).
  6. For every bit, we will calculate how many are sets and how many are not sets. We will simply multiply both values for every bit position 1-32.
  7. To check whether the bit is set or not we can use left shift or right shift bit manipulation.
  8.  Look into the below code for a better understanding.


Total Hamming Distance LeetCode C++ Solution

class Solution {
    #define ll int
    int totalHammingDistance(vector<int>& nums) {
        ll i,j,n=nums.size();
        ll cnt=0;
            int one=0,zero=0;
        return cnt;

Total Hamming Distance LeetCode Java Solution

class Solution {
    public int totalHammingDistance(int[] nums) {
         int i,j,n=nums.length;
        int cnt=0;
            int one=0,zero=0;
        return cnt;

Complexity Analysis for Total Hamming Distance LeetCode Solution

Time Complexity

Time complexity is O(N*32) or simply say O(N). Where N is the size of the input array.

Space Complexity

Space complexity is O(1) as we not taking any extra space.

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 characters2524
4Palindrome using Recursion2489
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 number1688
9Sort Elements by Frequency of Occurrences1672
10Write a program to print all permutations of a given string1655
11Find Minimum Distance Between Two Numbers in an Array1518
12Create a Doubly Linked List1484
13Reverse an Array1464
14Smallest window in a string containing all characters of another string1437
15Recursively remove all adjacent duplicates1406
16Find a Triplet That Sum to a Given Value1391
17First Repeating Element1386
18Sum of numbers in String1362
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 List1257
25Subarray with Given Sum1247
26Print all Possible Combinations of R Elements in a given Array of size N1247
27Recursive function to do substring search1246
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 second1114
34Find Leaders in an Array1092
35Swap nodes in the linked list1085
36Find the second most frequent character1034
37Find the Number Occurring Odd Number of Times in an Array1033
38Arrange given Numbers to Form the Biggest Number II1027
39Given a string find its first non-repeating character1014
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 x994
42Total number of occurrences of a given item in the linked list991
43A Program to check if strings are rotations of each other or not989
44Print all possible words from phone digits972
45Find the Missing Number963
46Rearrange Positive and Negative Numbers Alternatively in Array950
47Longest Palindromic Substring944
48Segregate even and odd nodes in a linked list934
49Print Longest common subsequence925
50Transform one string to another using minimum number of given operations913
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome895
53Rearrange given Array in Maximum Minimum Form876
54Iterative Implementation of Quick Sort868
55Insertion Sort858
56Count Possible Triangles856
57Multiplication of Two Matrices840
58Count of Triplets With Sum Less than Given Value830
59Stock Buy Sell to Maximize Profit827
60Check if the linked list is palindrome827
61Rotate a Linked List826
62Concatenation of two strings805
63Tug of War798
64Print all duplicates in the input string796
65Count Number of Substrings with K Distinct Character’s794
66Find Nearest Greater and Smaller Element782
67Reverse String Without Temporary Variable777
68The Celebrity Problem771
69Remove ‘b’ and ‘ac’ from a given string770
70Find Pythagorean Triplets from Array768
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’s737
74Find the subarray whose sum is equal to a given number X736
75Find the Peak Element from an Array735
76Remove Minimum Characters so that Two Strings Become Anagrams735
77Addition of Two Matrices729
78Find Smallest Missing Number in a Sorted Array725
79Generate all Binary Strings Without Consecutive 1’s724
80A Product Array Puzzle722
81Maximum Sum of Non Consecutive Elements710
82Implement Two Stacks in an Array707
83Lexicographic rank of string697
84Check if Two given Matrices are Identical690
85Maximum Product Subarray II686
86Multiplication of Previous and Next681
87Subtraction of Two Matrices674
88Merge K Sorted Arrays and Print Sorted Output668
89Move All the Zeros to the End of the Given Array666
90Divide a string in N equal parts665
91Form Minimum Number from Given Sequence of D’s and I’s664
92Online Algorithm for Checking Palindrome in a Stream664
93Remove recurring digits in a given number656
94Check whether two strings are anagram of each other656
95Sort a stack using a temporary stack651
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 place633
101First Circular Tour to Visit all the Petrol Bunks633
102Compare two strings(linked lists)628
1033Sum Leetcode Solution628
104Maximum Element in an Array which is Increasing and then Decreasing627
105Largest Subarray with Equal Number of 0’s and 1’s626
106Palindrome Permutations of a String626
107Flattening a linked list623
108Palindromes in a given range621
109Majority Element618
110Minimum insertions to form a shortest palindrome617
111Pangram Checking616
112Run length encoding615
113Print all permutations with repetition614
114Elements Appear more than N/K times in Array611
115Minimum Characters to be Added at Front to Make String Palindrome608
116Most repeating character in a string605
117Two Sum Leetcode Solution602
118Rotate string to get lexicographically minimum string601
119Repeated Subsequence of Length Two or More598
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 words591
125Reorder an Array According to the Given Indexes580
126Pancake Sorting Problem578
127Merge Overlapping Intervals II568
128Clone a Linked List with next and random pointer566
129Remove duplicates from a string565
130Smallest Palindrome after Replacement565
131Transpose of a Matrix565
132Longest Palindrome can be Formed by Removing or Rearranging Characters565
133Remove Extra Spaces from a String563
134Removing Spaces from a String using stringstream560
135Maximum Sum Increasing Subsequence559
136Size of The Subarray With Maximum Sum558
137Check if a given string is a rotation of a palindrome558
138Partition Problem552
139Generate all Binary Strings from Given Pattern546
140Check whether Strings are K Distance Apart or Not545
141Length of Longest valid Substring541
142Delete Last Occurrence538
143Check if Two given Strings are Isomorphic to each other537
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized535
145Insert Node in the Sorted Linked List532
146Program to Toggle all Characters in a String527
147Maximum difference between two elements such as larger element comes after smaller525
148Given string is interleaving of two other strings or not525
149Check length of a String is Equal to the Number Appended at its Last515
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 Other507
153Longest Common Prefix using Divide and Conquer506
154Find Pair with Given Difference506
155Merge sort better than quick sort for linked lists505
156Compare Two Version Numbers501
157Find nth node of the Linked list from the end497
158Print all interleavings of given two strings496
159Median of Two Sorted Arrays LeetCode Solution495
160Print Reverse of a string (Recursion)495
161Find a Fixed Point in a Given Array494
162Sort 0s 1s and 2s in an Array493
163Reorder Array Using Given Indexes493
164Reverse words in a given string491
165Find the Subarray of given length with Least Average485
166Merge two sorted linked lists such that merged list is in reverse order484
167Split linked list using alternate nodes483
168Print all Palindromic Partitions of a String475
169Print string of odd length in ‘X’ format472
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average466
172Swap Kth Node from beginning with Kth Node from End463
173Find Duplicates in an Array in Most Efficient Way459
174Shortest Superstring Problem455
175print all palindromic partitions454
176Check if String Follows Order of Characters by a Pattern or not450
177Maximum Length of Chain Pairs448
178Sort a String According to Another String446
179Flatten a multilevel linked list445
180Sorting a K Sorted Array440
181Program to add two binary digits433
182Find a Sorted Subsequence of size 3428
183Recursively print all the sentences that can be formed from list of word lists428
184Caesar Cipher426
185Longest Span with same Sum in two Binary Arrays II426
186Reverse a Linked List in groups426
187Longest Common Prefix Using Binary Search II425
188Find the two Numbers with Odd Occurrences in an Unsorted Array425
189Kth Non-repeating Character421
190Reverse a Singly Linked List (Iterative/Non-Recursive)420
191Check if String can Become Empty by Recursively Deleting given Substring416
192Longest Common Prefix Word by Word Matching412
193Rearrange a linked list in Zig-Zag410
194Permutations of a Given String Using STL407
195Rotate Image by 90 degrees406
196Pancake Sorting404
197Perfect Reversible String404
198Merging Two Sorted Arrays401
199Find First non-repeating character in a string400
2001`s and 2`s complement of binary number398
201Increasing Subsequence of Length three with Maximum Product394
202List items containing all characters of a given word394
203Find the point where a monotonically increasing function becomes positive first time393
204Maximum occurring character in a string393
205Four Elements that Sum to Given390
206Sort a linked list with 0s, 1s and 2s389
207Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes387
208Longest Common Prefix using Character by Character Matching385
209Count Number of Occurrences in a Sorted Array383
210Palindrome string (number)382
211Valid Parentheses LeetCode Solution380
212Delete N nodes after M379
213Minimum Characters to be Removed to Make a Binary String Alternate377
214Even Substring Count375
215Split a string374
216Recursive Implementation of atoi()371
217Sorting the array of strings371
218Convert a String that is Repetition of a Substring of Length K369
219Check if a Linked list of Strings form a Palindrome367
220Print Shortest Path to Print a String on Screen366
221Maximum Subarray Leetcode Solution363
222Print All Distinct Elements of the Array360
223Convert string1 to string2 in one edit359
224Reverse a String using Stack359
225Nth Character in Concatenated Decimal String358
226Count the number of words358
227Matrix Chain Multiplication using Dynamic Programming358
228Find the first Repeating Number in a Given Array358
229wildcard character matching357
230Reverse a singly linked list recursively357
231Lower Case To Upper Case353
232Can we reverse a linked list in less than O(n) time ?351
233Binary Tree to Doubly linked list349
234Sort Elements by Frequency II345
235Longest Common Subsequence with Permutations344
236Find the Lost Element From a Duplicated Array344
237Merge Two Sorted Arrays341
238Split Four Distinct Strings340
239Find middle of the Linked List337
240Count the Pairs at Same Distance as in English Alphabets335
241Roman to Integer Leetcode Solution335
242Toeplitz Matrix330
243Palindrome Permutation328
244Next Greater Element in an Array325
245Word Search Leetcode Solution325
246Move all negative elements to one side of array323
247N queen problem322
248Searching a node in a Binary Search Tree317
249Find All Pairs With a Given Difference317
250Sudoku Solver315
251Find Nth Node315
252Reverse Bits314
253First non Repeating Element314
254Print all Possible Ways to Break a String in Bracket Form314
255Count Pairs With Given Sum313
256Number of Islands LeetCode Solution313
257String(represents an integer) to value313
258Reverse a String312
259Triplet from three linked lists with given sum311
260Types of Binary Tree311
261Delete a Tree311
262Change Gender of a given String311
263Repeated Substring Pattern310
264Meeting Rooms II LeetCode Solution308
265Sort an array of strings308
266How to Efficiently Implement k Stacks in a Single Array?308
267Reverse a linked list308
268Fibonacci numbers307
269Delete a node under given conditions307
270Number of sub-strings which recursively add up to 9306
271Min Stack305
272Most Frequent Element in an Array304
273Longest Palindromic Substring LeetCode Solution304
274Cuckoo sequence program302
275Dijkstra Algorithm302
276Longest Common Extension300
277Binary Tree298
278Remove spaces from a string296
279House Robber Leetcode Solution296
280Max stack295
281Best Time to Buy and Sell Stock  II Leetcode Solution293
282Subset Leetcode293
283Word Search290
284Shuffle a given Array289
285KMP Algorithm288
286Remove middle points in a linked list of line segments288
287Expression Evaluation287
288Find, second, frequent, character287
289Minimize the maximum difference between the heights287
290Plus One Leetcode Solution287
291Combination Sum Leetcode Solution285
292Search Insert Position Leetcode Solution284
293Number Of 1 bits282
294Reverse words in a string282
295Evaluation of Postfix Expression281
296Pair of Positive Negative Values in an Array281
297Set Matrix Zeroes279
298Sliding Window Technique279
299Min Stack Leetcode Solution277
300Subarray with 0 sum277
301Valid Palindrome Leetcode Solution276
302Rabin Karp Algorithm276
303Backspace String Compare275
304Sort linked which is sorted on absolute values273
305Common elements in all rows of a given matrix273
306Merge Sorted Arrays Leetcode Solution272
307Clone a linked list with next and random pointer (Hashing)272
308Sqrt(x) Leetcode Solution270
309Delete middle element of a stack269
310Reversing a Queue269
311Implementation of Deque using Doubly Linked List266
312Contains Duplicate II Leetcode Solution265
313String Compression264
314Count of index pairs with equal elements in an array264
315Intersection of Two Arrays II Leetcode Solution264
316Product of array except self264
317Contains Duplicate263
318Tower Of Hanoi263
319Combination Sum263
320Count subarrays with equal number of 1’s and 0’s263
321Find Top K (or Most Frequent) Numbers in a Stream263
322Count Odd Numbers in an Interval Range Leetcode Solution262
323Pascal Triangle Leetcode262
324Reverse individual words262
325Page Replacement Algorithms in Operating Systems261
326How to Delete a Linked List261
327Minimum swaps required to bring all elements less than or equal to k together260
328Integer to Roman Leetcode Solution259
329Group Words With Same Set of Characters258
330Single Number Leetcode Solution258
331Segregate even and odd numbers258
332Second Most Repeated Word in a Sequence257
333Bellman Ford Algorithm257
334Sum of minimum and maximum elements of all subarrays of size k257
335Postfix to Infix Conversion257
336Sorting array using Stacks256
337Find sum of non-repeating elements (distinct) elements in an array256
338Smallest Subarray with k Distinct Numbers255
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution255
340Add Binary Leetcode Solution255
341Arithmetic Expression Evaluation255
342Sort elements by frequency255
343Top K Frequent Words254
344K-th Smallest Element in a Sorted Matrix254
345Next Permutation253
346Construct Binary Tree from Given Inorder and Preorder Traversals252
347Minimum operation to make all elements equal in array252
348Maximum Number of Balloons Leetcode Solution252
349Pow(x, n) Leetcode Solution251
350Count subarrays having total distinct elements same as original array251
351Palindrome Linked List Leetcode Solution250
352Given two unsorted arrays find all pairs whose sum is x250
353Longest Substring Without Repeating Characters LeetCode Solution250
354Longest Common Prefix Leetcode Solution250
355Convex Hull Algorithm250
356First element occurring k times in an array250
357Scramble String249
358Special Number249
359Design a stack that supports getMin() in O(1) time and O(1) extra space249
360Majority Element Leetcode Solution249
361Permutations Leetcode Solution248
362Kruskal Algorithm248
363Find Lucky Integer in an Array Leetcode Solution248
364Find duplicates in a given array when elements are not limited to a range247
365Third Maximum Number Leetcode Solution246
366Evaluate Division246
367Reversing the First K elements of a Queue243
368Running Sum of 1d Array Leetcode Solution243
369Check if two arrays are equal or not243
370Spiral Matrix LeetCode Solution243
371Reverse a Number Using Stack243
372Prefix to Infix Conversion243
373Fizz Buzz Leetcode243
374Maximum possible difference of two subsets of an array243
375Number of Good Pairs Leetcode Solution242
376Maximum Subarray242
377Minimum Path Sum242
378Find Numbers with Even Number of Digits Leetcode Solution241
379Huffman Coding241
380Unique Paths241
381Find the Town Judge Leetcode Solution240
382Count Primes Leetcode Solutions240
383Range Sum Query 2D – Immutable Leetcode Solution240
384Swap Nodes in Pairs Leetcode Solutions240
385Maximal Square240
386Group Anagrams239
387Minimum Steps to reach target by a Knight239
388Find the Closest Palindrome number238
389Single Number238
390Minimum Absolute Difference Leetcode Solution238
391Sort Array by Increasing Frequency Leetcode Solution238
392Maximum Distance Between two Occurrences of Same Element in Array238
393Smallest Element Repeated Exactly K Times237
394Find the first repeating element in an array of integers237
395Sorting using trivial hash function237
396Find top three repeated in array237
397Zigzag Conversion237
398Find All Numbers Disappeared in an Array Leetcode Solution236
399Remove Minimum Number of Elements Such That no Common Element Exist in both Array236
400Pascal’s Triangle II Leetcode Solution236
401Find Number of Employees Under every Employee236
402Palindrome Substring Queries236
403Cumulative Frequency of Count of Each Element in an Unsorted Array236
404Implement Stack and Queue using Deque236
405Merge Two Sorted Lists Leetcode Solutions235
406Power of Two Leetcode Solution235
407Leetcode Permutations235
408Convert String To Int235
409Count Substrings with equal number of 0s, 1s and 2s234
410Sort Integers by The Number of 1 Bit Leetcode Solution234
411Matrix Diagonal Sum Leetcode Solution234
412Check if Array Contains Contiguous Integers With Duplicates Allowed234
413Print All Distinct Elements of a Given Integer Array233
414Letter Case Permutation233
415Difference between highest and least frequencies in an array233
416House Robber II Leetcode Solution233
417Print all subarrays with 0 sum233
418Missing Number Leetcode Solution233
419Expression Contains Redundant Bracket or Not233
420Subarray Sum Equals k233
421Decode String233
422How to Implement Stack Using Priority Queue or Heap?233
423Bipartite Graph232
424Prim’s Algorithm232
425Length of the largest subarray with contiguous elements232
426Happy Number Leetcode Solution232
427Fizz Buzz232
428LRU Cache Implementation231
429Top K Frequent Elements231
430Sort a stack using recursion231
431Unique Paths Leetcode Solution231
432Subset sum problem231
433Maximum Depth of Binary Tree Leetcode Solution231
434Find all pairs (a, b) in an array such that a % b = k230
435Count pairs from two linked lists whose sum is equal to a given value230
436Subarrays with distinct elements230
437Search in Rotated Sorted Array Leetcode Solution230
438Find Median from data Stream230
439Find Winner on a Tic Tac Toe Game Leetcode Solution230
440Reverse Integer229
441Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution229
442Check If N and Its Double Exist Leetcode Solution228
443Reverse a Stack Using Recursion228
444Monotonic Array LeetCode Solution228
445Coin Change 2 Leetcode Solution228
446Max Consecutive Ones Leetcode Solution228
447Find the Difference Leetcode Solution228
448Capacity To Ship Packages Within D Days Leetcode Solution227
449Find elements which are present in first array and not in second227
450Find The Duplicate Number227
451Nth Catalan Number227
452Pair with given product226
453Text Justification LeetCode Solution226
454Subarray Sum Equals K LeetCode Solution226
455How Many Numbers Are Smaller Than the Current Number Leetcode Solution226
456Trapping Rain Water Leetcode Solution225
457Sum of Subarray Ranges Leetcode Solution225
458Find distinct elements common to all rows of a matrix225
459Integer to English words225
460Best Time to Buy and Sell Stock III Leetcode Solution224
461Edit Distance224
462Priority Queue Using Singly Linked List224
463Fibonacci Number LeetCode Solution224
464Find Minimum In Rotated Sorted Array224
465Reverse Vowels of a String Leetcode Solution224
466Remove Duplicates from Sorted Array Leetcode Solution224
467Count and Say224
468Floyd Warshall Algorithm224
469Kth largest element in an Array Leetcode Solutions223
470Find Index of Closing Bracket for a Given Opening Bracket in an Expression223
471Valid Parenthesis String223
472Subtract the Product and Sum of Digits of an Integer Leetcode Solution223
473Target Sum223
474Find four elements that sum to a given value (Hashmap)222
475Design Parking System Leetcode Solution222
476Longest subarray not having more than K distinct elements222
477Reverse a String222
478Find any one of the multiple repeating elements in read only array222
479Longest Common Prefix using Trie221
480Jump Game Leetcode Solution221
481Generate a String With Characters That Have Odd Counts Leetcode Solution221
482The K Weakest Rows in a Matrix Leetcode Solution221
483Delete a Node from linked list without head pointer221
484Shuffle the Array Leetcode Solution220
485Check if a given array contains duplicate elements within k distance from each other220
486MiniMax Algorithm220
487Word Ladder LeetCode Solution220
488Prefix to Postfix Conversion220
489Rearrange a binary string as alternate x and y occurrences220
490Shuffle String Leetcode Solution220
491Sorting a Queue without Extra Space220
492Find Common Characters Leetcode Solution220
493The Stock Span Problem219
494Intersection of Two Arrays219
495Flood Fill LeetCode219
496Count number of triplets with product equal to given number219
497Degree of an array218
498Multiply Strings Leetcode Solution218
499Find subarray with given sum (Handles Negative Numbers)218
500Find missing elements of a range218
501Merge Two Sorted Linked Lists218
502Balanced Binary Tree Leetcode Solution218
503Top View of Binary Tree218
504Best Time to Buy and Sell Stock LeetCode Solution218
505Shortest Palindrome217
506Excel Sheet Column Number Leetcode Solution217
507Substring With Concatenation Of All Words217
508Next Greater Element I Leetcode Solution217
509Iterative Tower of Hanoi217
510Slowest Key Leetcode Solution216
511Priority Queue in C++216
512Peak Index in a Mountain Array216
513Concatenation of Array LeetCode Solution216
514Count and Say Leetcode Solution216
515Move Zeroes LeetCode Solution216
516Longest Common Subsequence216
517Postfix to Prefix Conversion216
518Longest Common Prefix using Sorting216
519Iterative Inorder Traversal of a Binary Tree216
520Kids With the Greatest Number of Candies Leetcode Solution216
521Reverse Words in a String III LeetCode Solution216
522Find the Duplicate Element216
523Number of Steps to Reduce a Number to Zero Leetcode Solution216
524K-th Distinct Element in an Array215
525Check for Balanced Parentheses in an Expression215
526Valid Sudoku215
527Sum of Left Leaves Leetcode Solutions215
528Max Area of Island215
529Implement Stack using Queues215
531Arrange given numbers to form the biggest number214
532Convert array into Zig-Zag fashion214
533Linked List Cycle II LeetCode Solution214
534Container with Most Water214
535Minimum Knight Moves LeetCode Solution214
536Minimum Moves to Equal Array Elements Leetcode Solution214
537Find First and Last Position of Element in Sorted Array Leetcode Solution213
538Kth Largest Element in a Stream Leetcode Solution213
539Merge Overlapping Intervals213
540Hamming Distance213
541Find Sum of all unique sub-array sum for a given array213
542Implement a stack using single queue213
543Excel Sheet Column Title Leetcode Solution212
544Is Subsequence Leetcode Solution212
545Largest Sum Contiguous Subarray212
546Minimum Delete Operations to make all Elements of Array Same212
547Largest Perimeter Triangle Leetcode Solution212
548Jewels and Stones Leetcode Solution212
549Next Greater Frequency Element212
550Zigzag Conversion LeetCode Solution211
551Gold Mine Problem211
552How to check if two given sets are disjoint?211
553Smallest Subarray With all Occurrences of a Most Frequent Element211
554Group Multiple Occurrence of Array Elements Ordered by first Occurrence211
555Find N Unique Integers Sum up to Zero Leetcode Solution211
556Isomorphic Strings Leetcode Solution211
557Check if a queue can be sorted into another queue using a stack211
558Last Stone Weight210
559Contiguous Array Leetcode210
560Change the Array into Permutation of Numbers From 1 to N210
561Delete Node in a Linked List Leetcode Solution210
562Find if an Expression has Duplicate Parenthesis or Not209
563Shuffle an Array209
564Convert a normal BST to Balanced BST209
565Minimum Bracket Reversals209
566N-th Tribonacci Number Leetcode Solution209
567Koko Eating Bananas Leetcode Solution209
568Maximum sum rectangle in a 2D matrix209
569Summary Ranges Leetcode Solution208
570Minimum number of subsets with distinct elements208
571Mobile Numeric Keypad Problem208
572Best Time to Buy and Sell Stock208
5733Sum Closest LeetCode Solution208
574Minimum Cost to Hire K Workers208
575Valid Anagrams208
576Length of Last Word Leetcode Solution208
577Distribute Candies to People Leetcode Solution208
578Count the number of nodes at given level in a tree using BFS208
579Find Words That Can Be Formed by Characters Leetcode Solution207
580Shortest Path in a Grid with Obstacles Elimination LeetCode Solution207
581Maximum Distance in Array207
582Implementation of Deque using circular array207
583Decode Ways207
584Number of Provinces Leetcode Solution207
585Build Array From Permutation Leetcode Solution206
586Frog Jump Leetcode Solution206
587Longest Increasing Subsequence206
588Relative Sort Array Leetcode Solution206
589Maximum path sum in a triangle206
590Trapping Rain Water LeetCode Solution206
591Smallest Good Base206
592Integer to Roman205
59301 Matrix LeetCode Solution205
594Rotate Image LeetCode Solution205
595Maximum difference between first and last indexes of an element in array205
596Sort Characters By Frequency LeetCode Solution205
597First negative integer in every window of size k205
598Remove All Occurrences of a Substring LeetCode Solution205
599LRU Cache LeetCode Solution205
600Combinations Leetcode Solution205
601Maximum Number of Occurrences of a Substring Leetcode Solution205
602Remove Linked List Elements Leetcode Solution204
603Minimum Operations to convert X to Y204
604Island Perimeter Leetcode Solution204
605Iterative Method to find Height of Binary Tree204
606Delete consecutive same words in a sequence204
607Assign Cookies Leetcode Solution204
608Non-overlapping sum of two sets204
609XOR Operation in an Array Leetcode Solution204
610Word Pattern203
611Sieve of Eratosthenes203
612Minimum number of distinct elements after removing m items203
613Find the smallest positive integer value that cannot be represented as sum of any subset of a given array203
614Count all subsequences having product less than K203
615Find minimum difference between any two elements202
616Minimum insertions to form a palindrome with permutations allowed202
617The Knapsack Problem202
618GCD Of Two Numbers202
619Maximum Number of Chocolates to be Distributed Equally Among k Students201
620Rotate List Leetcode Solution201
621Insert Interval Leetcode Solution201
622Stone Game LeetCode201
623Reverse a stack without using extra space in O(n)201
624Convert Sorted Array to Binary Search Tree Leetcode Solution201
625Bubble sort using two Stacks201
626Permutation in String Leetcode Solution201
627Defanging an IP Address Leetcode Solution200
628Applications of Breadth First Search and Depth First Search200
629Unique Binary Search Trees200
630Find Largest d in Array such that a + b + c = d200
631Tracking current Maximum Element in a Stack200
632Same Tree LeetCode Solution200
633Sum of f(a[i], a[j]) over all pairs in an array of n integers200
634Distance Between Bus Stops Leetcode Solution199
635Isomorphic Strings199
636Count Good Nodes in Binary Tree Leetcode Solution199
637K Empty Slots199
638Reorganize String199
639Longest Increasing Path in a Matrix LeetCode Solution199
640Find the Duplicate Number LeetCode Solution199
641Convert an array to reduced form198
642Form minimum number from given sequence198
643First Unique Character in a String LeetCode Solution198
644License Key Formatting Leetcode Solution198
645How to Create Mergable Stack?198
646Optimal Account Balancing LeetCode Solution198
647Printing brackets in Matrix Chain Multiplication Problem198
648Employee Free Time LeetCode Solution198
649Word Wrap Problem197
650Letter Combinations of a Phone Number197
651Painting Fence Algorithm197
652Longest Substring with At Most K Distinct Characters LeetCode Solution197
653Find pairs with given sum such that elements of pair are in different rows197
654Minimum Depth of Binary Tree Leetcode Solution197
655Reducing Dishes LeetCode Solution196
656Find Pair with Greatest Product in Array196
657Replace Elements with Greatest Element on Right Side Leetcode Solution196
658Coin Change Problem196
659Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
660Merge Two Balanced Binary Search Trees196
661Convert a Number to Hexadecimal Leetcode Solution196
662House Robber196
663Sort Array By Parity LeetCode Solution196
664Check If It Is a Straight Line Leetcode Solution195
665Strobogrammatic Number LeetCode Solution195
666K Empty Slots LeetCode195
667Maximum Consecutive Numbers Present in an Array195
668Segregate 0s and 1s in an Array195
669Moving Average from Data Stream Leetcode Solution195
670Robot Room Cleaner Leetcode Solution195
671Kth Missing Positive Number Leetcode Solution194
672Find the node with minimum value in a Binary Search Tree194
673Partition Labels LeetCode Solution194
674Largest subarray with equal number of 0s and 1s194
675Longest Span with same Sum in two Binary arrays194
676Queries for counts of array elements with values in given range194
677Print the Fibonacci numbers in reverse order194
678Longest Substring with At Least K Repeating Characters LeetCode Solution193
679Find Maximum Level sum in Binary Tree193
680String to Integer (atoi) LeetCode Solution193
681Partition Array Into Three Parts With Equal Sum Leetcode Solution193
682Sum of All Odd Length Subarrays Leetcode Solution193
683Valid Palindrome II Leetcode Solution193
684Distance of nearest cell having 1 in a binary matrix193
685Flipping an Image LeetCode Solution193
686Maximum Product of Two Elements in an Array Leetcode Solution193
687Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
688Reservoir Sampling193
689String Compression LeetCode Solution193
690Power of Four Leetcode Solution192
691Check If Two String Arrays are Equivalent Leetcode Solution192
692Valid Palindrome192
693Dynamic Programming Basics192
694Find the Distance Value Between Two Arrays Leetcode Solution192
695Generate all possible sorted arrays from alternate elements of two given sorted arrays192
696Numbers with prime frequencies greater than or equal to k191
697Find unique character in a string191
698Remove Invalid Parentheses Leetcode Solution191
699Binary Tree Maximum Path Sum LeetCode Solution191
700Find the Smallest Divisor given a Threshold Leetcode Solution191
701Path With Maximum Minimum Value LeetCode Solution191
702Reverse Only Letters LeetCode Solution191
703Find Leaves of Binary Tree LeetCode Solution191
704Increasing Decreasing String Leetcode Solution191
705Unique Paths II Leetcode Solution190
706Number of Dice Rolls With Target Sum LeetCode Solution190
707Delete Nth node from the end of the given linked list190
708To Lower Case Leetcode Solution190
709Find the largest multiple of 3190
710Inorder Successor of a node in Binary Tree190
711Wiggle Sort190
712Lucky Numbers in a Matrix Leetcode Solution189
713Stack Permutations (Check if an array is stack permutation of other)189
714Bulb Switcher LeetCode Solution189
715Factorial Trailing Zeroes Leetcode Solution189
716Non-decreasing Array LeetCode Solution189
717Sort Array by Increasing Frequency Leetcode Solution189
718Find whether an array is subset of another array189
719Subset Sum Leetcode189
720k-th missing element in increasing sequence which is not present in a given sequence189
721Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest189
722Maximum Number of Coins You Can Get Leetcode Solution189
723Recover Binary Search Tree189
724Remove brackets from an algebraic string containing + and – operators189
725Edit Distance LeetCode Solution189
726Merge Two Binary Trees LeetCode Solution189
727BFS vs DFS for Binary Tree189
728Reversing a Queue using Recursion188
729Race Car LeetCode Solution188
730Valid Perfect Square Leetcode Solution188
731Find if Path Exists in Graph Leetcode Solution188
732Maximum Length of a Concatenated String with Unique Characters Leetcode Solution188
733Permutation Sequence LeetCode Solution188
734Populating Next Right Pointers in Each Node188
735Snakes and Ladders LeetCode Solution188
736Merge Sorted Array LeetCode Solution188
737Count quadruples from four sorted arrays whose sum is equal to a given value x188
738Perform String Shifts Leetcode188
739Binary Tree Zigzag Level Order Traversal LeetCode Solution187
740Maximum 69 Number Leetcode Solution187
741Student Attendance Record I Leetcode Solution187
742Find Maximum Depth of Nested Parenthesis in a String187
743Keyboard Row Leetcode Solution187
744Majority Element II Leetcode Solution187
745Tiling Problem187
746Ugly Number Leetcode Solution187
747Evaluate Reverse Polish Notation LeetCode Solution187
748Binary Tree zigzag level order Traversal187
749Minimum Cost For Tickets Leetcode Solution187
750Construct BST from given Preorder Traversal186
751N-Queens LeetCode Solution186
752Program for Bridge and Torch problem186
753Add and Search Word – Data structure design LeetCode186
754Minimum sum of multiplications of n numbers186
755Restore IP Addresses Leetcode Solution186
756Morris Traversal186
757Growable array based stack186
758Word Pattern LeetCode Solution186
759Rank Transform of an Array Leetcode Solution186
760Valid Number186
761Number of NGEs to the Right186
762Split a String in Balanced Strings Leetcode Solution186
763Print a Binary Tree in Vertical Order186
764Best Meeting Point LeetCode Solution186
765Base 7 Leetcode Solution186
766String comparison containing wildcards186
767Binomial Coefficient185
768Symmetric Tree Leetcode Solution185
769Maximum Profit in Job Scheduling Leetcode Solution185
770Find All Possible Recipes from Given Supplies LeetCode Solution185
771Elements to be added so that all elements of a range are present in array185
772Find Median from Data Stream LeetCode Solution185
773Maximum Product of Three Numbers LeetCode Solution185
774Finding K closest element185
775Hamming Distance Leetcode Solution185
776Priority Queue using doubly linked list185
777Number of Days Between Two Dates LeetCode Solution185
778Check if Two Expressions With Brackets are Same185
779Check If Array Pairs Are Divisible by k LeetCode Solution184
780Brick Wall LeetCode Solution184
781Sorted Linked List to Balanced BST184
782Partition to K Equal Sum Subsets Leetcode Solution184
783Regular Expression Matching184
784Jump Game184
785Find All Duplicates in an Array LeetCode Solution184
786Minimize Maximum Pair Sum in Array LeetCode Solution184
787Top K Frequent Words LeetCode Solution184
788Check for Palindrome after every character replacement Query184
789Special Array With X Elements Greater Than or Equal X Leetcode Solution184
790Decompress Run-Length Encoded List Leetcode Solution183
791Largest Rectangle in Histogram LeetCode Solution183
792Form Minimum Number From Given Sequence183
793Minimum Distance Between BST Nodes Leetcode Solution183
794Minimum Time Visiting All Points Leetcode Solution183
795Search in a Binary Search Tree Leetcode Solution183
796Linked List Cycle183
797Sort an array according to the order defined by another array183
798Merge K Sorted Linked Lists183
799Total Numbers With no Repeated Digits in a Range183
800Minimum Height Trees182
801Nearest Exit from Entrance in Maze LeetCode Solution182
802Queue based approach for first non-repeating character in a stream182
803Largest rectangular sub-matrix whose sum is 0182
804Kth ancestor of a node in binary tree182
805Maximum Depth of N-ary Tree Leetcode Solution182
806One Edit Distance LeetCode Solution182
807Maximum Nesting Depth of the Parentheses Leetcode Solution182
808Invert Binary Tree LeetCode Solution182
809Remove Nth Node From End of List Leetcode Solution182
810Longest Subarray Having Count of 1s One More than Count of 0s182
811Maximum Difference Between Increasing Elements LeetCode Solution182
812Balanced Expression with Replacement181
813Count items common to both the lists but with different prices181
814Identify and Mark Unmatched Parenthesis in an Expression181
815Given an Array of Pairs Find all Symmetric Pairs in it181
816Circular Queue181
817Final Prices With a Special Discount in a Shop Leetcode Solution181
818Number of Islands II LeetCode Solution181
819Repeated Substring Pattern LeetCode Solution180
820Diagonal Traversal of Binary Tree180
821Nested List Weight Sum II LeetCode Solution180
822Transpose Graph180
823Relative Ranks Leetcode Solution180
824Minimum time required to rot all oranges180
825Missing Element in Sorted Array LeetCode Solution179
826Course Schedule II – LeetCode179
827LCS (Longest Common Subsequence) of three strings179
828Minimum Swaps to Make Strings Equal Leetcode Solution179
829Reorder Data in Log Files LeetCode Solution179
830Last Stone Weight II LeetCode Solution179
831Deletion in a Binary Tree179
832Crawler Log Folder Leetcode Solution179
833Minimum Jumps to Reach Home LeetCode Solution179
834Daily Temperatures Leetcode Solution179
835Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
836Permutation Coefficient179
837Minimum Number of Taps to Open to Water a Garden LeetCode Solution179
838Search a 2D Matrix II Leetcode Solution179
839Sort Array By Parity II Leetcode Solution178
840Split Array Into Consecutive Subsequences178
841Subarray Product Less Than K LeetCode Solution178
842Distinct adjacent elements in an array178
843Check if a given array can represent Preorder Traversal of Binary Search Tree178
844Number Complement Leetcode Solution178
845Remove Duplicates from Sorted List II178
846Clone Graph LeetCode Solution178
847Lemonade Change Leetcode Solution178
848Design Browser History LeetCode Solution178
849Subsequence of Size K With the Largest Even Sum LeetCode Solution178
850Binary Search Tree Search and Insertion178
851Minimum number of jumps to reach end177
852Find Maximum Sum Possible Equal Sum of Three Stacks177
853Sliding Window Maximum177
854Iterative Preorder Traversal177
855A Space Optimized DP solution for 0-1 Knapsack Problem177
856Insert Delete GetRandom177
857Find all permuted rows of a given row in a matrix177
858Check if stack elements are pairwise consecutive177
859Check if an Array is Stack Sortable177
860Matrix Chain Multiplication176
861Partition List Leetcode Solution176
862An Interesting Method to generate Binary Numbers from 1 to n176
863Path with maximum average value176
864Valid Parentheses Leetcode Solution176
865Subset with sum divisible by m176
866Remove Duplicates from Sorted List LeetCode Solution176
867Guess Number Higher or Lower LeetCode Solution176
868Alien Dictionary LeetCode Solution176
869Minimum Sum Path in a Triangle176
870Tree Traversal (Preorder, Inorder & Postorder)176
871Find the subarray with least average176
872Spiral Matrix II Leetcode Solution176
873Minimum swaps to make sequences increasing176
874Sum of nearest smaller and greater number176
875Find the Only Repetitive Element Between 1 to N-1176
876Union and Intersection of two Linked Lists176
877Count Distinct Elements in Every Window of Size K176
878Convert BST to Min Heap175
879Sorted Array to Balanced BST175
880Design a Stack With Increment Operation Leetcode Solution175
881Can Place Flowers LeetCode Solution175
882Interval Tree175
883Least Number of Unique Integers after K Removals Leetcode Solution175
884Dividing Array into Pairs With Sum Divisible by K175
885Get Maximum in Generated Array Leetcode Solution175
886Count ways to reach the nth stair using step 1, 2 or 3175
887Check whether a given Binary Tree is Complete or not174
888Infix to Postfix174
889Sequences of given length where every element is more than or equal to twice of previous174
890Iterative Postorder Traversal Using Two Stacks174
891Friends Pairing Problem174
892Level order Traversal in Spiral Form174
893Find distance between two nodes of a Binary Tree174
894Number of Distinct Islands Leetcode Solution174
895Brightest Position on Street LeetCode Solution174
896GCDs of given index ranges in an array174
897Minesweeper LeetCode Solution174
898Time Based Key-Value Store LeetCode Solution174
899Diagonal Traverse LeetCode Solution174
900Sort Colors174
901Maximum size subarray sum equals k173
902Median of Two Sorted Arrays173
903Range sum queries without updates173
904Water Bottles Leetcode Solution173
905Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i173
906Maximum Score After Splitting a String Leetcode Solution173
907Diagonal Traversal LeetCode Solution173
908Set Matrix Zeroes Leetcode Solution173
909Destination City Leetcode Solution173
910Pattern Occurrences using Stack173
911Guess Number Higher or Lower II173
912Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution173
913Find all triplets with zero sum173
914Range LCM Queries173
915Shortest Word Distance Leetcode Solution173
916Count Negative Numbers in a Sorted Matrix LeetCode Solution173
917Delete And Earn172
918Lexicographical Numbers Leetcode Solution172
919Insert into a Binary Search Tree Leetcode Solution172
920Robot Bounded In Circle LeetCode Solution172
921Rearrange an Array Such that arr[i] is equal to i172
922Check if any two intervals overlap among a given set of intervals172
923A program to check if a binary tree is BST or not171
924Convert Sorted List to Binary Search Tree171
925Averages of Levels in Binary Tree171
926All Unique Triplets that Sum up to a Given Value171
927Alien Dictionary171
928Difference Array | Range update query in O(1)171
929Count Submatrices With All Ones LeetCode Solution171
930Construct the Rectangle Leetcode Solution171
931Palindrome Partitioning Leetcode Solution170
932My Calendar I LeetCode Solution170
933Analyze User Website Visit Pattern LeetCode Solution170
934Count Subarrays with Same Even and Odd Elements170
935Trim a Binary Search Tree170
936Binary Tree Longest Consecutive Sequence LeetCode Solution170
937K’th Largest Element in BST when modification to BST is not allowed170
938Spiral Matrix III LeetCode Solution170
939Find Common Characters Leetcode Solution170
940Product of Array Except Self LeetCode Solution170
941Three way partitioning of an array around a given range170
942Longest Palindromic Subsequence170
943Binary array after M range toggle operations170
944Construct Complete Binary Tree from its Linked List Representation170
945Three Consecutive Odds Leetcode Solution170
946Special Positions in a Binary Matrix Leetcode Solution170
9473 Sum170
948Check if the given array can represent Level Order Traversal of Binary Search Tree170
949Rearrange Spaces Between Words Leetcode Solution170
950Intersection of Two Linked Lists LeetCode Solution169
951Queue using Stacks169
952Maximum Frequency Stack Leetcode Solution169
953Vertical sum in a given binary tree169
954Minimum Height Trees LeetCode Solution169
955Number of Equivalent Domino Pairs Leetcode Solution169
956Create Maximum Number169
957Merge Two Sorted Lists Leetcode169
958Remove Duplicates from Sorted List II LeetCode Solution169
959Word Break168
960Maximize Sum of Array after K Negations Leetcode Solution168
961Symmetric Tree168
963Strongly Connected Component168
964Largest area rectangular sub-matrix with equal number of 1’s and 0’s168
965Queries for GCD of all numbers of an array except elements in a given range168
966BFS for Disconnected Graph168
967Climbing stairs167
968Count subarrays where second highest lie before highest167
969Construct BST from its given Level Order Traversal167
970Longest subsequence such that difference between adjacents is one167
971Reverse Nodes in K-Group167
972Depth First Search (DFS) for a Graph167
973Sign of the Product of an Array LeetCode Solution167
974Count Primes in Ranges167
975Print Fibonacci sequence using 2 variables167
976Maximum Product Subarray167
977Kth Smallest Element in a BST Leetcode Solution167
978Count pair with Given Sum166
979Combination Sum IV LeetCode Solution166
980Merging Intervals166
981Number of palindromic paths in a matrix166
982Stone Game II Leetcode166
983Unique Paths II166
984Find number of pairs in an array such that their XOR is 0165
985Find the First Circular Tour that visits all the Petrol Pumps165
986Find Maximum of Minimum for Every Window Size in a Given Array165
987Longest Nice Substring LeetCode Solution165
988Breadth First Search (BFS) for a Graph165
989Serialize and Deserialize Binary Tree165
990Largest Number Leetcode Solution165
991Scramble String LeetCode Solution165
992String Matching in an Array Leetcode Solution165
993The Maze III LeetCode Solution165
994Design Hit Counter LeetCode Solution165
995Maximum Subarray Sum Excluding Certain Elements165
996Can Make Arithmetic Progression From Sequence Leetcode Solution164
997Next Permutation Leetcode Solution164
998Find the Difference Leetcode Solution164
999Palindrome Partitioning164
1000Largest Substring Between Two Equal Characters Leetcode Solution164
1001Binary Search Tree Delete Operation164
1002Asteroid Collision LeetCode Solution164
1003Maximum Product of Indexes of Next Greater on Left and Right164
1004K Closest Points to Origin Leetcode Solution164
1005Count pairs from two sorted arrays whose sum is equal to a given value x164
1006Height of a generic tree from parent array164
1007Newman-Conway Sequence164
1008Maximum Length of Repeated Subarray164
1009Valid Boomerang Leetcode Solution164
1010K maximum sums of overlapping contiguous sub-arrays163
1011Consecutive Characters LeetCode Solution163
1012Graph Valid Tree LeetCode Solution163
1013Maximum length subsequence with difference between adjacent elements as either 0 or 1163
1014Shortest Completing Word Leetcode Solution163
1015Balanced Binary Tree163
1016The Painter’s Partition Problem163
1017Print Next Greater Number of Q queries163
1018Generate Parentheses Leetcode Solution163
1019Kth Smallest Element in a Sorted Matrix LeetCode Solution163
1020Maximum difference between frequency of two elements such that element having greater frequency is also greater163
1021Remove Duplicates from Sorted Array II Leetcode Solution163
1022Collect maximum points in a grid using two traversals162
1023Length of Longest Fibonacci Subsequence162
1024Maximum Sum of 3 Non-Overlapping Subarrays162
1025Maximum Number of Ways to Partition an Array LeetCode Solution162
1026Minimum Index Sum of Two Lists162
1027Validate Binary Search Tree162
1028Friends Of Appropriate Ages LeetCode Solution162
1029Largest divisible pairs subset162
1030Level Order Traversal of Binary Tree162
1031Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution162
1032Find postorder traversal of BST from preorder traversal162
1033Segment Tree162
1034Invalid Transactions LeetCode Solution162
1035Shuffle 2n integers as without using extra space162
1036Decrypt String from Alphabet to Integer Mapping Leetcode Solution162
1037Find Duplicate Subtrees162
1038Next Greater Element III LeetCode Solution161
1039Merge Sort161
1040Boolean Parenthesization Problem161
1041Move all negative elements to end in order with extra space allowed161
1042Find a Peak Element II LeetCode Solution161
1043Available Captures for Rook Leetcode Solution161
1044Number Of Longest Increasing Subsequence161
1045First missing positive161
1046Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’161
1047Make The String Great Leetcode Solution161
1048Kill Process LeetCode Solution160
1049Bitwise AND of Numbers Range LeetCode Solution160
1050Advantages of BST over Hash Table160
1051Insertion in a Binary Tree160
1052Construct Binary Tree from given Parent Array representation160
1053Custom Sort String Leetcode Solution160
1054Compute nCr % p160
1055Construction of Longest Increasing Subsequence (N log N)160
1056Rearrange array such that even positioned are greater than odd160
1057Build an Array With Stack Operations Leetcode Solution160
1058Boundary Traversal of binary tree160
1059Binary Search Tree160
1060Minimum Size Subarray Sum159
1061Iterative Depth First Traversal of Graph159
1062Rearrange array such that even index elements are smaller and odd index elements are greater159
1063Ugly Numbers159
1064Print Right View of a Binary Tree159
1065Count minimum steps to get the given desired array159
1066Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution159
1067Double the first element and move zero to end159
1068Recover Binary Search Tree Leetcode Solution158
1069Find Peak Element158
1070Partition Equal Subset Sum158
1071Maximum subsequence sum such that no three are consecutive158
1072Largest BST Subtree LeetCode Solution158
1073Subarrays with K Different Integers Leetcode Solution158
1074Employee Importance LeetCode Solution158
1075Path Sum II LeetCode Solution158
1076Remove Palindromic Subsequences Leetcode Solution158
1077Defanging an IP Address LeetCode Solution158
1078Maximum weight transformation of a given string157
1079Regular Expression Matching Regular Expression Matching LeetCode Solution157
1080Smallest Common Region Leetcode Solution157
1081Morris Inorder Traversal157
1082Find maximum difference between nearest left and right smaller elements157
1083Add two numbers157
1084Level order traversal using two Queues157
1085Find whether a subarray is in form of a mountain or not156
1086Ugly Number II LeetCode Solution156
1087Palindrome Permutation LeetCode Solution156
1088Implement Trie (Prefix Tree) Leetcode Solution156
1089Binary Tree Right Side View LeetCode Solution156
1090Remove duplicates from sorted array156
1091Longest Bitonic Subsequence156
1092Lowest Common Ancestor156
1093Palindromic Substrings Leetcode Solution155
1094Increasing Triplet Subsequence LeetCode Solution155
1095Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution155
1096Populating Next Right Pointers in Each Node Leetcode Solution155
1097Super Ugly Number155
1098Number of Closed Islands Leetcode Solution155
1099Bus Routes Leetcode Solution155
1100Number of siblings of a given Node in n-ary Tree155
1101Maximize Distance to Closest Person LeetCode Solution155
1102Divisible Pairs Counting154
1103Sum of Even Numbers After Queries154
1104Valid Tic-Tac-Toe State LeetCode Solution154
1105Clone a Binary Tree with Random Pointers154
1106Reformat The String Leetcode Solution154
1107Print all triplets in sorted array that form AP154
1108Path Sum154
1109Iterative method to find ancestors of a given binary tree154
1110Moser-de Bruijn Sequence153
1111Products of ranges in an array153
1112Thousand Separator Leetcode Solution153
1113Search in Sorted Rotated Array153
1114Find Three Element From Different Three Arrays Such That a + b + c = sum153
1115Binary Tree Data Structure153
1116Find the minimum distance between two numbers153
1117Cells with Odd Values in a Matrix LeetCode Solution153
1118Day of the Year Leetcode Solution153
1119Find Smallest Range Containing Elements from k Lists152
1120Kth Smallest Product of Two Sorted Arrays LeetCode Solution152
1121Mean of Array After Removing Some Elements Leetcode Solution152
1122Level of Each node in a Tree from source node152
1123Search Insert Position152
1124Number of Students Doing Homework at a Given Time Leetcode Solution152
1125Root to Leaf path with target sum Leetcode Solutions152
1126Minimum Absolute Difference in BST Leetcode Solution152
1127Count Largest Group Leetcode Solution152
1128Longest Subarray of 1’s After Deleting One Element LeetCode Solution152
1129Write Code to Determine if Two Trees are Identical151
1130Distinct Subsequences151
1131Longest Repeated Subsequence151
1132Bottom View of a Binary Tree151
1133Longest Increasing Consecutive Subsequence151
1134Serialize and Deserialize Binary Tree LeetCode Solution151
1135Third Maximum Number Leetcode Solution150
1136Find maximum length Snake sequence150
1137Convert BST into a Min-Heap without using array150
1138Maximum Product of Splitted Binary Tree LeetCode Solution150
1139Closest Leaf in a Binary Tree LeetCode Solution150
1140Constant time range add operation on an array150
1141Prime Palindrome LeetCode Solution150
1142Maximum Depth Of Binary Tree150
1143Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution150
1144Topological Sorting150
1145Maximum Product Subarray150
1146Minimum Moves to Equal Array Elements LeetCode Solution150
1147Minimum sum of squares of character counts in a given string after removing k characters150
1148Construct K Palindrome Strings LeetCode Solution150
1149Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1150Diameter of N-Ary Tree LeetCode Solution149
1151Golomb sequence149
1152Queries for Number of Distinct Elements in a Subarray149
1153Search an Element in Sorted Rotated Array149
1154Swap Nodes In Pairs149
1155Rotate Array149
1156Search Suggestions System LeetCode Solution148
1157Web Crawler LeetCode Solution148
1158Reformat Date LeetCode Solution148
1159Cutting a Rod148
1160Count even length binary sequences with same sum of first and second half bits148
1161Priority Queue148
1162Kth Smallest Number in Multiplication Table Leetcode Solution148
1163Print modified array after executing the commands of addition and subtraction148
1164Minimum Score Triangulation of Polygon Leetcode Solution148
1165Subset Sum Problem in O(sum) space148
1166Contiguous Array LeetCode Solution147
1167Closest Binary Search Tree Value Leetcode Solution147
1168Find Largest Value in Each Tree Row LeetCode Solution147
1169Maximize sum of consecutive differences in a circular array147
1170Delete Nodes and Return Forest Leetcode Solution147
1171Find a sorted subsequence of size 3 in linear time147
1172Matchsticks to Square Leetcode Solution146
1173Count Pairs Whose Products Exist in Array146
1174Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1175Decision Tree146
1176Transform a BST to Greater sum Tree146
1177Binary Tree to Binary Search Tree Conversion146
1178Red-Black Tree Introduction146
1179Given a binary tree, how do you remove all the half nodes?146
1180Maximum Binary Tree146
1181Maximum sum of a path in a Right Number Triangle145
1182Check Array Formation Through Concatenation Leetcode Solution145
1183Reverse a Path in BST using Queue145
1184Factorial Trailing Zeroes LeetCode Solution145
1185K’th Largest element in BST using constant extra space145
1186Possible Bipartition LeetCode Solution145
1187Minimum Swaps To Make Sequences Increasing LeetCode Solution145
1188Minimum Sideway Jumps LeetCode Solution145
1189Valid Triangle Number144
1190Replace two consecutive equal values with one greater144
1191Maximum Value at a Given Index in a Bounded Array LeetCode Solution144
1192Sum of Left Leaves LeetCode Solution144
1193Concatenation of Array LeetCode Solution144
1194Merge two BSTs with limited extra space144
1195First Bad Version144
1196Maximum number of segments of lengths a, b and c144
1197Find the smallest binary digit multiple of given number144
1198Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution144
1199Decrease Elements To Make Array Zigzag LeetCode Solution144
1200Perfect Squares LeetCode Solution144
1201Path Crossing Leetcode Solution144
1202Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution143
1203Maximum sum bitonic subarray143
1204Maximum sum of pairs with specific difference143
1205Swapping Nodes in a Linked List Leetcode Solution143
1206Queue Reconstruction by Height143
1207Number of Orders in the Backlog Leetcode Solution143
1208Divide Two Integers Leetcode Solution143
1209Print n terms of Newman-Conway Sequence143
1210Convert Sorted Array to Binary Search Tree LeetCode Solutions142
1211Guess The Word142
1212Sliding Window Median Leetcode Solution142
1213Valid Perfect Square LeetCode Solution142
1214Queries on Probability of Even or Odd Number in given Ranges142
1215Integer Break LeetCode Solution142
1216How to print maximum number of A’s using given four keys141
1217New 21 Game141
1218Find minimum number of merge operations to make an array palindrome140
1219Array Queries for multiply replacements and product140
1220Lowest Common Ancestor in Binary Search Tree140
1221Check if all levels of two Binary Tree are anagrams or not140
1222Kth Smallest Element in a BST140
1223Champagne Tower LeetCode Solution140
1224Graph and its representation140
1225Moving Stones Until Consecutive Leetcode Solution140
1226Lowest Common Ancestor of a Binary Tree Leetcode Solution140
1227Maximum Array from Two given Arrays Keeping Order Same139
1228Range Sum Query using Sparse Table139
1229Find Minimum in Rotated Sorted Array II LeetCode Solution139
1230Merge k Sorted Lists Leetcode Solution139
1231Flatten 2D Vector LeetCode Solution139
1232Longest Common Prefix Using Word by Word Matching139
1233Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution138
1234Design Skiplist LeetCode Solution138
1235Maximum Product Subarray138
1236Missing Number138
1237The kth Factor of n Leetcode Solution138
1238Contiguous Array138
1239BST to a Tree with Sum of all Smaller Keys138
1240Mean of range in array138
1241Maximize Elements Using Another Array138
1242Maximum Sum Increasing Subsequence138
1243Write a function to get the intersection point of two Linked Lists138
1244Range Queries for Longest Correct Bracket Subsequence138
1245Find k-th smallest element in BST (Order Statistics in BST)137
1246LRU Cache Leetcode Solution137
1247Print modified array after multiple array range increment operations137
1248Bold Words in String LeetCode Solution137
1249Largest Plus Sign Leetcode Solution137
1250Min Cost Climbing Stairs LeetCode Solution136
1251Minimum Remove to Make Valid Parentheses LeetCode Solution136
1252Count Subsets Having Distinct Even Numbers136
1253Parallel Courses II LeetCode Solution136
1254Check in binary array the number represented by a subarray is odd or even135
1255Power of Two135
1256Graph Cloning135
1257Check if each internal node of a BST has exactly one child134
1258Check Completeness of a Binary Tree LeetCode Solution134
1259Verify Preorder Serialization of a Binary Tree134
1260Image Overlap LeetCode Solution134
1261Minimum Time to Collect All Apples in a Tree LeetCode Solution134
1262Arithmetic Slices II – Subsequence LeetCode Solution134
1263Different Ways to Add Parentheses Leetcode Solution134
1264Smallest Range II Leetcode Solution133
1265Check for Identical BSTs without building the trees133
1266Check if two nodes are on the same path in a Tree133
1267Longest Substring Without Repeating Characters Leetcode Solution132
1268Symmetric Tree LeetCode Solution Leetcode Solution132
1269Orderly Queue LeetCode Solution132
1270Koko Eating Bananas LeetCode Solution132
1271Next greater element132
1272Print Ancestors of a Given Binary Tree Node Without Recursion132
1273Excel Sheet Column Title LeetCode Solution131
1274Arranging Coins Leetcode Solution130
1275Count and Toggle Queries on a Binary Array130
1276Vertical Order Traversal of Binary Tree LeetCode Solution129
1277Merge Sorted Array129
1278Number of elements less than or equal to a given number in a given subarray129
1279Palindrome Partitioning128
1280Largest Submatrix With Rearrangements LeetCode Solution128
1281Array Nesting Leetcode Solution128
1282Palindrome Number LeetCode Solution127
1283Find the Winner of the Circular Game LeetCode Solution126
1284Add Two Numbers II Leetcode Solution126
1285Check if X can give change to every person in the Queue126
1286Peeking Iterator LeetCode Solution126
1287Check If a String Can Break Another String Leetcode Solution126
1288Maximum product of an increasing subsequence126
1289Newman–Shanks–Williams prime126
1290Range Minimum Query (Square Root Decomposition and Sparse Table)125
1291Insert Delete GetRandom O(1) Leetcode Solution125
1292Queries for Decimal Values of Subarrays of a Binary Array125
1293Find maximum average subarray of k length124
1294Continuous Subarray Sum LeetCode Solution123
1295Check given array of size n can represent BST of n levels or not123
1296Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution123
1297Encoded String With Shortest Length LeetCode Solution123
1298Jump Game IV LeetCode Solution122
1299Random Pick Index LeetCode Solution121
1300Reach a Number LeetCode Solution121
1301Binary Tree to Binary Search Tree Conversion using STL set121
1302Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1303Number of indexes with equal elements in given range120
1304Minimum Number of People to Teach LeetCode Solution120
1305Convert a BST to a Binary Tree such that sum of all greater keys is added to every key118
1306Minimum Total Space Wasted With K Resizing Operations LeetCode Solution117
1307Design A Leaderboard Leetcode Solution116
1308Convert to Base -2 LeetCode Solution116
1309Queries on XOR of greatest odd divisor of the range115
1310Design Underground System Leetcode Solution114
1311Shifting Letters LeetCode Solution114
1312Print Maximum Length Chain of Pairs111
1313Detect Capital Leetcode Solution111
1314Minimum Swaps to Group All 1’s Together Leetcode Solution110
1315Top K Frequent Elements LeetCode Solution110
1316Minimum Path Sum Leetcode Solution108
1317Count Sub Islands LeetCode Solution108
1318Substring with Concatenation of All Words Leetcode Solution108
1319Odd Even Linked List Leetcode Solution107
1320Monotonic Array Leetcode Solution105
1321Longest Common Subsequence LeetCode Solution102
1322Find the Town Judge LeetCode Solution101
1323Decode String Leetcode Solution101
1324Binary Tree Inorder Traversal LeetCode Solution101
1325Maximum Population Year LeetCode Solution100
1326Rectangle Overlap LeetCode Solution96
1327Shortest Unsorted Continuous Subarray LeetCode Solution96
1328Best Meeting Point LeetCode Solution94
1329Maximum Population Year LeetCode Solution93
1330Find the Town Judge LeetCode Solution92
1331Insert into a Sorted Circular Linked List LeetCode Solution92
1332Flatten Binary Tree to Linked List LeetCode Solution92
1333Sum Root to Leaf Numbers LeetCode Solution91
1334Design Add and Search Words Data Structure LeetCode Solution90
1335Reveal Cards In Increasing Order Leetcode Solution88
1336Stone Game IV LeetCode Solution88
1337Range Sum Query 2D – Immutable LeetCode Solution87
1338Is Graph Bipartite? LeetCode Solution87
1339Valid Triangle Number LeetCode Solution86
1340Score of Parenthesis LeetCode Solution85
1341Divide Chocolate LeetCode Solution81
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution70
1344Reverse Integer Leetcode Solution68
1345Rotate String LeetCode Solution65
1346Find K Closest Elements LeetCode Solution64
1347Sort Colors LeetCode Solution63
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution61
1349Excel Sheet Column Number LeetCode Solution57
1350Maximum Size Subarray Sum Equals k Leetcode Solution51
1351H-Index Leetcode Solution46
1352Camelcase Matching Leetcode Solution45
1353Valid Anagram Leetcode Solution45
1354Most Stones Removed with Same Row or Column LeetCode Solution44
1355High Five LeetCode Solution43
1356Container With Most Water LeetCode Solution43
1357Group Anagrams LeetCode Solution42
1358Sliding Window Maximum LeetCode Solution42
1359Next Permutation LeetCode Solution41
1360Find Peak Element LeetCode Solution40
1361Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution40
1362Binary Search LeetCode Solution40
1363Paint House LeetCode Solution37
1364Flatten Binary Tree to Linked List LeetCode Solution36
1365Minimum Number of Arrows to Burst Balloons LeetCode Solution36
1366Valid Triangle Number LeetCode Solution36
1367Isomorphic Strings LeetCode Solution35
1368Split Linked List in Parts Leetcode Solution35
1369Group Shifted Strings Leetcode Solution35
1370Unique Binary Search Trees LeetCode Solution35
1371Sentence Screen Fitting LeetCode Solution35
1372Next Greater Element I Leetcode Solution35
1373The Number of Weak Characters in the Game LeetCode Solution34
1374Count Good Nodes in Binary Tree LeetCode Solution34
1375Swim in Rising Water LeetCode Solution32
1376Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution32
1377Closest Binary Search Tree Value II LeetCode Solution31
1378Single Element in a Sorted Array LeetCode Solution31
1379Peak Index in a Mountain Array LeetCode Solution31
1380Best Time to Buy and Sell Stock IV LeetCode Solution30
1381Find First and Last Position of Element in Sorted Array LeetCode Solution29
1382All Possible Full Binary Trees LeetCode Solution28
1383Max Sum of Two Non-Overlapping Subarrays LeetCode Solution28
1384Lowest Common Ancestor of a Binary Search Tree Leetcode Solution27
1385Minimum Increment to Make Array Unique Leetcode Solution27
1386Validate Stack Sequences LeetCode Solution27
1387Break a Palindrome LeetCode Solution25
1388Implement Rand10() Using Rand7() Leetcode Solution25
1389Implement strStr() LeetCode Solution25
1390Detect Squares LeetCode Solution25
1391Trapping Rain Water II LeetCode Solution25
1392Greatest Sum Divisible by Three LeetCode Solution24
1393Reverse Nodes in k-Group LeetCode Solution23
1394Stone Game IV LeetCode Solution23
1395Remove All Ones With Row and Column Flips Leetcode Solution22
1396Contains Duplicate LeetCode Solution22
1397Invert Binary Tree LeetCode Solution22
1398Design Bounded Blocking Queue LeetCode Solution21
1399Fibonacci Number LeetCode Solution21
1400Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution20
1401Total Hamming Distance LeetCode Solution16
1402Candy LeetCode Solution16
1403Unique Paths III LeetCode Solution14
Translate »