Group Anagrams LeetCode Solution


Frequently asked in Adobe Amazon American Express Apple BlackRock Bloomberg ByteDance Citadel DE Shaw Expedia Google Intel Mathworks Microsoft Morgan Stanley Netflix Nvidia Oracle PayPal ServiceNow Twitter Two Sigma VMware Yelp
categories - MediumViews 1

Problem Statement

Group Anagrams LeetCode Solution Says that – Given an array of strings strs, group the anagrams together. You can return the answer in any order.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Example 1:

Input:

 strs = ["eat","tea","tan","ate","nat","bat"]

Output:

 [["bat"],["nat","tan"],["ate","eat","tea"]]

Example 2:

Input:

 strs = [""]

Output:

 [[""]]

Example 3:

Input:

 strs = ["a"]

Output:

 [["a"]]

Constraints:

  • 1 <= strs.length <= 104
  • 0 <= strs[i].length <= 100
  • strs[i] consists of lowercase English letters.

ALGORITHM –

IDEA –

  • In order to Find Group Anagrams. First, we will focus on the anagrams(after sorting the words are the same).
  • So, first traversed through the array and sort each word in order to find anagrams.
  • We will make one Hashmap and check if sorted words are present in Hashmap then we will append that non-sorted words into the list as value and key as sorted words.
  • Else sorted word as key and value as non-sorted word as a value within a list.
  • and At last we will create one answer list and  will run a loop in hash map and add the values in answer.
  • Hence We will find the Group Anagrams.

Approach –

  • At first we will create one Hashmap and a list that will return the answer.
  • After that will run a loop from 0 to length of array and sort each words.
  • after sorting each words we will check if it is present in hashmap or not if it is present then will the non-sorted word into the value else will create one non-sorted word list as value and key as sorted word.
  • At last we will traverse the whole Hashmap and append value into ans and return ans.
  • Hence we will Find the Group Anagrams.

Image of the solution –

Group Anagrams LeetCode SolutionPin

Group Anagrams LeetCode SolutionPin

Group Anagrams LeetCode SolutionPin

 

class Solution:
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        
        ans = []
        dic = {}
        for i in range(len(strs)):
            k = ""
            for j in sorted(strs[i]):
                k += j
                
            if k in dic:
                dic[k].append(strs[i])
            
            else:
                dic[k] = [strs[i]]
                
                
        for i in dic:
            ans.append(dic[i])

        return ans
class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
      List<List<String>> ans = new ArrayList<>();
        HashMap<String, List<String>> dic = new HashMap<>();
    
        
        for (int i = 0; i < strs.length; i++) {
    	    String temp = strs[i];
    	    char[] ch = temp.toCharArray();
    	    Arrays.sort(ch);
    	    if (dic.containsKey(String.valueOf(ch))) {
    		    dic.get(String.valueOf(ch)).add(strs[i]);
    	    } else {
    		    List<String> each = new ArrayList<>();
    		    each.add(strs[i]);
    		    dic.put(String.valueOf(ch), each);
    	    }
        }
        for (List<String> item: dic.values()) {
    	    ans.add(item);
        }
        return ans;
    }
    

}

TIME COMPLEXITY : O(N*K(LOGK)), K = Len(Words).

SPACE COMPLEXITY: O(N), As we have taken Extra Space.

SIMILAR QUESTIONS – https://www.tutorialcup.com/leetcode-solutions/minimum-number-of-steps-to-make-two-strings-anagram-leetcode-solutions.htm

 

Top Interview Questions

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