Design Add and Search Words Data Structure LeetCode Solution

Difficulty Level Medium
Frequently asked in Adobe Amazon Apple ByteDance Facebook Google lyft Microsoft Nvidia Oracle Twitter Uber
Depth First Search Design String TrieViews 67

Problem Statement:

Design Add and Search Words Data Structure LeetCode Solution says – Design a data structure that supports adding new words and finding if a string matches any previously added string.

Implement the WordDictionary class:

  • WordDictionary() Initializes the object.
  • void addWord(word) Adds word to the data structure, it can be matched later.
  • bool search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter.







WordDictionary wordDictionary = new WordDictionary();
wordDictionary.addWord("mad");"pad");  // return False"bad"); // return True".ad"); // return True"b.."); // return True

Approach for Design Add and Search Words Data Structure Leetcode Solution:


  • We generally consider Trie data structure to solve problems efficiently which involves operations like string matching. If you are new to Trie then first understand what is Trie and how it is implemented, and how searching is done it.
  • You can refer to Trie
  • Coming on to the solution. First, we will create a Trie Node consisting of 26 child nodes, one for each character of the lowercase English letters, and will declare a head node, denoting the root node of the Trie. The Node structure will also consist of a flag named isEnd which will mark the end of a word if set to true.
  • addWord(): This function simply involves the insertion of a word in a Trie. We will iterate over all the words and will insert them one by one in the Trie.
  • search(): For the word which does not involve any “.” in them, the search is simple we just need to iterate over the Trie and check if the particular word exists in the Trie or not.
  • The tricky part is when “.” is present in the word. Here we need to keep in mind that as soon as we see a “.” we can use any of the characters from the lower case English alphabet, to form a word that is present in the Trie. So the idea is to search for all the possibilities in the Trie for that particular node i.e., we need to explore all possible paths at each . level.


Design Add and Search Words Data Structure Leetcode C++ Solution:

class WordDictionary {
    struct Node{
        Node* child[26]={NULL};
        bool isEnd=false;
    Node* head = NULL;
    WordDictionary() {
        head = new Node();
    void addWord(string word) {
        Node* ptr = head;
        for(auto it:word){
                ptr->child[it-'a'] = new Node();
            ptr = ptr->child[it-'a'];
        ptr->isEnd = true;
    bool searchHelper(Node* node,string s){
        Node* ptr = node;
        int pos=0;
        for(auto it:s){
                for(int i=0;i<26;i++){
                            return true;
                return false;
            else if(ptr->child[it-'a']){
                ptr = ptr->child[it-'a'];
                return false;
        return ptr->isEnd;
    bool search(string word) {
        return searchHelper(head,word);

Design Add and Search Words Data Structure Leetcode Python Solution:

class Node:
    def __init__(self):
        self.child = {}
        self.isEnd = False
class WordDictionary:
    def __init__(self):
        self.head = Node()
    def addWord(self, word: str) -> None:
        ptr = self.head
        for it in word:
            if it not in ptr.child:
                ptr.child[it] = Node()
            ptr = ptr.child[it]
        ptr.isEnd = True
    def search(self, word: str) -> bool:
        def searchHelper(node,s):
            ptr = node
            for it in s:
                if it==".":
                    for i in ptr.child:
                        if searchHelper(ptr.child[i],s[pos+1:]):
                            return True
                    return False
                elif it in ptr.child:
                    ptr = ptr.child[it]
                    return False
            return ptr.isEnd
        return searchHelper(self.head,word)

Complexity Analysis:

  • Time Complexity: The time complexity of the above code is for the words without dots, where “m” is the key length, and O(N.26^ M) for the words without dots, where n is the number of keys.
  • Space Complexity: The space complexity of the above code is  for the search of words without dots, and O(m) for the words with dots, in order to keep the recursion stack.

Related Problem: Implement Trie (Prefix Tree) Leetcode Solution

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2819
2Java program to find the number of Nodes in a Binary Tree2500
3Reverse a string without affecting special characters2462
4Delete a node of a linked list at given position1976
5Palindrome using Recursion1780
6Insert nodes in a linked list in a sorted way (Ascending Order)1662
7Find elements pair from array whose sum equal to number1648
8Sort Elements by Frequency of Occurrences1631
9Write a program to print all permutations of a given string1606
10Find Minimum Distance Between Two Numbers in an Array1473
11Create a Doubly Linked List1444
12Quick Sort1420
13Reverse an Array1414
14Smallest window in a string containing all characters of another string1395
15Find a Triplet That Sum to a Given Value1356
16Recursively remove all adjacent duplicates1353
17First Repeating Element1337
18Arrange Even and Odd number such that Odd comes after Even1320
19Sum of numbers in String1316
20Smallest Positive Number Missing in an Unsorted Array1283
21Check if the Elements of an Array are Consecutive1253
22Detect a loop in the Linked List1237
23Largest Sum Contiguous Subarray1230
24Quick Sort on SIngly Linked List1214
25Subarray with Given Sum1212
26Print all Possible Combinations of R Elements in a given Array of size N1205
27Recursive function to do substring search1197
28Find the Maximum Repeating Number in Array1155
29Binary Tree Level order traversal in Java1124
30Find the First and Second Smallest Elements1121
31Check if two linked lists are identical1103
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1070
34Find Leaders in an Array1061
35Swap nodes in the linked list1036
36Find the Number Occurring Odd Number of Times in an Array1001
37Arrange given Numbers to Form the Biggest Number II993
38Find the second most frequent character990
39Given a string find its first non-repeating character970
40Find Triplet in Array With a Given Sum964
41Given a sorted array and a number x, find the pair in array whose sum is closest to x954
42Total number of occurrences of a given item in the linked list951
43A Program to check if strings are rotations of each other or not943
44Print all possible words from phone digits934
45Find the Missing Number926
46Rearrange Positive and Negative Numbers Alternatively in Array920
47Longest Palindromic Substring905
48Segregate even and odd nodes in a linked list883
49Print Longest common subsequence882
50Union and Intersection of Two Linked Lists871
51Transform one string to another using minimum number of given operations867
52Rearrange given Array in Maximum Minimum Form846
53Check rearranged string can form a palindrome844
54Count Possible Triangles819
55Iterative Implementation of Quick Sort816
56Multiplication of Two Matrices802
57Check if the linked list is palindrome795
58Count of Triplets With Sum Less than Given Value791
59Rotate a Linked List790
60Stock Buy Sell to Maximize Profit788
61Concatenation of two strings761
62Tug of War760
63Count Number of Substrings with K Distinct Character’s758
64Print all duplicates in the input string753
65Find Nearest Greater and Smaller Element746
66Find Pythagorean Triplets from Array736
67The Celebrity Problem736
68Reverse String Without Temporary Variable734
69Remove ‘b’ and ‘ac’ from a given string728
70Find all Common Elements in Given Three Sorted Arrays727
71Remove all duplicates in an unsorted linked list709
72Find the Row with Maximum Number of 1’s706
73Find the Peak Element from an Array699
74Find the subarray whose sum is equal to a given number X696
75Remove Minimum Characters so that Two Strings Become Anagrams689
76Find Smallest Missing Number in a Sorted Array687
77Insertion Sort686
78A Product Array Puzzle685
79Addition of Two Matrices682
80Implement Two Stacks in an Array676
81Generate all Binary Strings Without Consecutive 1’s672
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II659
84Lexicographic rank of string653
85Check if Two given Matrices are Identical644
86Multiplication of Previous and Next644
87Subtraction of Two Matrices632
88Merge K Sorted Arrays and Print Sorted Output632
89Move All the Zeros to the End of the Given Array627
90Online Algorithm for Checking Palindrome in a Stream625
91Form Minimum Number from Given Sequence of D’s and I’s623
92Divide a string in N equal parts622
93Check whether two strings are anagram of each other614
94Maximum Circular Subarray Sum613
95Remove recurring digits in a given number609
96Sort a stack using a temporary stack608
97Sort a linked list that is sorted alternating ascending and descending608
98Find the Minimum Element in a Sorted and Rotated Array605
99Move last element of the Linked List at first place601
100Subarray and Subsequence600
101First Circular Tour to Visit all the Petrol Bunks599
102Largest Subarray with Equal Number of 0’s and 1’s597
103Compare two strings(linked lists)592
104Flattening a linked list591
105Maximum Element in an Array which is Increasing and then Decreasing590
106Palindrome Permutations of a String584
107Elements Appear more than N/K times in Array581
108Majority Element576
109Run length encoding575
110Minimum insertions to form a shortest palindrome573
111Print all permutations with repetition572
112Palindromes in a given range571
113Pangram Checking570
114Merge a linked list into another at alternate positions568
115Minimum Characters to be Added at Front to Make String Palindrome564
116Remove all duplicates in a sorted linked list563
117Rearrange a given linked list in-place562
118Minimum number of Merge Operations to make an Array Palindrome560
119Most repeating character in a string558
120Rotate string to get lexicographically minimum string557
121Repeated Subsequence of Length Two or More556
122Print all anagrams together in a sequence of words552
123Reorder an Array According to the Given Indexes550
124Pancake Sorting Problem542
125Merge Overlapping Intervals II539
126Two Sum Leetcode Solution539
127Clone a Linked List with next and random pointer536
128Size of The Subarray With Maximum Sum528
129Transpose of a Matrix524
130Removing Spaces from a String using stringstream521
131Remove Extra Spaces from a String520
132Remove duplicates from a string519
133Check if a given string is a rotation of a palindrome519
134Smallest Palindrome after Replacement518
135Partition Problem517
136Maximum Sum Increasing Subsequence515
137Longest Palindrome can be Formed by Removing or Rearranging Characters513
138Check whether Strings are K Distance Apart or Not502
139Generate all Binary Strings from Given Pattern502
140Delete Last Occurrence501
1413Sum Leetcode Solution500
142Length of Longest valid Substring499
143Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized499
144Insert Node in the Sorted Linked List498
145Check if Two given Strings are Isomorphic to each other494
146Maximum difference between two elements such as larger element comes after smaller487
147Program to Toggle all Characters in a String483
148Given string is interleaving of two other strings or not482
149Count Minimum Steps to Get the given Array480
150Number of Smaller Elements on Right Side478
151Merge sort better than quick sort for linked lists477
152Find Pair with Given Difference473
153Check if all Rows of a Matrix are Circular Rotations of Each Other471
154Check length of a String is Equal to the Number Appended at its Last470
155Longest Common Prefix using Divide and Conquer468
156Find nth node of the Linked list from the end466
157Find a Fixed Point in a Given Array463
158Sort 0s 1s and 2s in an Array458
159Print all interleavings of given two strings457
160Compare Two Version Numbers456
161Reverse words in a given string455
162Merge two sorted linked lists such that merged list is in reverse order453
163Find the Subarray of given length with Least Average452
164Reorder Array Using Given Indexes451
165Split linked list using alternate nodes450
166Median of Two Sorted Arrays LeetCode Solution450
167Print Reverse of a string (Recursion)448
168Find K Length Subarray of Maximum Average439
169Print string of odd length in ‘X’ format436
170Swap Kth Node from beginning with Kth Node from End433
171Find Element Using Binary Search in Sorted Array433
172Print all Palindromic Partitions of a String430
173Find Duplicates in an Array in Most Efficient Way428
174print all palindromic partitions421
175Maximum Length of Chain Pairs417
176Shortest Superstring Problem415
177Flatten a multilevel linked list415
178Check if String Follows Order of Characters by a Pattern or not412
179Sorting a K Sorted Array409
180Sort a String According to Another String404
181Longest Span with same Sum in two Binary Arrays II398
182Reverse a Linked List in groups395
183Find a Sorted Subsequence of size 3393
184Program to add two binary digits390
185Recursively print all the sentences that can be formed from list of word lists388
186Find the two Numbers with Odd Occurrences in an Unsorted Array387
187Longest Common Prefix Using Binary Search II385
188Reverse a Singly Linked List (Iterative/Non-Recursive)382
189Caesar Cipher378
190Rearrange a linked list in Zig-Zag377
191Check if String can Become Empty by Recursively Deleting given Substring377
192Kth Non-repeating Character377
193Pancake Sorting373
194Rotate Image by 90 degrees371
195Longest Common Prefix Word by Word Matching370
196Perfect Reversible String366
197Permutations of a Given String Using STL364
198Merging Two Sorted Arrays363
199Find the point where a monotonically increasing function becomes positive first time361
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes361
201Increasing Subsequence of Length three with Maximum Product361
202Find First non-repeating character in a string358
203Sort a linked list with 0s, 1s and 2s357
2041`s and 2`s complement of binary number357
205Four Elements that Sum to Given353
206Delete N nodes after M352
207List items containing all characters of a given word352
208Count Number of Occurrences in a Sorted Array350
209Longest Common Prefix using Character by Character Matching349
210Palindrome string (number)343
211Split a string342
212Minimum Characters to be Removed to Make a Binary String Alternate340
213Recursive Implementation of atoi()333
214Check if a Linked list of Strings form a Palindrome333
215Print All Distinct Elements of the Array332
216Sorting the array of strings330
217Convert a String that is Repetition of a Substring of Length K330
218Even Substring Count328
219Find the first Repeating Number in a Given Array326
220Maximum occurring character in a string326
221Valid Parentheses LeetCode Solution326
222Reverse a singly linked list recursively325
223Can we reverse a linked list in less than O(n) time ?323
224Binary Tree to Doubly linked list323
225Print Shortest Path to Print a String on Screen322
226Convert string1 to string2 in one edit319
227Maximum Subarray Leetcode Solution319
228wildcard character matching319
229Nth Character in Concatenated Decimal String318
230Reverse a String using Stack318
231Sort Elements by Frequency II317
232Lower Case To Upper Case314
233Count the number of words313
234Merge Two Sorted Arrays311
235Find the Lost Element From a Duplicated Array310
236Split Four Distinct Strings309
237Find middle of the Linked List307
238Longest Common Subsequence with Permutations306
239Count the Pairs at Same Distance as in English Alphabets301
240Matrix Chain Multiplication using Dynamic Programming297
241Next Greater Element in an Array294
242Palindrome Permutation290
243Find Nth Node285
244Roman to Integer Leetcode Solution285
245Find All Pairs With a Given Difference283
246Searching a node in a Binary Search Tree283
247Triplet from three linked lists with given sum280
248Delete a Tree280
249String(represents an integer) to value278
250Print all Possible Ways to Break a String in Bracket Form277
251Reverse a String276
252Reverse Bits275
253Binary Tree273
254Word Search Leetcode Solution273
255Delete a node under given conditions272
256How to Efficiently Implement k Stacks in a Single Array?272
257Change Gender of a given String271
258Sort an array of strings270
259Meeting Rooms II LeetCode Solution269
260Count Pairs With Given Sum269
261Number of sub-strings which recursively add up to 9268
262First non Repeating Element267
263Longest Common Extension267
264Remove middle points in a linked list of line segments266
265Repeated Substring Pattern263
266Toeplitz Matrix263
267Remove spaces from a string262
268Move all negative elements to one side of array262
269Longest Palindromic Substring LeetCode Solution262
270Shuffle a given Array258
271Min Stack257
272N queen problem257
273Number of Islands LeetCode Solution252
274Dijkstra Algorithm251
275Find, second, frequent, character251
276House Robber Leetcode Solution250
277Cuckoo sequence program250
278Clone a linked list with next and random pointer (Hashing)248
279Max stack248
280Most Frequent Element in an Array247
281Search Insert Position Leetcode Solution246
282Expression Evaluation245
283Minimize the maximum difference between the heights245
284Sort linked which is sorted on absolute values245
285KMP Algorithm242
286Subset Leetcode242
287Plus One Leetcode Solution242
288Valid Palindrome Leetcode Solution241
289Evaluation of Postfix Expression240
290Fibonacci numbers240
291Word Search239
292Min Stack Leetcode Solution239
293Sudoku Solver239
294Reverse words in a string239
295How to Delete a Linked List238
296Combination Sum Leetcode Solution237
297Number Of 1 bits236
298Merge Sorted Arrays Leetcode Solution233
299Sqrt(x) Leetcode Solution232
300Subarray with 0 sum230
301Set Matrix Zeroes230
302Backspace String Compare230
303Rabin Karp Algorithm228
304Contains Duplicate II Leetcode Solution228
305Reversing a Queue228
306Pair of Positive Negative Values in an Array227
307Tower Of Hanoi225
308Product of array except self225
309Combination Sum224
310Pascal Triangle Leetcode224
311Common elements in all rows of a given matrix223
312Integer to Roman Leetcode Solution223
313String Compression222
314Intersection of Two Arrays II Leetcode Solution222
315Delete middle element of a stack222
316Count subarrays with equal number of 1’s and 0’s221
317Minimum swaps required to bring all elements less than or equal to k together220
318Reverse individual words218
319Sliding Window Technique217
320Arithmetic Expression Evaluation217
321Pow(x, n) Leetcode Solution217
322Implementation of Deque using Doubly Linked List217
323Segregate even and odd numbers217
324Single Number Leetcode Solution217
325Add Binary Leetcode Solution217
326Construct Binary Tree from Given Inorder and Preorder Traversals216
327Second Most Repeated Word in a Sequence216
328Find Top K (or Most Frequent) Numbers in a Stream216
329Bellman Ford Algorithm216
330Count of index pairs with equal elements in an array215
331Palindrome Linked List Leetcode Solution215
332Design a stack that supports getMin() in O(1) time and O(1) extra space213
333Count Odd Numbers in an Interval Range Leetcode Solution213
334Next Permutation213
335Minimum Value to Get Positive Step by Step Sum Leetcode Solution212
336Maximum Number of Balloons Leetcode Solution212
337Contains Duplicate212
338Kruskal Algorithm211
339Page Replacement Algorithms in Operating Systems211
340Third Maximum Number Leetcode Solution211
341Postfix to Infix Conversion210
342Sort elements by frequency210
343Find Lucky Integer in an Array Leetcode Solution209
344Find sum of non-repeating elements (distinct) elements in an array209
345Permutations Leetcode Solution208
346K-th Smallest Element in a Sorted Matrix208
347Longest Common Prefix Leetcode Solution208
348Group Words With Same Set of Characters207
349Find the Town Judge Leetcode Solution207
350Convex Hull Algorithm207
351Majority Element Leetcode Solution206
352Find Numbers with Even Number of Digits Leetcode Solution206
353Sum of minimum and maximum elements of all subarrays of size k206
354Longest Substring Without Repeating Characters LeetCode Solution206
355Maximum Subarray206
356Sorting array using Stacks204
357Scramble String204
358Minimum operation to make all elements equal in array204
359Swap Nodes in Pairs Leetcode Solutions204
360Spiral Matrix LeetCode Solution204
361Count Primes Leetcode Solutions203
362Smallest Subarray with k Distinct Numbers203
363Top K Frequent Words203
364First element occurring k times in an array203
365Special Number202
366Check if two arrays are equal or not202
367Count subarrays having total distinct elements same as original array202
368Given two unsorted arrays find all pairs whose sum is x201
369Evaluate Division201
370Minimum Path Sum200
371Prefix to Infix Conversion200
372Merge Two Sorted Lists Leetcode Solutions200
373Pascal’s Triangle II Leetcode Solution200
374Number of Good Pairs Leetcode Solution200
375Power of Two Leetcode Solution200
376Best Time to Buy and Sell Stock  II Leetcode Solution200
377Reverse a Number Using Stack199
378Fizz Buzz Leetcode199
379Find All Numbers Disappeared in an Array Leetcode Solution198
380Reversing the First K elements of a Queue198
381Search in Rotated Sorted Array Leetcode Solution198
382Group Anagrams198
383House Robber II Leetcode Solution198
384Maximal Square197
385Missing Number Leetcode Solution197
386Minimum Steps to reach target by a Knight197
387Find duplicates in a given array when elements are not limited to a range197
388Minimum Absolute Difference Leetcode Solution196
389Leetcode Permutations196
390Huffman Coding196
391Matrix Diagonal Sum Leetcode Solution196
392Maximum possible difference of two subsets of an array196
393Running Sum of 1d Array Leetcode Solution195
394Unique Paths Leetcode Solution195
395Coin Change 2 Leetcode Solution195
396Top K Frequent Elements195
397How to Implement Stack Using Priority Queue or Heap?195
398Maximum Distance Between two Occurrences of Same Element in Array195
399Expression Contains Redundant Bracket or Not194
400Check if Array Contains Contiguous Integers With Duplicates Allowed194
401Sorting using trivial hash function193
402How Many Numbers Are Smaller Than the Current Number Leetcode Solution193
403Max Consecutive Ones Leetcode Solution193
404Single Number193
405Find The Duplicate Number193
406Remove Duplicates from Sorted Array Leetcode Solution193
407Subarray Sum Equals k192
408Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution192
409Unique Paths192
410Sort Integers by The Number of 1 Bit Leetcode Solution192
411Decode String192
412Length of the largest subarray with contiguous elements192
413Sort Array by Increasing Frequency Leetcode Solution192
414Range Sum Query 2D – Immutable Leetcode Solution192
415Happy Number Leetcode Solution191
416Find Number of Employees Under every Employee191
417Fibonacci Number LeetCode Solution191
418Subarray Sum Equals K LeetCode Solution191
419Smallest Element Repeated Exactly K Times191
420Subtract the Product and Sum of Digits of an Integer Leetcode Solution190
421Find Winner on a Tic Tac Toe Game Leetcode Solution190
422Find the Closest Palindrome number190
423Reverse Integer190
424Zigzag Conversion190
425Monotonic Array LeetCode Solution190
426Find Median from data Stream190
427Reverse Vowels of a String Leetcode Solution190
428Difference between highest and least frequencies in an array189
429Shuffle the Array Leetcode Solution189
430Cumulative Frequency of Count of Each Element in an Unsorted Array189
431Subset sum problem189
432Delete a Node from linked list without head pointer189
433Nth Catalan Number189
434Palindrome Substring Queries188
435LRU Cache Implementation188
436Check If N and Its Double Exist Leetcode Solution188
437Trapping Rain Water Leetcode Solution188
438Implement Stack and Queue using Deque188
439Best Time to Buy and Sell Stock III Leetcode Solution188
440Count Substrings with equal number of 0s, 1s and 2s188
441Letter Case Permutation187
442Find top three repeated in array187
443Maximum Depth of Binary Tree Leetcode Solution187
444Subarrays with distinct elements187
445Reverse Words in a String III LeetCode Solution187
446Print All Distinct Elements of a Given Integer Array187
447Convert String To Int187
448Find all pairs (a, b) in an array such that a % b = k186
449Sort a stack using recursion186
450Kth largest element in an Array Leetcode Solutions186
451The K Weakest Rows in a Matrix Leetcode Solution186
452Find the Duplicate Element186
453Capacity To Ship Packages Within D Days Leetcode Solution186
454Integer to English words186
455Minimum Moves to Equal Array Elements Leetcode Solution186
456Bipartite Graph185
457Excel Sheet Column Number Leetcode Solution185
458Iterative Tower of Hanoi185
459Find the first repeating element in an array of integers185
460Reverse a Stack Using Recursion185
461Count pairs from two linked lists whose sum is equal to a given value184
462Prim’s Algorithm184
463Concatenation of Array LeetCode Solution184
464Generate a String With Characters That Have Odd Counts Leetcode Solution184
465Sorting a Queue without Extra Space184
466Find Minimum In Rotated Sorted Array184
467Merge Two Sorted Linked Lists184
468Priority Queue Using Singly Linked List183
469Find First and Last Position of Element in Sorted Array Leetcode Solution183
470Floyd Warshall Algorithm183
471Find the Difference Leetcode Solution183
472Flood Fill LeetCode182
473Move Zeroes LeetCode Solution182
474Word Ladder LeetCode Solution182
475Longest Common Subsequence182
476Find Common Characters Leetcode Solution182
477Sum of Subarray Ranges Leetcode Solution182
478Reverse a String182
479Kth Largest Element in a Stream Leetcode Solution182
480Merge Overlapping Intervals182
481Slowest Key Leetcode Solution182
482Edit Distance182
483Multiply Strings Leetcode Solution182
484Next Greater Element I Leetcode Solution182
485Count and Say181
486Balanced Binary Tree Leetcode Solution181
487Kids With the Greatest Number of Candies Leetcode Solution181
488Number of Steps to Reduce a Number to Zero Leetcode Solution181
489Remove Minimum Number of Elements Such That no Common Element Exist in both Array181
490Find elements which are present in first array and not in second181
491Text Justification LeetCode Solution181
492Fizz Buzz181
493Print all subarrays with 0 sum180
494Top View of Binary Tree180
495Target Sum180
496Degree of an array180
497Zigzag Conversion LeetCode Solution180
498Reverse a linked list180
499Longest Common Prefix using Trie180
500MiniMax Algorithm180
501Design Parking System Leetcode Solution179
502Jump Game Leetcode Solution179
503Convert array into Zig-Zag fashion179
504Longest subarray not having more than K distinct elements178
505Pair with given product178
506Intersection of Two Arrays178
507Peak Index in a Mountain Array178
508Count and Say Leetcode Solution178
509Find subarray with given sum (Handles Negative Numbers)178
510Max Area of Island177
511Valid Parenthesis String177
512Check if a given array contains duplicate elements within k distance from each other177
513Priority Queue in C++177
514Last Stone Weight177
515Length of Last Word Leetcode Solution177
516Koko Eating Bananas Leetcode Solution176
517Shuffle String Leetcode Solution176
518Shortest Palindrome176
519Find Index of Closing Bracket for a Given Opening Bracket in an Expression176
520Prefix to Postfix Conversion176
521Find four elements that sum to a given value (Hashmap)176
522Find missing elements of a range176
523The Stock Span Problem176
524Contiguous Array Leetcode176
525Postfix to Prefix Conversion176
526Find N Unique Integers Sum up to Zero Leetcode Solution176
527Find distinct elements common to all rows of a matrix175
528Substring With Concatenation Of All Words175
529Longest Common Prefix using Sorting175
530Mobile Numeric Keypad Problem175
531Largest Perimeter Triangle Leetcode Solution174
532Iterative Inorder Traversal of a Binary Tree174
534Count number of triplets with product equal to given number174
535K-th Distinct Element in an Array174
536Find any one of the multiple repeating elements in read only array174
537N-th Tribonacci Number Leetcode Solution174
538Delete Node in a Linked List Leetcode Solution174
539Smallest Subarray With all Occurrences of a Most Frequent Element174
540Relative Sort Array Leetcode Solution174
541Implementation of Deque using circular array174
542Implement a stack using single queue174
543Best Time to Buy and Sell Stock173
544Is Subsequence Leetcode Solution173
545Valid Anagrams173
546Container with Most Water173
547Minimum Operations to convert X to Y173
548Valid Sudoku173
549Excel Sheet Column Title Leetcode Solution173
550Implement Stack using Queues173
551Build Array From Permutation Leetcode Solution173
55201 Matrix LeetCode Solution172
553Next Greater Frequency Element172
554Distribute Candies to People Leetcode Solution172
555Linked List Cycle II LeetCode Solution172
556Jewels and Stones Leetcode Solution172
557Maximum sum rectangle in a 2D matrix172
558Island Perimeter Leetcode Solution172
559Convert Sorted Array to Binary Search Tree Leetcode Solution172
560Sum of Left Leaves Leetcode Solutions172
561Isomorphic Strings Leetcode Solution172
562First negative integer in every window of size k172
563Find Words That Can Be Formed by Characters Leetcode Solution171
564Convert a normal BST to Balanced BST171
565Trapping Rain Water LeetCode Solution171
566Remove Linked List Elements Leetcode Solution171
567Minimum Delete Operations to make all Elements of Array Same171
568Minimum Bracket Reversals170
569Hamming Distance170
570Arrange given numbers to form the biggest number170
571Rearrange a binary string as alternate x and y occurrences170
572Gold Mine Problem170
573Insert Interval Leetcode Solution170
574Count the number of nodes at given level in a tree using BFS170
575Shuffle an Array170
576Assign Cookies Leetcode Solution170
577The Knapsack Problem169
578Count all subsequences having product less than K169
579Integer to Roman169
5803Sum Closest LeetCode Solution169
581Check for Balanced Parentheses in an Expression169
582Maximum path sum in a triangle169
583Find the smallest positive integer value that cannot be represented as sum of any subset of a given array169
584Rotate List Leetcode Solution168
585Group Multiple Occurrence of Array Elements Ordered by first Occurrence168
586Summary Ranges Leetcode Solution168
587Shortest Path in a Grid with Obstacles Elimination LeetCode Solution168
588Minimum Knight Moves LeetCode Solution168
589LRU Cache LeetCode Solution168
590Change the Array into Permutation of Numbers From 1 to N168
591Minimum number of distinct elements after removing m items168
592Unique Binary Search Trees167
593XOR Operation in an Array Leetcode Solution167
594Decode Ways167
595K Empty Slots LeetCode167
596How to check if two given sets are disjoint?167
597Permutation in String Leetcode Solution167
598Same Tree LeetCode Solution166
599Distance Between Bus Stops Leetcode Solution166
600Combinations Leetcode Solution166
601Sieve of Eratosthenes166
602Remove All Occurrences of a Substring LeetCode Solution166
603Maximum Distance in Array166
604Printing brackets in Matrix Chain Multiplication Problem166
605Find if an Expression has Duplicate Parenthesis or Not166
606Rotate Image LeetCode Solution166
607Find minimum difference between any two elements165
608Sort Characters By Frequency LeetCode Solution165
609License Key Formatting Leetcode Solution165
610Segregate 0s and 1s in an Array165
611Stone Game LeetCode165
612Frog Jump Leetcode Solution165
613Maximum difference between first and last indexes of an element in array165
614Word Pattern165
615Painting Fence Algorithm164
616Replace Elements with Greatest Element on Right Side Leetcode Solution164
617Word Wrap Problem164
618Best Time to Buy and Sell Stock LeetCode Solution164
619Minimum number of subsets with distinct elements164
620Find the Duplicate Number LeetCode Solution164
621Find Sum of all unique sub-array sum for a given array164
622Minimum insertions to form a palindrome with permutations allowed164
623Applications of Breadth First Search and Depth First Search163
624Defanging an IP Address Leetcode Solution163
625Sort Array By Parity LeetCode Solution163
626Longest Substring with At Most K Distinct Characters LeetCode Solution163
627Minimum Depth of Binary Tree Leetcode Solution163
628Smallest Good Base163
629Maximum Number of Chocolates to be Distributed Equally Among k Students163
630House Robber162
631Coin Change Problem162
632Distance of nearest cell having 1 in a binary matrix162
633Find Maximum Level sum in Binary Tree162
634Kth Missing Positive Number Leetcode Solution162
635Valid Palindrome II Leetcode Solution161
636Iterative Method to find Height of Binary Tree161
637Tracking current Maximum Element in a Stack161
638Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest161
639Minimum Cost to Hire K Workers161
640Isomorphic Strings160
641Reverse a stack without using extra space in O(n)160
642GCD Of Two Numbers160
643Longest Increasing Subsequence160
644Delete consecutive same words in a sequence160
645Count Good Nodes in Binary Tree Leetcode Solution160
646Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions160
647Non-overlapping sum of two sets160
648Power of Four Leetcode Solution160
649Maximum Consecutive Numbers Present in an Array160
650Sum of All Odd Length Subarrays Leetcode Solution160
651Optimal Account Balancing LeetCode Solution160
652Binary Tree Zigzag Level Order Traversal LeetCode Solution160
653Merge Two Balanced Binary Search Trees159
654Best Time to Buy and Sell Stock with Cooldown Leetcode Solution159
655Ugly Number Leetcode Solution159
656Moving Average from Data Stream Leetcode Solution159
657Number of Provinces Leetcode Solution159
658Check If Two String Arrays are Equivalent Leetcode Solution159
659Convert an array to reduced form159
660Check If It Is a Straight Line Leetcode Solution159
661K Empty Slots159
662Largest Sum Contiguous Subarray158
663Maximum Number of Coins You Can Get Leetcode Solution158
664Wiggle Sort158
665Check if a queue can be sorted into another queue using a stack158
666Reverse Only Letters LeetCode Solution158
667Strobogrammatic Number LeetCode Solution158
668String to Integer (atoi) LeetCode Solution158
669Employee Free Time LeetCode Solution158
670Number of Dice Rolls With Target Sum LeetCode Solution158
671Flipping an Image LeetCode Solution158
672Letter Combinations of a Phone Number158
673Queries for counts of array elements with values in given range158
674Longest Increasing Path in a Matrix LeetCode Solution157
675Reorganize String157
676Reducing Dishes LeetCode Solution157
677Path With Maximum Minimum Value LeetCode Solution157
678Inorder Successor of a node in Binary Tree157
679Construct BST from given Preorder Traversal157
680Sum of f(a[i], a[j]) over all pairs in an array of n integers157
681Subset Sum Leetcode157
682Print the Fibonacci numbers in reverse order157
683Longest Substring with At Least K Repeating Characters LeetCode Solution157
684Form minimum number from given sequence157
685Find the Smallest Divisor given a Threshold Leetcode Solution157
686Find Largest d in Array such that a + b + c = d157
687How to Create Mergable Stack?157
688To Lower Case Leetcode Solution157
689Increasing Decreasing String Leetcode Solution157
690Lucky Numbers in a Matrix Leetcode Solution157
691Partition Labels LeetCode Solution157
692Find Leaves of Binary Tree LeetCode Solution156
693Valid Perfect Square Leetcode Solution156
694Valid Palindrome156
695Unique Paths II Leetcode Solution156
696Find whether an array is subset of another array156
697Maximum Number of Occurrences of a Substring Leetcode Solution156
698Robot Room Cleaner Leetcode Solution156
699Reversing a Queue using Recursion156
700Find the Distance Value Between Two Arrays Leetcode Solution156
701Populating Next Right Pointers in Each Node155
702Delete Nth node from the end of the given linked list155
703Find pairs with given sum such that elements of pair are in different rows155
704Permutation Sequence LeetCode Solution155
705Partition Array Into Three Parts With Equal Sum Leetcode Solution155
706Merge Two Binary Trees LeetCode Solution155
707Recover Binary Search Tree155
708Maximum Product of Two Elements in an Array Leetcode Solution155
709Keyboard Row Leetcode Solution155
710Dynamic Programming Basics155
711BFS vs DFS for Binary Tree155
712Remove Invalid Parentheses Leetcode Solution155
713Majority Element II Leetcode Solution155
714Reservoir Sampling155
715Binary Tree zigzag level order Traversal155
716Edit Distance LeetCode Solution155
717Hamming Distance Leetcode Solution154
718Sort Array by Increasing Frequency Leetcode Solution154
719Find the node with minimum value in a Binary Search Tree154
720Add and Search Word – Data structure design LeetCode154
721Rank Transform of an Array Leetcode Solution154
722Restore IP Addresses Leetcode Solution154
723Maximum Product of Three Numbers LeetCode Solution154
724Decompress Run-Length Encoded List Leetcode Solution154
725Factorial Trailing Zeroes Leetcode Solution153
726Numbers with prime frequencies greater than or equal to k153
727String Compression LeetCode Solution153
728Stack Permutations (Check if an array is stack permutation of other)153
729Convert a Number to Hexadecimal Leetcode Solution153
730Best Meeting Point LeetCode Solution152
731Binary Tree Maximum Path Sum LeetCode Solution152
732Find unique character in a string152
733Find the largest multiple of 3152
734Bulb Switcher LeetCode Solution152
735Deletion in a Binary Tree152
736Sorted Linked List to Balanced BST152
737Symmetric Tree Leetcode Solution152
738Longest Span with same Sum in two Binary arrays152
739Queue based approach for first non-repeating character in a stream152
740Find Maximum Depth of Nested Parenthesis in a String151
741Maximum 69 Number Leetcode Solution151
742Minimum Distance Between BST Nodes Leetcode Solution151
743Find All Duplicates in an Array LeetCode Solution151
744Race Car LeetCode Solution151
745Search in a Binary Search Tree Leetcode Solution151
746Check If Array Pairs Are Divisible by k LeetCode Solution151
747Non-decreasing Array LeetCode Solution151
748Word Pattern LeetCode Solution151
749Generate all possible sorted arrays from alternate elements of two given sorted arrays151
750Finding K closest element151
751Minimum Cost For Tickets Leetcode Solution151
752Find Median from Data Stream LeetCode Solution151
753Minimum Height Trees151
754Binomial Coefficient151
755Largest subarray with equal number of 0s and 1s151
756Invert Binary Tree LeetCode Solution151
757Linked List Cycle151
758First Unique Character in a String LeetCode Solution150
759Find if Path Exists in Graph Leetcode Solution150
760Find Pair with Greatest Product in Array150
761Search a 2D Matrix II Leetcode Solution150
762Maximum Length of a Concatenated String with Unique Characters Leetcode Solution150
763Bubble sort using two Stacks150
764Perform String Shifts Leetcode150
765k-th missing element in increasing sequence which is not present in a given sequence150
766Number of Islands II LeetCode Solution150
767Maximum Depth of N-ary Tree Leetcode Solution150
768Remove Duplicates from Sorted List LeetCode Solution150
769Minimize Maximum Pair Sum in Array LeetCode Solution150
770Student Attendance Record I Leetcode Solution150
771N-Queens LeetCode Solution150
772Remove Nth Node From End of List Leetcode Solution150
773Count quadruples from four sorted arrays whose sum is equal to a given value x150
774Kth ancestor of a node in binary tree149
775Largest rectangular sub-matrix whose sum is 0149
776Morris Traversal149
777Evaluate Reverse Polish Notation LeetCode Solution149
778Maximum Difference Between Increasing Elements LeetCode Solution149
779Growable array based stack149
780Merge K Sorted Linked Lists149
781Diagonal Traversal of Binary Tree149
782Split a String in Balanced Strings Leetcode Solution149
783Elements to be added so that all elements of a range are present in array149
784Jump Game149
785Minimum number of jumps to reach end148
786Minimum time required to rot all oranges148
787Snakes and Ladders LeetCode Solution148
788Transpose Graph148
789Largest Rectangle in Histogram LeetCode Solution148
790Minimum Time Visiting All Points Leetcode Solution148
791Final Prices With a Special Discount in a Shop Leetcode Solution148
792Remove brackets from an algebraic string containing + and – operators148
793Valid Number148
794Program for Bridge and Torch problem148
795Number Complement Leetcode Solution148
796Relative Ranks Leetcode Solution147
797Remove Duplicates from Sorted List II147
798Crawler Log Folder Leetcode Solution147
799Nested List Weight Sum II LeetCode Solution147
800Check if Two Expressions With Brackets are Same147
801Nearest Exit from Entrance in Maze LeetCode Solution147
802Special Array With X Elements Greater Than or Equal X Leetcode Solution147
803Get Maximum in Generated Array Leetcode Solution147
804Count items common to both the lists but with different prices147
805Sort an array according to the order defined by another array147
806Number of NGEs to the Right147
807Tiling Problem147
808Merge Sorted Array LeetCode Solution147
809Check for Palindrome after every character replacement Query147
810Minimum Jumps to Reach Home LeetCode Solution147
811Subarray Product Less Than K LeetCode Solution146
812Regular Expression Matching146
813Base 7 Leetcode Solution146
814Circular Queue146
815A Space Optimized DP solution for 0-1 Knapsack Problem146
816String comparison containing wildcards146
817Reorder Data in Log Files LeetCode Solution146
818Partition to K Equal Sum Subsets Leetcode Solution146
819Minimum Number of Taps to Open to Water a Garden LeetCode Solution146
820Interval Tree146
821Print a Binary Tree in Vertical Order146
822Friends Pairing Problem146
823One Edit Distance LeetCode Solution146
824Sort Colors146
825Sort Array By Parity II Leetcode Solution146
826Convert BST to Min Heap146
827Longest Subarray Having Count of 1s One More than Count of 0s146
828Priority Queue using doubly linked list145
829Find the subarray with least average145
830Path with maximum average value145
831Clone Graph LeetCode Solution145
832Alien Dictionary LeetCode Solution145
833Sorted Array to Balanced BST145
834Minimum swaps to make sequences increasing145
835Check if a given array can represent Preorder Traversal of Binary Search Tree145
836Maximum Profit in Job Scheduling Leetcode Solution145
837Maximum size subarray sum equals k145
838Subsequence of Size K With the Largest Even Sum LeetCode Solution145
839Find the Only Repetitive Element Between 1 to N-1144
840Course Schedule II – LeetCode144
841Guess Number Higher or Lower LeetCode Solution144
842Brightest Position on Street LeetCode Solution144
843Minimum Swaps to Make Strings Equal Leetcode Solution144
844Last Stone Weight II LeetCode Solution144
845Iterative Preorder Traversal144
846Level order Traversal in Spiral Form144
847Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution144
848Count Distinct Elements in Every Window of Size K144
849Insert into a Binary Search Tree Leetcode Solution144
850Design a Stack With Increment Operation Leetcode Solution144
851Partition List Leetcode Solution144
852Total Numbers With no Repeated Digits in a Range144
853Permutation Coefficient143
854Valid Parentheses Leetcode Solution143
855Minimum Sum Path in a Triangle143
856Can Place Flowers LeetCode Solution143
857Union and Intersection of two Linked Lists143
858Find all triplets with zero sum143
859Maximum Nesting Depth of the Parentheses Leetcode Solution143
860Check if an Array is Stack Sortable143
861Repeated Substring Pattern LeetCode Solution143
862Top K Frequent Words LeetCode Solution143
863Subset with sum divisible by m143
864Brick Wall LeetCode Solution143
865Given an Array of Pairs Find all Symmetric Pairs in it142
866Check whether a given Binary Tree is Complete or not142
867Water Bottles Leetcode Solution142
868Form Minimum Number From Given Sequence142
869Lemonade Change Leetcode Solution142
870Three way partitioning of an array around a given range142
871Find All Possible Recipes from Given Supplies LeetCode Solution142
872Binary Search Tree Search and Insertion141
873Rearrange Spaces Between Words Leetcode Solution141
874LCS (Longest Common Subsequence) of three strings141
875Least Number of Unique Integers after K Removals Leetcode Solution141
876Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution141
877Daily Temperatures Leetcode Solution141
878Tree Traversal (Preorder, Inorder & Postorder)141
879Matrix Chain Multiplication141
880Range sum queries without updates141
881Count ways to reach the nth stair using step 1, 2 or 3141
882Spiral Matrix II Leetcode Solution141
884Design Browser History LeetCode Solution141
885Sum of nearest smaller and greater number141
886GCDs of given index ranges in an array141
887Balanced Expression with Replacement141
888Special Positions in a Binary Matrix Leetcode Solution140
889Construct Complete Binary Tree from its Linked List Representation140
890Diagonal Traversal LeetCode Solution140
891Identify and Mark Unmatched Parenthesis in an Expression140
892An Interesting Method to generate Binary Numbers from 1 to n140
893BFS for Disconnected Graph140
894Maximum Score After Splitting a String Leetcode Solution140
895Queries for GCD of all numbers of an array except elements in a given range140
896Count Negative Numbers in a Sorted Matrix LeetCode Solution140
897Robot Bounded In Circle LeetCode Solution140
898Missing Element in Sorted Array LeetCode Solution140
899Destination City Leetcode Solution140
900Delete And Earn140
901Count Subarrays with Same Even and Odd Elements140
902Find all permuted rows of a given row in a matrix140
903Sequences of given length where every element is more than or equal to twice of previous140
904Shortest Word Distance Leetcode Solution140
905Number of Days Between Two Dates LeetCode Solution140
906Find Maximum Sum Possible Equal Sum of Three Stacks140
907Distinct adjacent elements in an array140
908Guess Number Higher or Lower II140
909Insert Delete GetRandom140
910Convert Sorted List to Binary Search Tree139
911Check if the given array can represent Level Order Traversal of Binary Search Tree139
912Rearrange an Array Such that arr[i] is equal to i139
913Alien Dictionary139
914Time Based Key-Value Store LeetCode Solution139
915Check if stack elements are pairwise consecutive139
916Set Matrix Zeroes Leetcode Solution139
917Minimum sum of multiplications of n numbers139
918A program to check if a binary tree is BST or not139
919Range LCM Queries138
920Palindrome Partitioning Leetcode Solution138
921Analyze User Website Visit Pattern LeetCode Solution138
922Number of Distinct Islands Leetcode Solution138
923Vertical sum in a given binary tree138
924Find Common Characters Leetcode Solution138
925Diagonal Traverse LeetCode Solution138
926Find distance between two nodes of a Binary Tree138
927Merging Intervals137
928Spiral Matrix III LeetCode Solution137
929Remove Duplicates from Sorted List II LeetCode Solution137
930Longest Palindromic Subsequence137
931Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i137
932Merge Two Sorted Lists Leetcode137
933Stone Game II Leetcode137
934Maximize Sum of Array after K Negations Leetcode Solution136
935Maximum Subarray Sum Excluding Certain Elements136
936Three Consecutive Odds Leetcode Solution136
937Strongly Connected Component136
938Largest area rectangular sub-matrix with equal number of 1’s and 0’s136
9393 Sum136
940Averages of Levels in Binary Tree136
941Maximum Frequency Stack Leetcode Solution136
942Sliding Window Maximum136
943Word Break136
944Construct the Rectangle Leetcode Solution136
945Can Make Arithmetic Progression From Sequence Leetcode Solution136
946Queue using Stacks136
947K’th Largest Element in BST when modification to BST is not allowed136
948Number of Equivalent Domino Pairs Leetcode Solution136
949Lexicographical Numbers Leetcode Solution136
950Print Fibonacci sequence using 2 variables136
951Infix to Postfix136
952Intersection of Two Linked Lists LeetCode Solution136
953Count Submatrices With All Ones LeetCode Solution135
954Pattern Occurrences using Stack135
955Difference Array | Range update query in O(1)135
956Trim a Binary Search Tree135
957All Unique Triplets that Sum up to a Given Value135
958Binary array after M range toggle operations135
959Median of Two Sorted Arrays135
960Minimum Height Trees LeetCode Solution135
961Breadth First Search (BFS) for a Graph135
962Dividing Array into Pairs With Sum Divisible by K135
963Check if any two intervals overlap among a given set of intervals135
964Reverse Nodes in K-Group135
965Binary Tree Longest Consecutive Sequence LeetCode Solution135
966Construct BST from its given Level Order Traversal135
967Largest divisible pairs subset134
968Find Maximum of Minimum for Every Window Size in a Given Array134
969Largest Substring Between Two Equal Characters Leetcode Solution134
970Symmetric Tree134
971Height of a generic tree from parent array134
972Split Array Into Consecutive Subsequences134
973Palindrome Partitioning134
974Count Primes in Ranges134
975Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution134
976Find postorder traversal of BST from preorder traversal134
977Newman-Conway Sequence134
978K Closest Points to Origin Leetcode Solution133
979Kth Smallest Element in a BST Leetcode Solution133
980Product of Array Except Self LeetCode Solution133
981Sign of the Product of an Array LeetCode Solution133
982Depth First Search (DFS) for a Graph133
983Asteroid Collision LeetCode Solution133
984Create Maximum Number133
985Minesweeper LeetCode Solution133
986Find Duplicate Subtrees133
987Iterative Postorder Traversal Using Two Stacks133
988Binary Search Tree Delete Operation133
989Count pair with Given Sum133
990Segment Tree133
991First missing positive133
992Maximum Product Subarray133
993Shuffle 2n integers as without using extra space133
994The Painter’s Partition Problem132
995The Maze III LeetCode Solution132
996Level Order Traversal of Binary Tree132
997Serialize and Deserialize Binary Tree132
998My Calendar I LeetCode Solution132
999Boundary Traversal of binary tree132
1000Rearrange array such that even positioned are greater than odd132
1001Kill Process LeetCode Solution132
1002Find the Difference Leetcode Solution132
1003Unique Paths II132
1004Climbing stairs132
1005Length of Longest Fibonacci Subsequence132
1006Find the First Circular Tour that visits all the Petrol Pumps132
1007Maximum subsequence sum such that no three are consecutive132
1008Decrypt String from Alphabet to Integer Mapping Leetcode Solution131
1009Maximum Number of Ways to Partition an Array LeetCode Solution131
1010Build an Array With Stack Operations Leetcode Solution131
1011Longest subsequence such that difference between adjacents is one131
1012Next Greater Element III LeetCode Solution131
1013Count subarrays where second highest lie before highest131
1014Double the first element and move zero to end131
1015Partition Equal Subset Sum131
1016Longest Nice Substring LeetCode Solution131
1017Graph Valid Tree LeetCode Solution131
1018Make The String Great Leetcode Solution131
1019Boolean Parenthesization Problem130
1020Level order traversal using two Queues130
1021Super Ugly Number130
1022Insertion in a Binary Tree130
1023Morris Inorder Traversal130
1024Maximum Length of Repeated Subarray130
1025Valid Boomerang Leetcode Solution130
1026Collect maximum points in a grid using two traversals130
1027Shortest Completing Word Leetcode Solution130
1028Largest Number Leetcode Solution130
1029Find number of pairs in an array such that their XOR is 0130
1030Recover Binary Search Tree Leetcode Solution129
1031Friends Of Appropriate Ages LeetCode Solution129
1032Compute nCr % p129
1033Ugly Number II LeetCode Solution129
1034String Matching in an Array Leetcode Solution129
1035Binary Search Tree129
1036Advantages of BST over Hash Table129
1037Number Of Longest Increasing Subsequence129
1038Design Hit Counter LeetCode Solution129
1039Balanced Binary Tree129
1040Minimum Size Subarray Sum128
1041Invalid Transactions LeetCode Solution128
1042Number of palindromic paths in a matrix128
1043Employee Importance LeetCode Solution128
1044Construct Binary Tree from given Parent Array representation128
1045Implement Trie (Prefix Tree) Leetcode Solution128
1046Ugly Numbers128
1047Maximum length subsequence with difference between adjacent elements as either 0 or 1128
1048Move all negative elements to end in order with extra space allowed128
1049Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’128
1050Defanging an IP Address LeetCode Solution128
1051Validate Binary Search Tree128
1052Kth Smallest Element in a Sorted Matrix LeetCode Solution128
1053Scramble String LeetCode Solution128
1054Construction of Longest Increasing Subsequence (N log N)128
1055Maximum Product of Indexes of Next Greater on Left and Right128
1056Available Captures for Rook Leetcode Solution128
1057Maximum weight transformation of a given string127
1058Count minimum steps to get the given desired array127
1059Populating Next Right Pointers in Each Node Leetcode Solution127
1060Longest Bitonic Subsequence127
1061Find Peak Element127
1062Increasing Triplet Subsequence LeetCode Solution127
1063Find whether a subarray is in form of a mountain or not127
1064Regular Expression Matching Regular Expression Matching LeetCode Solution127
1065Minimum Index Sum of Two Lists127
1066Iterative Depth First Traversal of Graph127
1067Maximum difference between frequency of two elements such that element having greater frequency is also greater127
1068Maximum Sum of 3 Non-Overlapping Subarrays127
1069Add two numbers127
1070Generate Parentheses Leetcode Solution126
1071Remove Duplicates from Sorted Array II Leetcode Solution126
1072Divisible Pairs Counting126
1073Clone a Binary Tree with Random Pointers126
1074Custom Sort String Leetcode Solution126
1075Count pairs from two sorted arrays whose sum is equal to a given value x126
1076Bitwise AND of Numbers Range LeetCode Solution126
1077Maximize Distance to Closest Person LeetCode Solution126
1078Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution126
1079Day of the Year Leetcode Solution126
1080Path Sum II LeetCode Solution126
1081Combination Sum IV LeetCode Solution126
1082Find a Peak Element II LeetCode Solution126
1083Lowest Common Ancestor126
1084Find the minimum distance between two numbers126
1085Binary Tree Right Side View LeetCode Solution125
1086Smallest Common Region Leetcode Solution125
1087Number of Closed Islands Leetcode Solution125
1088Search in Sorted Rotated Array125
1089Path Sum125
1090Binary Tree Data Structure125
1091Largest BST Subtree LeetCode Solution125
1092Consecutive Characters LeetCode Solution124
1093Number of Students Doing Homework at a Given Time Leetcode Solution124
1094Types of Binary Tree124
1095Subarrays with K Different Integers Leetcode Solution124
1096Find maximum difference between nearest left and right smaller elements124
1097Print all triplets in sorted array that form AP124
1098Find Smallest Range Containing Elements from k Lists124
1099Rearrange array such that even index elements are smaller and odd index elements are greater124
1100Kth Smallest Product of Two Sorted Arrays LeetCode Solution124
1101Next Permutation Leetcode Solution124
1102Level of Each node in a Tree from source node124
1103Print Next Greater Number of Q queries124
1104Number of siblings of a given Node in n-ary Tree124
1105Remove Palindromic Subsequences Leetcode Solution124
1106Find Three Element From Different Three Arrays Such That a + b + c = sum123
1107Serialize and Deserialize Binary Tree LeetCode Solution123
1108Third Maximum Number Leetcode Solution123
1109Distinct Subsequences123
1110Topological Sorting123
1111Bottom View of a Binary Tree122
1112Maximum Product Subarray122
1113Write Code to Determine if Two Trees are Identical122
1114Cutting a Rod122
1115Remove duplicates from sorted array122
1116Minimum Absolute Difference in BST Leetcode Solution122
1117Root to Leaf path with target sum Leetcode Solutions122
1118Constant time range add operation on an array122
1119Convert BST into a Min-Heap without using array122
1120Mean of Array After Removing Some Elements Leetcode Solution121
1121Maximum Binary Tree121
1122Count Largest Group Leetcode Solution121
1123Valid Tic-Tac-Toe State LeetCode Solution121
1124Cells with Odd Values in a Matrix LeetCode Solution121
1125Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution121
1126Print Right View of a Binary Tree121
1127Reformat The String Leetcode Solution121
1128Minimum Score Triangulation of Polygon Leetcode Solution121
1129Search Insert Position120
1130Construct K Palindrome Strings LeetCode Solution120
1131Products of ranges in an array120
1132Iterative method to find ancestors of a given binary tree120
1133Search an Element in Sorted Rotated Array120
1134Longest Subarray of 1’s After Deleting One Element LeetCode Solution120
1135Closest Binary Search Tree Value Leetcode Solution120
1136Golomb sequence120
1137Palindrome Permutation LeetCode Solution120
1138Minimum sum of squares of character counts in a given string after removing k characters120
1139Sum of Even Numbers After Queries120
1140Queries for Number of Distinct Elements in a Subarray120
1141Thousand Separator Leetcode Solution120
1142Moser-de Bruijn Sequence119
1143Print modified array after executing the commands of addition and subtraction119
1144Find a sorted subsequence of size 3 in linear time119
1145Factorial Trailing Zeroes LeetCode Solution119
1146Longest Increasing Consecutive Subsequence119
1147Prime Palindrome LeetCode Solution119
1148Red-Black Tree Introduction119
1149Binary Tree to Binary Search Tree Conversion118
1150Find maximum length Snake sequence118
1151Delete Nodes and Return Forest Leetcode Solution118
1152Bus Routes Leetcode Solution118
1153Transform a BST to Greater sum Tree118
1154Maximum Product of Splitted Binary Tree LeetCode Solution118
1155Subset Sum Problem in O(sum) space118
1156Merge two BSTs with limited extra space118
1157Count even length binary sequences with same sum of first and second half bits117
1158Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1159Kth Smallest Number in Multiplication Table Leetcode Solution117
1160K’th Largest element in BST using constant extra space117
1161Longest Repeated Subsequence117
1162Swapping Nodes in a Linked List Leetcode Solution117
1163Number of Orders in the Backlog Leetcode Solution117
1164Check Array Formation Through Concatenation Leetcode Solution117
1165Swap Nodes In Pairs117
1166Compare Strings by Frequency of the Smallest Character Leetcode Solution117
1167Possible Bipartition LeetCode Solution117
1168Find the smallest binary digit multiple of given number117
1169Decision Tree117
1170K maximum sums of overlapping contiguous sub-arrays117
1171Palindromic Substrings Leetcode Solution117
1172Rotate Array116
1173Web Crawler LeetCode Solution116
1174Minimum Cost to Move Chips to The Same Position LeetCode Solution116
1175Priority Queue116
1176Minimum Moves to Equal Array Elements LeetCode Solution116
1177Maximize sum of consecutive differences in a circular array116
1178Minimum Sideway Jumps LeetCode Solution116
1179Closest Leaf in a Binary Tree LeetCode Solution115
1180Decrease Elements To Make Array Zigzag LeetCode Solution115
1181Count Pairs Whose Products Exist in Array115
1182Search Suggestions System LeetCode Solution115
1183Find Largest Value in Each Tree Row LeetCode Solution115
1184First Bad Version115
1185Contiguous Array LeetCode Solution114
1186Queue Reconstruction by Height114
1187Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1188Moving Stones Until Consecutive Leetcode Solution114
1189Diameter of N-Ary Tree LeetCode Solution114
1190Given a binary tree, how do you remove all the half nodes?114
1191Lowest Common Ancestor in Binary Search Tree113
1192Convert Sorted Array to Binary Search Tree LeetCode Solutions113
1193Reverse a Path in BST using Queue113
1194Matchsticks to Square Leetcode Solution113
1195Kth Smallest Element in a BST113
1196Maximum sum bitonic subarray113
1197Maximum number of segments of lengths a, b and c113
1198How to print maximum number of A’s using given four keys113
1199Divide Two Integers Leetcode Solution112
1200Valid Triangle Number112
1201Reformat Date LeetCode Solution112
1202Sum of Left Leaves LeetCode Solution112
1203Array Queries for multiply replacements and product112
1204Write a function to get the intersection point of two Linked Lists112
1205Champagne Tower LeetCode Solution112
1206Integer Break LeetCode Solution112
1207Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution112
1208Maximum Depth Of Binary Tree112
1209Longest Common Prefix Using Word by Word Matching112
1210Replace two consecutive equal values with one greater111
1211Range Queries for Longest Correct Bracket Subsequence111
1212New 21 Game111
1213Maximum sum of pairs with specific difference111
1214Range Sum Query using Sparse Table111
1215Guess The Word111
1216Print modified array after multiple array range increment operations110
1217Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1218Path Crossing Leetcode Solution110
1219Symmetric Tree LeetCode Solution Leetcode Solution110
1220Arithmetic Slices II – Subsequence LeetCode Solution110
1221Concatenation of Array LeetCode Solution110
1222Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution110
1223Valid Perfect Square LeetCode Solution110
1224Design Skiplist LeetCode Solution110
1225Graph and its representation110
1226Maximum sum of a path in a Right Number Triangle109
1227Maximum Array from Two given Arrays Keeping Order Same109
1228Check if each internal node of a BST has exactly one child109
1229Minimum Swaps To Make Sequences Increasing LeetCode Solution109
1230Lowest Common Ancestor of a Binary Tree Leetcode Solution109
1231Flatten 2D Vector LeetCode Solution109
1232Check Completeness of a Binary Tree LeetCode Solution109
1233Check for Identical BSTs without building the trees109
1234The kth Factor of n Leetcode Solution109
1235Perfect Squares LeetCode Solution109
1236Merge Sort109
1237BST to a Tree with Sum of all Smaller Keys109
1238LRU Cache Leetcode Solution108
1239Power of Two108
1240Print n terms of Newman-Conway Sequence108
1241Queries on Probability of Even or Odd Number in given Ranges108
1242Sliding Window Median Leetcode Solution108
1243Parallel Courses II LeetCode Solution108
1244Mean of range in array108
1245Check if all levels of two Binary Tree are anagrams or not108
1246Count Subsets Having Distinct Even Numbers108
1247Graph Cloning107
1248Maximum Product Subarray107
1249Maximize Elements Using Another Array107
1250Count and Toggle Queries on a Binary Array107
1251Missing Number107
1252Contiguous Array107
1253Largest Plus Sign Leetcode Solution107
1254Image Overlap LeetCode Solution107
1255Find Minimum in Rotated Sorted Array II LeetCode Solution107
1256Bold Words in String LeetCode Solution106
1257Check If a String Can Break Another String Leetcode Solution106
1258Find minimum number of merge operations to make an array palindrome106
1259Find k-th smallest element in BST (Order Statistics in BST)105
1260Verify Preorder Serialization of a Binary Tree105
1261Next greater element105
1262Excel Sheet Column Title LeetCode Solution105
1263Minimum Remove to Make Valid Parentheses LeetCode Solution105
1264Print Ancestors of a Given Binary Tree Node Without Recursion104
1265Min Cost Climbing Stairs LeetCode Solution104
1266Merge k Sorted Lists Leetcode Solution104
1267Smallest Range II Leetcode Solution104
1268Minimum Time to Collect All Apples in a Tree LeetCode Solution103
1269Palindrome Partitioning103
1270Check in binary array the number represented by a subarray is odd or even102
1271Check if two nodes are on the same path in a Tree102
1272Orderly Queue LeetCode Solution101
1273Merge Sorted Array101
1274Different Ways to Add Parentheses Leetcode Solution100
1275Peeking Iterator LeetCode Solution100
1276Koko Eating Bananas LeetCode Solution100
1277Newman–Shanks–Williams prime99
1278Number of elements less than or equal to a given number in a given subarray99
1279Check if X can give change to every person in the Queue99
1280Largest Submatrix With Rearrangements LeetCode Solution97
1281Maximum Sum Increasing Subsequence97
1282Find maximum average subarray of k length97
1283Range Minimum Query (Square Root Decomposition and Sparse Table)97
1284Longest Substring Without Repeating Characters Leetcode Solution97
1285Number of indexes with equal elements in given range96
1286Queries for Decimal Values of Subarrays of a Binary Array96
1287Minimum Total Space Wasted With K Resizing Operations LeetCode Solution96
1288Maximum product of an increasing subsequence95
1289Array Nesting Leetcode Solution95
1290Check given array of size n can represent BST of n levels or not94
1291Binary Tree to Binary Search Tree Conversion using STL set94
1292Minimum Number of People to Teach LeetCode Solution94
1293Random Pick Index LeetCode Solution93
1294Arranging Coins Leetcode Solution93
1295Queries on XOR of greatest odd divisor of the range92
1296Find the Winner of the Circular Game LeetCode Solution92
1297Add Two Numbers II Leetcode Solution92
1298Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution92
1299Reach a Number LeetCode Solution92
1300Convert to Base -2 LeetCode Solution92
1301Jump Game IV LeetCode Solution92
1302Encoded String With Shortest Length LeetCode Solution92
1303Convert a BST to a Binary Tree such that sum of all greater keys is added to every key91
1304Insert Delete GetRandom O(1) Leetcode Solution90
1305Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution89
1306Palindrome Number LeetCode Solution88
1307Vertical Order Traversal of Binary Tree LeetCode Solution87
1308Design Underground System Leetcode Solution86
1309Continuous Subarray Sum LeetCode Solution86
1310Print Maximum Length Chain of Pairs84
1311Detect Capital Leetcode Solution82
1312Design A Leaderboard Leetcode Solution81
1313Top K Frequent Elements LeetCode Solution79
1314Substring with Concatenation of All Words Leetcode Solution78
1315Minimum Swaps to Group All 1’s Together Leetcode Solution78
1316Minimum Path Sum Leetcode Solution75
1317Decode String Leetcode Solution74
1318Count Sub Islands LeetCode Solution73
1319Odd Even Linked List Leetcode Solution72
1320Binary Tree Inorder Traversal LeetCode Solution72
1321Shortest Unsorted Continuous Subarray LeetCode Solution71
1322Shifting Letters LeetCode Solution71
1323Best Meeting Point LeetCode Solution71
1324Maximum Population Year LeetCode Solution71
1325Find the Town Judge LeetCode Solution70
1326Sum Root to Leaf Numbers LeetCode Solution70
1327Longest Common Subsequence LeetCode Solution70
1328Find the Town Judge LeetCode Solution68
1329Design Add and Search Words Data Structure LeetCode Solution67
1330Rectangle Overlap LeetCode Solution66
1331Maximum Population Year LeetCode Solution66
1332Score of Parenthesis LeetCode Solution65
1333Insert into a Sorted Circular Linked List LeetCode Solution63
1334Flatten Binary Tree to Linked List LeetCode Solution62
1335Stone Game IV LeetCode Solution62
1336Range Sum Query 2D – Immutable LeetCode Solution60
1337Is Graph Bipartite? LeetCode Solution60
1338Valid Triangle Number LeetCode Solution59
1339Reveal Cards In Increasing Order Leetcode Solution55
1340Divide Chocolate LeetCode Solution51
1341Range Sum of BST LeetCode Solution43
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution42
1343Reverse Integer Leetcode Solution41
1344Sort Colors LeetCode Solution37
1345Find K Closest Elements LeetCode Solution36
1346Excel Sheet Column Number LeetCode Solution34
1347Rotate String LeetCode Solution32
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution31
Translate »