Valid Anagram Leetcode Solution

Difficulty Level Easy
Frequently asked in Adobe Affirm Amazon American Express Apple BlackRock Bloomberg Cisco Dell Facebook Goldman Sachs Google Grab IBM JPMorgan Microsoft Oracle PayPal Qualcomm Salesforce Snapchat Spotify Tesla Uber Visa VMware Yahoo Yandex Yelp
Categories - Easy Walmart Global techViews 8

Problem Statement

Valid Anagram Leetcode Solution – Given two strings s and t, return true if t is an anagram of s, and false otherwise.

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:

 s = "anagram", t = "nagaram"

Output:

 true

Example 2:

Input:

 s = "rat", t = "car"

Output:

 false

Constraints:

Valid Anagram Leetcode Solution

Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

Approach

Idea:

  1. if two strings are anagrams then the frequency of every char in both of the strings are same.
  2. we count the freq of every character in string1 and string 2.
  3. here to count freq we make an array of size 26.
  4. characters in the string are from ‘a’ to ‘z’ so we can represent ‘a’ as 0 and ‘z’ as 25 by doing (int idx=ch-‘a’)
  5. now we compare freq1[i] and freq2[i] for every index i from 0 to 26 and if they are different we return false
  6. otherwise, we return true

C++ Program of  Valid Anagram

class Solution {
public:
    bool isAnagram(string s, string t) {
       
        if(s.length()!=t.length())return false;
        
        vector<int> freq1(26,0),freq2(26,0);
        
        for(int i=0;i<s.length();i++)
        {
            freq1[s[i]-'a']++;
            freq2[t[i]-'a']++;
        }
        
        for(int i=0;i<26;i++)
        {
            if(freq1[i]!=freq2[i])return false;
        }
        
        return true;
        
    }
};

JAVA Program of  Valid Anagram

public class Solution {
    public boolean isAnagram(String s, String t) {
        if(s.length()!=t.length()){
            return false;
        }
        int[] freq1 = new int[26];
        int[] freq2 = new int[26];
        
        for(int i=0;i<s.length();i++){
            freq1[s.charAt(i)-'a']++;
            freq2[t.charAt(i)-'a']++;
        }
       
        for(int i=0;i<26;i++)
        {
            if(freq1[i]!=freq2[i])return false;
        }
        
        return true;
    }
}

Time Complexity for Valid Anagram Leetcode Solution

O(n) +O(26) i.e=> O(n) as we iterate the string to count the frequency of every character where n is the length of the string.

Space Complexity

O(26) i.e => O(1) as we are using  26 size-frequency array to store the frequency of every character.

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 Tree2509
3Reverse a string without affecting special characters2470
4Delete a node of a linked list at given position1983
5Palindrome using Recursion1884
6Insert nodes in a linked list in a sorted way (Ascending Order)1668
7Find elements pair from array whose sum equal to number1655
8Sort Elements by Frequency of Occurrences1641
9Quick Sort1627
10Write a program to print all permutations of a given string1615
11Find Minimum Distance Between Two Numbers in an Array1479
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 Value1365
16Recursively remove all adjacent duplicates1363
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1328
19Sum of numbers in String1324
20Smallest Positive Number Missing in an Unsorted Array1292
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 List1225
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1212
27Recursive function to do substring search1206
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 identical1112
32Maximum Subarray Sum using Divide and Conquer1110
33Remove characters from first string which are in second1077
34Find Leaders in an Array1065
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 II998
38Find the second most frequent character997
39Given a string find its first non-repeating character976
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 not957
44Print all possible words from phone digits940
45Find the Missing Number932
46Rearrange Positive and Negative Numbers Alternatively in Array928
47Longest Palindromic Substring910
48Segregate even and odd nodes in a linked list893
49Print Longest common subsequence890
50Union and Intersection of Two Linked Lists880
51Transform one string to another using minimum number of given operations874
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 Matrices809
57Check if the linked list is palindrome803
58Rotate a Linked List802
59Count of Triplets With Sum Less than Given Value802
60Stock Buy Sell to Maximize Profit797
61Insertion Sort773
62Concatenation of two strings769
63Tug of War767
64Count Number of Substrings with K Distinct Character’s763
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 string738
70Reverse String Without Temporary Variable738
71Find all Common Elements in Given Three Sorted Arrays735
72Remove all duplicates in an unsorted linked list716
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 Matrices692
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s685
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 Identical653
86Multiplication of Previous and Next653
87Subtraction of Two Matrices642
88Merge K Sorted Arrays and Print Sorted Output639
89Move All the Zeros to the End of the Given Array637
90Divide a string in N equal parts634
91Online Algorithm for Checking Palindrome in a Stream629
92Form Minimum Number from Given Sequence of D’s and I’s628
93Check whether two strings are anagram of each other624
94Remove recurring digits in a given number622
95Sort a linked list that is sorted alternating ascending and descending617
96Maximum Circular Subarray Sum616
97Sort a stack using a temporary stack614
98Find the Minimum Element in a Sorted and Rotated Array610
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 Decreasing598
106Palindrome Permutations of a String594
107Elements Appear more than N/K times in Array588
108Palindromes in a given range585
109Print all permutations with repetition583
110Run length encoding582
111Majority Element582
112Pangram Checking580
113Minimum insertions to form a shortest palindrome580
114Minimum Characters to be Added at Front to Make String Palindrome572
115Rearrange a given linked list in-place572
116Remove all duplicates in a sorted linked list571
117Merge a linked list into another at alternate positions570
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 More565
122Print all anagrams together in a sequence of words560
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem548
125Merge Overlapping Intervals II545
126Two Sum Leetcode Solution545
127Clone a Linked List with next and random pointer543
1283Sum Leetcode Solution542
129Size of The Subarray With Maximum Sum533
130Transpose of a Matrix533
131Remove Extra Spaces from a String530
132Removing Spaces from a String using stringstream529
133Check if a given string is a rotation of a palindrome526
134Remove duplicates from a string526
135Partition Problem525
136Longest Palindrome can be Formed by Removing or Rearranging Characters525
137Smallest Palindrome after Replacement524
138Maximum Sum Increasing Subsequence523
139Check whether Strings are K Distance Apart or Not515
140Generate all Binary Strings from Given Pattern515
141Length of Longest valid Substring510
142Insert Node in the Sorted Linked List507
143Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized507
144Delete Last Occurrence506
145Check if Two given Strings are Isomorphic to each other502
146Maximum difference between two elements such as larger element comes after smaller494
147Program to Toggle all Characters in a String493
148Given string is interleaving of two other strings or not490
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
153Find Pair with Given Difference480
154Check if all Rows of a Matrix are Circular Rotations of Each Other479
155Longest Common Prefix using Divide and Conquer477
156Find nth node of the Linked list from the end476
157Sort 0s 1s and 2s in an Array468
158Find a Fixed Point in a Given Array467
159Print all interleavings of given two strings467
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 Indexes460
165Print Reverse of a string (Recursion)460
166Median of Two Sorted Arrays LeetCode Solution459
167Split linked list using alternate nodes458
168Print string of odd length in ‘X’ format445
169Print all Palindromic Partitions of a String441
170Swap Kth Node from beginning with Kth Node from End441
171Find K Length Subarray of Maximum Average440
172Find Element Using Binary Search in Sorted Array439
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions426
175Flatten a multilevel linked list424
176Shortest Superstring Problem423
177Maximum Length of Chain Pairs421
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 II395
187Reverse a Singly Linked List (Iterative/Non-Recursive)394
188Find the two Numbers with Odd Occurrences in an Unsorted Array394
189Caesar Cipher389
190Kth Non-repeating Character388
191Rearrange a linked list in Zig-Zag386
192Check if String can Become Empty by Recursively Deleting given Substring385
193Longest Common Prefix Word by Word Matching381
194Pancake Sorting380
195Rotate Image by 90 degrees380
196Permutations of a Given String Using STL373
197Perfect Reversible String372
198Merging Two Sorted Arrays369
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
203Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes366
204Find First non-repeating character in a string366
205Four Elements that Sum to Given363
206Delete N nodes after M360
207List items containing all characters of a given word360
208Count Number of Occurrences in a Sorted Array354
209Longest Common Prefix using Character by Character Matching354
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 strings338
217Maximum occurring character in a string336
218Even Substring Count336
219Convert a String that is Repetition of a Substring of Length K335
220Valid Parentheses LeetCode Solution334
221Find the first Repeating Number in a Given Array333
222Reverse a singly linked list recursively333
223Print Shortest Path to Print a String on Screen331
224Binary Tree to Doubly linked list329
225Convert string1 to string2 in one edit329
226Can we reverse a linked list in less than O(n) time ?329
227Nth Character in Concatenated Decimal String328
228Reverse a String using Stack326
229wildcard character matching325
230Sort Elements by Frequency II325
231Lower Case To Upper Case323
232Maximum Subarray Leetcode Solution323
233Merge Two Sorted Arrays318
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 Programming308
240Count the Pairs at Same Distance as in English Alphabets308
241Next Greater Element in an Array303
242Palindrome Permutation298
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 String283
251Word Search Leetcode Solution283
252Reverse Bits282
253Print all Possible Ways to Break a String in Bracket Form281
254Delete a node under given conditions280
255Change Gender of a given String278
256Binary Tree278
257Sort an array of strings277
258How to Efficiently Implement k Stacks in a Single Array?277
259Count Pairs With Given Sum275
260First non Repeating Element274
261Meeting Rooms II LeetCode Solution273
262Toeplitz Matrix273
263Number of sub-strings which recursively add up to 9273
264Repeated Substring Pattern272
265Longest Common Extension271
266Remove middle points in a linked list of line segments270
267N queen problem270
268Move all negative elements to one side of array270
269Remove spaces from a string268
270Longest Palindromic Substring LeetCode Solution266
271Shuffle a given Array264
272Min Stack263
273Number of Islands LeetCode Solution260
274Dijkstra Algorithm259
275Cuckoo sequence program259
276Find, second, frequent, character258
277House Robber Leetcode Solution258
278Max stack258
279Most Frequent Element in an Array256
280Fibonacci numbers255
281Minimize the maximum difference between the heights254
282Clone a linked list with next and random pointer (Hashing)252
283Search Insert Position Leetcode Solution251
284Expression Evaluation250
285Sort linked which is sorted on absolute values250
286Sudoku Solver249
287Subset Leetcode249
288Valid Palindrome Leetcode Solution248
289Plus One Leetcode Solution247
290KMP Algorithm247
291Evaluation of Postfix Expression246
292Word Search246
293Number Of 1 bits246
294How to Delete a Linked List245
295Combination Sum Leetcode Solution245
296Reverse words in a string245
297Min Stack Leetcode Solution244
298Backspace String Compare241
299Set Matrix Zeroes238
300Rabin Karp Algorithm237
301Reversing a Queue236
302Sqrt(x) Leetcode Solution236
303Pair of Positive Negative Values in an Array236
304Merge Sorted Arrays Leetcode Solution236
305Subarray with 0 sum234
306Common elements in all rows of a given matrix233
307Tower Of Hanoi233
308Combination Sum231
309Contains Duplicate II Leetcode Solution230
310Delete middle element of a stack230
311Product of array except self230
312Integer to Roman Leetcode Solution230
313String Compression228
314Intersection of Two Arrays II Leetcode Solution228
315Pascal Triangle Leetcode228
316Minimum swaps required to bring all elements less than or equal to k together226
317Reverse individual words226
318Count of index pairs with equal elements in an array225
319Count subarrays with equal number of 1’s and 0’s225
320Construct Binary Tree from Given Inorder and Preorder Traversals225
321Segregate even and odd numbers225
322Find Top K (or Most Frequent) Numbers in a Stream224
323Add Binary Leetcode Solution224
324Implementation of Deque using Doubly Linked List224
325Bellman Ford Algorithm224
326Sliding Window Technique223
327Single Number Leetcode Solution223
328Minimum Value to Get Positive Step by Step Sum Leetcode Solution223
329Contains Duplicate222
330Palindrome Linked List Leetcode Solution221
331Sort elements by frequency221
332Arithmetic Expression Evaluation221
333Find sum of non-repeating elements (distinct) elements in an array221
334Second Most Repeated Word in a Sequence221
335Count Odd Numbers in an Interval Range Leetcode Solution220
336Pow(x, n) Leetcode Solution220
337Page Replacement Algorithms in Operating Systems219
338Postfix to Infix Conversion219
339Design a stack that supports getMin() in O(1) time and O(1) extra space218
340Next Permutation218
341Maximum Number of Balloons Leetcode Solution218
342Group Words With Same Set of Characters218
343Kruskal Algorithm217
344Smallest Subarray with k Distinct Numbers216
345Sum of minimum and maximum elements of all subarrays of size k216
346Longest Common Prefix Leetcode Solution216
347Maximum Subarray215
348Find Lucky Integer in an Array Leetcode Solution215
349Scramble String215
350Third Maximum Number Leetcode Solution215
351Convex Hull Algorithm214
352Longest Substring Without Repeating Characters LeetCode Solution214
353Sorting array using Stacks214
354Minimum operation to make all elements equal in array214
355K-th Smallest Element in a Sorted Matrix214
356Permutations Leetcode Solution214
357Top K Frequent Words214
358Find the Town Judge Leetcode Solution213
359Find Numbers with Even Number of Digits Leetcode Solution212
360Count subarrays having total distinct elements same as original array212
361Majority Element Leetcode Solution210
362Evaluate Division210
363Special Number210
364Number of Good Pairs Leetcode Solution210
365Swap Nodes in Pairs Leetcode Solutions210
366Spiral Matrix LeetCode Solution209
367First element occurring k times in an array209
368Given two unsorted arrays find all pairs whose sum is x209
369Prefix to Infix Conversion208
370Check if two arrays are equal or not207
371Huffman Coding207
372Merge Two Sorted Lists Leetcode Solutions207
373Count Primes Leetcode Solutions207
374Reversing the First K elements of a Queue207
375Minimum Path Sum207
376Pascal’s Triangle II Leetcode Solution206
377Reverse a Number Using Stack206
378Best Time to Buy and Sell Stock  II Leetcode Solution206
379Single Number206
380Missing Number Leetcode Solution206
381Maximal Square205
382Group Anagrams205
383Minimum Absolute Difference Leetcode Solution205
384Search in Rotated Sorted Array Leetcode Solution205
385Running Sum of 1d Array Leetcode Solution205
386Minimum Steps to reach target by a Knight205
387Find duplicates in a given array when elements are not limited to a range204
388Sort Array by Increasing Frequency Leetcode Solution204
389House Robber II Leetcode Solution204
390Maximum Distance Between two Occurrences of Same Element in Array203
391Power of Two Leetcode Solution203
392Top K Frequent Elements202
393Find the first repeating element in an array of integers202
394Find Minimum In Rotated Sorted Array202
395Find All Numbers Disappeared in an Array Leetcode Solution202
396Convert String To Int202
397How to Implement Stack Using Priority Queue or Heap?202
398Matrix Diagonal Sum Leetcode Solution202
399Palindrome Substring Queries202
400Unique Paths Leetcode Solution201
401Find the Closest Palindrome number201
402Maximum possible difference of two subsets of an array201
403Range Sum Query 2D – Immutable Leetcode Solution201
404Sorting using trivial hash function201
405Check if Array Contains Contiguous Integers With Duplicates Allowed201
406Expression Contains Redundant Bracket or Not201
407Unique Paths201
408Subarray Sum Equals k201
409Zigzag Conversion201
410Fizz Buzz Leetcode201
411Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
412How Many Numbers Are Smaller Than the Current Number Leetcode Solution200
413Sort Integers by The Number of 1 Bit Leetcode Solution200
414Smallest Element Repeated Exactly K Times200
415Leetcode Permutations199
416Max Consecutive Ones Leetcode Solution199
417Cumulative Frequency of Count of Each Element in an Unsorted Array199
418Find Number of Employees Under every Employee199
419Subset sum problem199
420Letter Case Permutation198
421Happy Number Leetcode Solution198
422Find Winner on a Tic Tac Toe Game Leetcode Solution198
423Coin Change 2 Leetcode Solution198
424Length of the largest subarray with contiguous elements198
425Best Time to Buy and Sell Stock III Leetcode Solution197
426Print All Distinct Elements of a Given Integer Array197
427Decode String197
428Subarray Sum Equals K LeetCode Solution197
429Implement Stack and Queue using Deque197
430Sort a stack using recursion197
431Difference between highest and least frequencies in an array197
432Reverse Integer197
433Find top three repeated in array197
434Fibonacci Number LeetCode Solution196
435Monotonic Array LeetCode Solution196
436Print all subarrays with 0 sum196
437Remove Duplicates from Sorted Array Leetcode Solution196
438Nth Catalan Number196
439LRU Cache Implementation196
440Sum of Subarray Ranges Leetcode Solution195
441Count Substrings with equal number of 0s, 1s and 2s195
442Check If N and Its Double Exist Leetcode Solution195
443Find The Duplicate Number194
444Generate a String With Characters That Have Odd Counts Leetcode Solution194
445Reverse Vowels of a String Leetcode Solution194
446Capacity To Ship Packages Within D Days Leetcode Solution194
447Subarrays with distinct elements194
448Reverse a Stack Using Recursion194
449Maximum Depth of Binary Tree Leetcode Solution194
450Find Median from data Stream193
451Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
452Merge Two Sorted Linked Lists193
453Kth largest element in an Array Leetcode Solutions193
454Integer to English words193
455Delete a Node from linked list without head pointer193
456Reverse Words in a String III LeetCode Solution193
457Shuffle the Array Leetcode Solution192
458Prim’s Algorithm192
459Bipartite Graph192
460Trapping Rain Water Leetcode Solution192
461Find the Duplicate Element192
462Count pairs from two linked lists whose sum is equal to a given value191
463Sorting a Queue without Extra Space191
464Reverse a String191
465Longest Common Subsequence191
466Count and Say191
467Target Sum191
468Find the Difference Leetcode Solution191
469Find Common Characters Leetcode Solution191
470Remove Minimum Number of Elements Such That no Common Element Exist in both Array191
471Balanced Binary Tree Leetcode Solution190
472Excel Sheet Column Number Leetcode Solution190
473Find all pairs (a, b) in an array such that a % b = k190
474Iterative Tower of Hanoi190
475Find elements which are present in first array and not in second190
476Priority Queue Using Singly Linked List190
477Edit Distance190
478Concatenation of Array LeetCode Solution189
479Text Justification LeetCode Solution189
480Fizz Buzz189
481Longest Common Prefix using Trie189
482Floyd Warshall Algorithm189
483The K Weakest Rows in a Matrix Leetcode Solution189
484Kids With the Greatest Number of Candies Leetcode Solution188
485Design Parking System Leetcode Solution188
486Next Greater Element I Leetcode Solution188
487Reverse a linked list188
488Minimum Moves to Equal Array Elements Leetcode Solution188
489Find First and Last Position of Element in Sorted Array Leetcode Solution188
490Degree of an array188
491Longest subarray not having more than K distinct elements187
492Number of Steps to Reduce a Number to Zero Leetcode Solution187
493Prefix to Postfix Conversion187
494Flood Fill LeetCode187
495Word Ladder LeetCode Solution187
496Merge Overlapping Intervals187
497MiniMax Algorithm187
498Valid Parenthesis String187
499Kth Largest Element in a Stream Leetcode Solution187
500Top View of Binary Tree187
501Zigzag Conversion LeetCode Solution186
502Slowest Key Leetcode Solution186
503Find four elements that sum to a given value (Hashmap)186
504Find N Unique Integers Sum up to Zero Leetcode Solution186
505Multiply Strings Leetcode Solution186
506Shortest Palindrome186
507Pair with given product186
508Find subarray with given sum (Handles Negative Numbers)186
509Priority Queue in C++185
510Jump Game Leetcode Solution185
511Convert array into Zig-Zag fashion185
512The Stock Span Problem185
513Postfix to Prefix Conversion185
514Count and Say Leetcode Solution185
515Max Area of Island185
516Length of Last Word Leetcode Solution184
517Mobile Numeric Keypad Problem184
518Substring With Concatenation Of All Words184
519Move Zeroes LeetCode Solution184
520Find Index of Closing Bracket for a Given Opening Bracket in an Expression184
521Recursion184
522Find distinct elements common to all rows of a matrix184
523Implement a stack using single queue184
524Find any one of the multiple repeating elements in read only array184
525Count number of triplets with product equal to given number184
526Longest Common Prefix using Sorting183
527Shuffle String Leetcode Solution183
528Next Greater Frequency Element183
529Peak Index in a Mountain Array183
530Intersection of Two Arrays183
531Check if a given array contains duplicate elements within k distance from each other183
532Largest Sum Contiguous Subarray182
533Rearrange a binary string as alternate x and y occurrences182
534Implement Stack using Queues182
535Iterative Inorder Traversal of a Binary Tree182
536Find missing elements of a range182
537Convert a normal BST to Balanced BST181
538Relative Sort Array Leetcode Solution181
539Change the Array into Permutation of Numbers From 1 to N181
540Last Stone Weight181
541Contiguous Array Leetcode181
542Delete Node in a Linked List Leetcode Solution181
543Excel Sheet Column Title Leetcode Solution181
544Smallest Subarray With all Occurrences of a Most Frequent Element181
545Koko Eating Bananas Leetcode Solution181
546Minimum Bracket Reversals180
547K-th Distinct Element in an Array180
548Valid Sudoku180
549Group Multiple Occurrence of Array Elements Ordered by first Occurrence180
550Distribute Candies to People Leetcode Solution179
551Container with Most Water179
552First negative integer in every window of size k179
553N-th Tribonacci Number Leetcode Solution179
554Is Subsequence Leetcode Solution179
555Sum of Left Leaves Leetcode Solutions179
556Isomorphic Strings Leetcode Solution179
557Best Time to Buy and Sell Stock179
558Linked List Cycle II LeetCode Solution179
559Implementation of Deque using circular array178
560Island Perimeter Leetcode Solution178
561Number of Provinces Leetcode Solution178
562Assign Cookies Leetcode Solution178
563Build Array From Permutation Leetcode Solution178
564Minimum Delete Operations to make all Elements of Array Same178
565Find Words That Can Be Formed by Characters Leetcode Solution178
566Jewels and Stones Leetcode Solution178
567Integer to Roman178
568Minimum Operations to convert X to Y178
569Arrange given numbers to form the biggest number177
570Largest Perimeter Triangle Leetcode Solution177
571Check for Balanced Parentheses in an Expression177
572Valid Anagrams177
573Shuffle an Array177
574Unique Binary Search Trees177
575Gold Mine Problem177
576Summary Ranges Leetcode Solution177
577Minimum Knight Moves LeetCode Solution177
578Convert Sorted Array to Binary Search Tree Leetcode Solution177
579Remove Linked List Elements Leetcode Solution176
580Maximum sum rectangle in a 2D matrix176
58101 Matrix LeetCode Solution176
582Hamming Distance176
583Trapping Rain Water LeetCode Solution176
584LRU Cache LeetCode Solution176
585Combinations Leetcode Solution176
586Count the number of nodes at given level in a tree using BFS176
587Count all subsequences having product less than K176
588Maximum path sum in a triangle176
589Rotate List Leetcode Solution175
590The Knapsack Problem175
5913Sum Closest LeetCode Solution175
592Find the smallest positive integer value that cannot be represented as sum of any subset of a given array175
593Decode Ways175
594Minimum insertions to form a palindrome with permutations allowed174
595Minimum number of subsets with distinct elements174
596Shortest Path in a Grid with Obstacles Elimination LeetCode Solution174
597Same Tree LeetCode Solution173
598Maximum Number of Chocolates to be Distributed Equally Among k Students173
599Find minimum difference between any two elements173
600Maximum Distance in Array173
601Rotate Image LeetCode Solution173
602Minimum number of distinct elements after removing m items173
603Bubble sort using two Stacks173
604Sort Characters By Frequency LeetCode Solution173
605Insert Interval Leetcode Solution173
606Distance Between Bus Stops Leetcode Solution173
607Sieve of Eratosthenes172
608Find if an Expression has Duplicate Parenthesis or Not172
609How to check if two given sets are disjoint?172
610Stone Game LeetCode172
611Longest Increasing Subsequence172
612Painting Fence Algorithm172
613XOR Operation in an Array Leetcode Solution172
614Find Sum of all unique sub-array sum for a given array172
615License Key Formatting Leetcode Solution171
616Replace Elements with Greatest Element on Right Side Leetcode Solution171
617Frog Jump Leetcode Solution171
618Defanging an IP Address Leetcode Solution171
619Reverse a stack without using extra space in O(n)171
620Word Pattern171
621Applications of Breadth First Search and Depth First Search171
622Permutation in String Leetcode Solution171
623Sort Array By Parity LeetCode Solution170
624Smallest Good Base170
625Maximum Consecutive Numbers Present in an Array170
626Word Wrap Problem170
627Minimum Cost to Hire K Workers170
628Find the Duplicate Number LeetCode Solution170
629K Empty Slots LeetCode170
630Remove All Occurrences of a Substring LeetCode Solution170
631Distance of nearest cell having 1 in a binary matrix170
632House Robber170
633Optimal Account Balancing LeetCode Solution169
634Isomorphic Strings169
635Longest Substring with At Least K Repeating Characters LeetCode Solution169
636Non-overlapping sum of two sets169
637Best Time to Buy and Sell Stock LeetCode Solution169
638Minimum Depth of Binary Tree Leetcode Solution169
639Tracking current Maximum Element in a Stack169
640Printing brackets in Matrix Chain Multiplication Problem169
641Segregate 0s and 1s in an Array169
642Coin Change Problem168
643Iterative Method to find Height of Binary Tree168
644Binary Tree Zigzag Level Order Traversal LeetCode Solution168
645Employee Free Time LeetCode Solution168
646Wiggle Sort168
647Queries for counts of array elements with values in given range168
648Kth Missing Positive Number Leetcode Solution168
649Moving Average from Data Stream Leetcode Solution168
650Merge Two Balanced Binary Search Trees168
651Longest Substring with At Most K Distinct Characters LeetCode Solution168
652Valid Palindrome II Leetcode Solution168
653How to Create Mergable Stack?167
654Count Good Nodes in Binary Tree Leetcode Solution167
655Strobogrammatic Number LeetCode Solution167
656Check If It Is a Straight Line Leetcode Solution167
657Reorganize String167
658Maximum difference between first and last indexes of an element in array167
659Path With Maximum Minimum Value LeetCode Solution167
660Sum of All Odd Length Subarrays Leetcode Solution167
661Find Maximum Level sum in Binary Tree167
662Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions167
663Best Time to Buy and Sell Stock with Cooldown Leetcode Solution166
664Find Largest d in Array such that a + b + c = d166
665GCD Of Two Numbers166
666Find the Distance Value Between Two Arrays Leetcode Solution166
667Flipping an Image LeetCode Solution166
668Maximum Number of Occurrences of a Substring Leetcode Solution166
669Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest166
670Inorder Successor of a node in Binary Tree165
671Convert an array to reduced form165
672Find pairs with given sum such that elements of pair are in different rows165
673Partition Labels LeetCode Solution165
674Delete consecutive same words in a sequence165
675Valid Palindrome165
676Maximum Number of Coins You Can Get Leetcode Solution165
677K Empty Slots165
678To Lower Case Leetcode Solution165
679Remove Invalid Parentheses Leetcode Solution165
680Check if a queue can be sorted into another queue using a stack165
681Reducing Dishes LeetCode Solution165
682Print the Fibonacci numbers in reverse order165
683Letter Combinations of a Phone Number165
684Increasing Decreasing String Leetcode Solution164
685Number of Dice Rolls With Target Sum LeetCode Solution164
686Find the Smallest Divisor given a Threshold Leetcode Solution164
687Delete Nth node from the end of the given linked list164
688BFS vs DFS for Binary Tree164
689Check If Two String Arrays are Equivalent Leetcode Solution164
690Factorial Trailing Zeroes Leetcode Solution164
691Edit Distance LeetCode Solution163
692Lucky Numbers in a Matrix Leetcode Solution163
693Form minimum number from given sequence163
694Find whether an array is subset of another array163
695Permutation Sequence LeetCode Solution163
696Valid Perfect Square Leetcode Solution163
697Find Leaves of Binary Tree LeetCode Solution163
698Partition Array Into Three Parts With Equal Sum Leetcode Solution163
699Longest Increasing Path in a Matrix LeetCode Solution163
700Populating Next Right Pointers in Each Node163
701Power of Four Leetcode Solution163
702Recover Binary Search Tree163
703Subset Sum Leetcode163
704Reversing a Queue using Recursion162
705Construct BST from given Preorder Traversal162
706Dynamic Programming Basics162
707Binary Tree zigzag level order Traversal162
708Merge Two Binary Trees LeetCode Solution162
709Ugly Number Leetcode Solution162
710Sort Array by Increasing Frequency Leetcode Solution162
711String to Integer (atoi) LeetCode Solution162
712Unique Paths II Leetcode Solution162
713Reverse Only Letters LeetCode Solution162
714Maximum Product of Two Elements in an Array Leetcode Solution162
715Robot Room Cleaner Leetcode Solution162
716Add and Search Word – Data structure design LeetCode161
717Decompress Run-Length Encoded List Leetcode Solution161
718Find the node with minimum value in a Binary Search Tree161
719Convert a Number to Hexadecimal Leetcode Solution161
720Find the largest multiple of 3161
721Perform String Shifts Leetcode161
722Keyboard Row Leetcode Solution161
723Reservoir Sampling161
724Binomial Coefficient161
725Tiling Problem160
726Sum of f(a[i], a[j]) over all pairs in an array of n integers160
727Restore IP Addresses Leetcode Solution160
728Bulb Switcher LeetCode Solution160
729Hamming Distance Leetcode Solution160
730Majority Element II Leetcode Solution160
731Finding K closest element160
732Find Maximum Depth of Nested Parenthesis in a String159
733Minimum Distance Between BST Nodes Leetcode Solution159
734Numbers with prime frequencies greater than or equal to k159
735Snakes and Ladders LeetCode Solution159
736Word Pattern LeetCode Solution159
737Minimum Cost For Tickets Leetcode Solution159
738Check if Two Expressions With Brackets are Same159
739Rank Transform of an Array Leetcode Solution159
740Race Car LeetCode Solution159
741Find Pair with Greatest Product in Array159
742Minimum Height Trees158
743Maximum Product of Three Numbers LeetCode Solution158
744Longest Span with same Sum in two Binary arrays158
745First Unique Character in a String LeetCode Solution158
746Student Attendance Record I Leetcode Solution158
747Binary Tree Maximum Path Sum LeetCode Solution158
748Invert Binary Tree LeetCode Solution158
749Diagonal Traversal of Binary Tree158
750Remove brackets from an algebraic string containing + and – operators158
751Maximum Depth of N-ary Tree Leetcode Solution158
752Linked List Cycle158
753Morris Traversal158
754Number of Islands II LeetCode Solution158
755Maximum 69 Number Leetcode Solution158
756Find unique character in a string158
757Merge K Sorted Linked Lists158
758Non-decreasing Array LeetCode Solution158
759Queue based approach for first non-repeating character in a stream158
760Generate all possible sorted arrays from alternate elements of two given sorted arrays158
761Minimum time required to rot all oranges158
762Stack Permutations (Check if an array is stack permutation of other)158
763Best Meeting Point LeetCode Solution157
764Remove Nth Node From End of List Leetcode Solution157
765String Compression LeetCode Solution157
766Final Prices With a Special Discount in a Shop Leetcode Solution157
767Transpose Graph157
768Sorted Linked List to Balanced BST157
769Minimize Maximum Pair Sum in Array LeetCode Solution157
770Find if Path Exists in Graph Leetcode Solution157
771Largest subarray with equal number of 0s and 1s157
772Kth ancestor of a node in binary tree157
773Symmetric Tree Leetcode Solution156
774Partition to K Equal Sum Subsets Leetcode Solution156
775Jump Game156
776Total Numbers With no Repeated Digits in a Range156
777k-th missing element in increasing sequence which is not present in a given sequence156
778Check If Array Pairs Are Divisible by k LeetCode Solution156
779Special Array With X Elements Greater Than or Equal X Leetcode Solution156
780Largest rectangular sub-matrix whose sum is 0156
781Find All Duplicates in an Array LeetCode Solution156
782Largest Rectangle in Histogram LeetCode Solution156
783Elements to be added so that all elements of a range are present in array156
784Maximum Length of a Concatenated String with Unique Characters Leetcode Solution156
785Maximum Difference Between Increasing Elements LeetCode Solution155
786Longest Subarray Having Count of 1s One More than Count of 0s155
787Find Median from Data Stream LeetCode Solution155
788Program for Bridge and Torch problem155
789Split a String in Balanced Strings Leetcode Solution155
790Search a 2D Matrix II Leetcode Solution155
791Count items common to both the lists but with different prices155
792Evaluate Reverse Polish Notation LeetCode Solution155
793Base 7 Leetcode Solution154
794Number of NGEs to the Right154
795Print a Binary Tree in Vertical Order154
796Deletion in a Binary Tree154
797Sort an array according to the order defined by another array154
798Search in a Binary Search Tree Leetcode Solution154
799Circular Queue154
800Minimum Jumps to Reach Home LeetCode Solution154
801Interval Tree154
802Valid Number154
803Minimum swaps to make sequences increasing154
804N-Queens LeetCode Solution154
805Course Schedule II – LeetCode154
806Check for Palindrome after every character replacement Query154
807Growable array based stack154
808Nearest Exit from Entrance in Maze LeetCode Solution154
809Spiral Matrix II Leetcode Solution153
810One Edit Distance LeetCode Solution153
811Sort Array By Parity II Leetcode Solution153
812Maximum Profit in Job Scheduling Leetcode Solution153
813Last Stone Weight II LeetCode Solution153
814Minimum number of jumps to reach end153
815String comparison containing wildcards153
816Nested List Weight Sum II LeetCode Solution153
817Minimum Time Visiting All Points Leetcode Solution153
818Get Maximum in Generated Array Leetcode Solution153
819Remove Duplicates from Sorted List II153
820Number Complement Leetcode Solution153
821Count quadruples from four sorted arrays whose sum is equal to a given value x153
822Reorder Data in Log Files LeetCode Solution153
823Merge Sorted Array LeetCode Solution153
824Crawler Log Folder Leetcode Solution152
825Subarray Product Less Than K LeetCode Solution152
826Remove Duplicates from Sorted List LeetCode Solution152
827Regular Expression Matching152
828Find Maximum Sum Possible Equal Sum of Three Stacks152
829Iterative Preorder Traversal152
830Convert BST to Min Heap152
831Relative Ranks Leetcode Solution152
832Priority Queue using doubly linked list152
833A Space Optimized DP solution for 0-1 Knapsack Problem152
834Maximum size subarray sum equals k152
835Find all triplets with zero sum152
836LCS (Longest Common Subsequence) of three strings151
837Form Minimum Number From Given Sequence151
838Insert into a Binary Search Tree Leetcode Solution151
839Tree Traversal (Preorder, Inorder & Postorder)151
840Top K Frequent Words LeetCode Solution150
841Valid Parentheses Leetcode Solution150
842Maximum Nesting Depth of the Parentheses Leetcode Solution150
843Permutation Coefficient150
844Count Distinct Elements in Every Window of Size K150
845Friends Pairing Problem150
846Partition List Leetcode Solution150
847Alien Dictionary LeetCode Solution150
848Sequences of given length where every element is more than or equal to twice of previous150
849Given an Array of Pairs Find all Symmetric Pairs in it150
850Check if a given array can represent Preorder Traversal of Binary Search Tree150
851Path with maximum average value150
852Subsequence of Size K With the Largest Even Sum LeetCode Solution150
853Find the subarray with least average150
854Sort Colors150
855Sum of nearest smaller and greater number150
856Minimum Number of Taps to Open to Water a Garden LeetCode Solution150
857Minimum Swaps to Make Strings Equal Leetcode Solution150
858Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution150
859Subset with sum divisible by m150
860Level order Traversal in Spiral Form150
861Design a Stack With Increment Operation Leetcode Solution150
862Brick Wall LeetCode Solution150
863Identify and Mark Unmatched Parenthesis in an Expression150
864Can Place Flowers LeetCode Solution150
865Binary Search Tree Search and Insertion150
866Find All Possible Recipes from Given Supplies LeetCode Solution149
867Guess Number Higher or Lower LeetCode Solution149
868Matrix Chain Multiplication149
869Minimum Sum Path in a Triangle149
870Find the Only Repetitive Element Between 1 to N-1149
871Check whether a given Binary Tree is Complete or not149
872Check if stack elements are pairwise consecutive149
873Count Negative Numbers in a Sorted Matrix LeetCode Solution149
874Range LCM Queries149
875Brightest Position on Street LeetCode Solution149
876Missing Element in Sorted Array LeetCode Solution149
877Balanced Expression with Replacement149
878Range sum queries without updates149
879Sorted Array to Balanced BST149
880Number of Days Between Two Dates LeetCode Solution149
881Clone Graph LeetCode Solution149
882Find distance between two nodes of a Binary Tree148
883Diagonal Traverse LeetCode Solution148
884Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution148
885Count ways to reach the nth stair using step 1, 2 or 3148
886Find Common Characters Leetcode Solution148
887Union and Intersection of two Linked Lists148
888Rearrange an Array Such that arr[i] is equal to i148
889An Interesting Method to generate Binary Numbers from 1 to n148
890Time Based Key-Value Store LeetCode Solution148
891Repeated Substring Pattern LeetCode Solution148
892GCDs of given index ranges in an array148
893Destination City Leetcode Solution148
894BFS for Disconnected Graph147
895Diagonal Traversal LeetCode Solution147
896Check if an Array is Stack Sortable147
897Three way partitioning of an array around a given range147
898Distinct adjacent elements in an array147
899Design Browser History LeetCode Solution147
900Minimum sum of multiplications of n numbers147
901K’th Largest Element in BST when modification to BST is not allowed147
902Guess Number Higher or Lower II147
903Shortest Word Distance Leetcode Solution147
904Averages of Levels in Binary Tree147
905Water Bottles Leetcode Solution147
906Lemonade Change 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
908Insert Delete GetRandom147
909Spiral Matrix III LeetCode Solution147
910Convert Sorted List to Binary Search Tree147
911Delete And Earn147
912Set Matrix Zeroes Leetcode Solution146
913Vertical sum in a given binary tree146
914Special Positions in a Binary Matrix Leetcode Solution146
915Rearrange Spaces Between Words Leetcode Solution146
916Construct Complete Binary Tree from its Linked List Representation146
917Maximum Score After Splitting a String Leetcode Solution146
918Robot Bounded In Circle LeetCode Solution146
919Queue using Stacks146
920Daily Temperatures Leetcode Solution146
921Least Number of Unique Integers after K Removals Leetcode Solution146
922Number of Distinct Islands Leetcode Solution145
923Find all permuted rows of a given row in a matrix145
924Dividing Array into Pairs With Sum Divisible by K145
925Largest area rectangular sub-matrix with equal number of 1’s and 0’s145
926Alien Dictionary145
927Count Subarrays with Same Even and Odd Elements145
928Construct the Rectangle Leetcode Solution145
929Iterative Postorder Traversal Using Two Stacks145
930Maximum Subarray Sum Excluding Certain Elements145
931Check if the given array can represent Level Order Traversal of Binary Search Tree145
932Check if any two intervals overlap among a given set of intervals145
9333 Sum144
934Three Consecutive Odds Leetcode Solution144
935Palindrome Partitioning Leetcode Solution144
936Lexicographical Numbers Leetcode Solution144
9374Sum144
938A program to check if a binary tree is BST or not144
939Split Array Into Consecutive Subsequences144
940Binary Tree Longest Consecutive Sequence LeetCode Solution144
941Merge Two Sorted Lists Leetcode144
942Print Fibonacci sequence using 2 variables144
943Construct BST from its given Level Order Traversal144
944Stone Game II Leetcode143
945Queries for GCD of all numbers of an array except elements in a given range143
946Strongly Connected Component143
947Difference Array | Range update query in O(1)143
948Minimum Height Trees LeetCode Solution143
949Median of Two Sorted Arrays143
950Create Maximum Number143
951Sliding Window Maximum143
952Longest Palindromic Subsequence143
953Number of Equivalent Domino Pairs Leetcode Solution143
954Maximum Frequency Stack Leetcode Solution143
955Remove Duplicates from Sorted List II LeetCode Solution143
956Collect maximum points in a grid using two traversals142
957Analyze User Website Visit Pattern LeetCode Solution142
958Maximize Sum of Array after K Negations Leetcode Solution142
959My Calendar I LeetCode Solution142
960Trim a Binary Search Tree142
961Can Make Arithmetic Progression From Sequence Leetcode Solution142
962Unique Paths II142
963All Unique Triplets that Sum up to a Given Value142
964Infix to Postfix142
965Binary array after M range toggle operations141
966Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space141
967Minesweeper LeetCode Solution141
968Maximum Product Subarray141
969Merging Intervals141
970Find postorder traversal of BST from preorder traversal141
971Count Primes in Ranges141
972Intersection of Two Linked Lists LeetCode Solution141
973Count Submatrices With All Ones LeetCode Solution141
974Kth Smallest Element in a BST Leetcode Solution141
975Find the Difference Leetcode Solution141
976Symmetric Tree140
977Word Break140
978Length of Longest Fibonacci Subsequence140
979K Closest Points to Origin Leetcode Solution140
980Reverse Nodes in K-Group140
981Longest Nice Substring LeetCode Solution140
982Count subarrays where second highest lie before highest140
983Pattern Occurrences using Stack140
984Climbing stairs140
985Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution140
986The Painter’s Partition Problem140
987Sign of the Product of an Array LeetCode Solution140
988Height of a generic tree from parent array140
989Count pair with Given Sum140
990Find Maximum of Minimum for Every Window Size in a Given Array140
991Boundary Traversal of binary tree140
992Maximum length subsequence with difference between adjacent elements as either 0 or 1139
993Segment Tree139
994Largest Substring Between Two Equal Characters Leetcode Solution139
995Friends Of Appropriate Ages LeetCode Solution139
996Product of Array Except Self LeetCode Solution139
997Largest Number Leetcode Solution139
998Largest divisible pairs subset139
999Binary Search Tree Delete Operation139
1000Asteroid Collision LeetCode Solution139
1001Palindrome Partitioning139
1002Level Order Traversal of Binary Tree139
1003Newman-Conway Sequence139
1004Valid Boomerang Leetcode Solution139
1005Number Of Longest Increasing Subsequence138
1006Breadth First Search (BFS) for a Graph138
1007Double the first element and move zero to end138
1008Merge Sort138
1009Find Duplicate Subtrees138
1010Compute nCr % p138
1011Maximum subsequence sum such that no three are consecutive138
1012Boolean Parenthesization Problem138
1013Find number of pairs in an array such that their XOR is 0138
1014Maximum Length of Repeated Subarray138
1015Shortest Completing Word Leetcode Solution138
1016Construction of Longest Increasing Subsequence (N log N)138
1017Insertion in a Binary Tree138
1018Maximum Number of Ways to Partition an Array LeetCode Solution138
1019The Maze III LeetCode Solution138
1020Scramble String LeetCode Solution138
1021Graph Valid Tree LeetCode Solution138
1022Minimum Index Sum of Two Lists138
1023Find the First Circular Tour that visits all the Petrol Pumps138
1024Kill Process LeetCode Solution137
1025K maximum sums of overlapping contiguous sub-arrays137
1026Binary Search Tree137
1027Partition Equal Subset Sum137
1028Number of palindromic paths in a matrix137
1029Construct Binary Tree from given Parent Array representation137
1030Rearrange array such that even positioned are greater than odd137
1031Longest subsequence such that difference between adjacents is one137
1032Maximum Product of Indexes of Next Greater on Left and Right137
1033Depth First Search (DFS) for a Graph137
1034Maximum Sum of 3 Non-Overlapping Subarrays137
1035Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’137
1036Decrypt String from Alphabet to Integer Mapping Leetcode Solution137
1037Ugly Numbers137
1038Build an Array With Stack Operations Leetcode Solution137
1039String Matching in an Array Leetcode Solution137
1040Count minimum steps to get the given desired array136
1041Serialize and Deserialize Binary Tree136
1042Level order traversal using two Queues136
1043Morris Inorder Traversal136
1044Next Greater Element III LeetCode Solution136
1045First missing positive136
1046Advantages of BST over Hash Table136
1047Design Hit Counter LeetCode Solution136
1048Maximum weight transformation of a given string136
1049Iterative Depth First Traversal of Graph136
1050Make The String Great Leetcode Solution136
1051Available Captures for Rook Leetcode Solution136
1052Maximum difference between frequency of two elements such that element having greater frequency is also greater135
1053Kth Smallest Element in a Sorted Matrix LeetCode Solution135
1054Add two numbers135
1055Bitwise AND of Numbers Range LeetCode Solution135
1056Custom Sort String Leetcode Solution135
1057Find a Peak Element II LeetCode Solution135
1058Invalid Transactions LeetCode Solution135
1059Balanced Binary Tree135
1060Count pairs from two sorted arrays whose sum is equal to a given value x134
1061Minimum Size Subarray Sum134
1062Validate Binary Search Tree134
1063Path Sum II LeetCode Solution134
1064Employee Importance LeetCode Solution134
1065Rearrange array such that even index elements are smaller and odd index elements are greater133
1066Move all negative elements to end in order with extra space allowed133
1067Find Peak Element133
1068Ugly Number II LeetCode Solution133
1069Super Ugly Number133
1070Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution133
1071Generate Parentheses Leetcode Solution133
1072Lowest Common Ancestor133
1073Implement Trie (Prefix Tree) Leetcode Solution133
1074Defanging an IP Address LeetCode Solution133
1075Recover Binary Search Tree Leetcode Solution133
1076Root to Leaf path with target sum Leetcode Solutions132
1077Subarrays with K Different Integers Leetcode Solution132
1078Find whether a subarray is in form of a mountain or not132
1079Search in Sorted Rotated Array132
1080Binary Tree Right Side View LeetCode Solution132
1081Regular Expression Matching Regular Expression Matching LeetCode Solution132
1082Populating Next Right Pointers in Each Node Leetcode Solution132
1083Remove Duplicates from Sorted Array II Leetcode Solution132
1084Number of Closed Islands Leetcode Solution132
1085Largest BST Subtree LeetCode Solution132
1086Combination Sum IV LeetCode Solution132
1087Consecutive Characters LeetCode Solution131
1088Smallest Common Region Leetcode Solution131
1089Longest Bitonic Subsequence131
1090Number of Students Doing Homework at a Given Time Leetcode Solution131
1091Remove Palindromic Subsequences Leetcode Solution131
1092Types of Binary Tree131
1093Count Largest Group Leetcode Solution131
1094Find Smallest Range Containing Elements from k Lists131
1095Day of the Year Leetcode Solution131
1096Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1097Find the minimum distance between two numbers130
1098Serialize and Deserialize Binary Tree LeetCode Solution130
1099Convert BST into a Min-Heap without using array130
1100Maximize Distance to Closest Person LeetCode Solution130
1101Next Permutation Leetcode Solution130
1102Print all triplets in sorted array that form AP130
1103Minimum Absolute Difference in BST Leetcode Solution130
1104Clone a Binary Tree with Random Pointers130
1105Number of siblings of a given Node in n-ary Tree130
1106Binary Tree Data Structure130
1107Construct K Palindrome Strings LeetCode Solution129
1108Sum of Even Numbers After Queries129
1109Level of Each node in a Tree from source node129
1110Print Next Greater Number of Q queries129
1111Cutting a Rod129
1112Remove duplicates from sorted array129
1113Palindrome Permutation LeetCode Solution129
1114Find Three Element From Different Three Arrays Such That a + b + c = sum129
1115Path Sum129
1116Divisible Pairs Counting129
1117Find maximum difference between nearest left and right smaller elements129
1118Distinct Subsequences129
1119Increasing Triplet Subsequence LeetCode Solution129
1120Constant time range add operation on an array128
1121Longest Increasing Consecutive Subsequence128
1122Third Maximum Number Leetcode Solution128
1123Iterative method to find ancestors of a given binary tree128
1124Mean of Array After Removing Some Elements Leetcode Solution128
1125Minimum sum of squares of character counts in a given string after removing k characters128
1126Valid Tic-Tac-Toe State LeetCode Solution128
1127Maximum Product Subarray128
1128Diameter of N-Ary Tree LeetCode Solution128
1129Bottom View of a Binary Tree128
1130Write Code to Determine if Two Trees are Identical128
1131Thousand Separator Leetcode Solution128
1132Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution128
1133Reformat The String Leetcode Solution128
1134Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1135Prime Palindrome LeetCode Solution127
1136Products of ranges in an array127
1137Minimum Score Triangulation of Polygon Leetcode Solution127
1138Print Right View of a Binary Tree127
1139Delete Nodes and Return Forest Leetcode Solution127
1140Maximum Product of Splitted Binary Tree LeetCode Solution127
1141Moser-de Bruijn Sequence126
1142Palindromic Substrings Leetcode Solution126
1143Cells with Odd Values in a Matrix LeetCode Solution126
1144Queries for Number of Distinct Elements in a Subarray126
1145Swap Nodes In Pairs126
1146Search Insert Position126
1147Search an Element in Sorted Rotated Array126
1148Find maximum length Snake sequence126
1149Maximum Binary Tree125
1150Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution125
1151Topological Sorting125
1152Red-Black Tree Introduction125
1153Merge two BSTs with limited extra space125
1154Subset Sum Problem in O(sum) space125
1155Kth Smallest Number in Multiplication Table Leetcode Solution124
1156Bus Routes Leetcode Solution124
1157Closest Binary Search Tree Value Leetcode Solution124
1158Transform a BST to Greater sum Tree124
1159Print modified array after executing the commands of addition and subtraction124
1160Priority Queue124
1161Maximize sum of consecutive differences in a circular array124
1162Check Array Formation Through Concatenation Leetcode Solution124
1163Find Largest Value in Each Tree Row LeetCode Solution123
1164Decision Tree123
1165Search Suggestions System LeetCode Solution123
1166Minimum Sideway Jumps LeetCode Solution123
1167Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution123
1168Web Crawler LeetCode Solution123
1169Rotate Array123
1170Possible Bipartition LeetCode Solution123
1171Golomb sequence123
1172Find a sorted subsequence of size 3 in linear time122
1173Find the smallest binary digit multiple of given number122
1174Compare Strings by Frequency of the Smallest Character Leetcode Solution122
1175Minimum Moves to Equal Array Elements LeetCode Solution122
1176K’th Largest element in BST using constant extra space122
1177Factorial Trailing Zeroes LeetCode Solution122
1178Longest Repeated Subsequence122
1179Minimum Cost to Move Chips to The Same Position LeetCode Solution122
1180Count even length binary sequences with same sum of first and second half bits122
1181Binary Tree to Binary Search Tree Conversion122
1182Matchsticks to Square Leetcode Solution121
1183Given a binary tree, how do you remove all the half nodes?121
1184Decrease Elements To Make Array Zigzag LeetCode Solution121
1185First Bad Version121
1186Lowest Common Ancestor in Binary Search Tree121
1187Graph and its representation121
1188Swapping Nodes in a Linked List Leetcode Solution121
1189Reverse a Path in BST using Queue121
1190Contiguous Array LeetCode Solution120
1191Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1192Number of Orders in the Backlog Leetcode Solution120
1193Sum of Left Leaves LeetCode Solution120
1194Reformat Date LeetCode Solution120
1195Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution120
1196Maximum number of segments of lengths a, b and c120
1197Maximum sum bitonic subarray120
1198Count Pairs Whose Products Exist in Array120
1199Queue Reconstruction by Height120
1200Maximum sum of pairs with specific difference120
1201Concatenation of Array LeetCode Solution119
1202How to print maximum number of A’s using given four keys119
1203Closest Leaf in a Binary Tree LeetCode Solution119
1204Valid Triangle Number119
1205Range Queries for Longest Correct Bracket Subsequence119
1206Maximum Depth Of Binary Tree119
1207Path Crossing Leetcode Solution119
1208BST to a Tree with Sum of all Smaller Keys118
1209Write a function to get the intersection point of two Linked Lists118
1210Moving Stones Until Consecutive Leetcode Solution118
1211Kth Smallest Element in a BST118
1212Champagne Tower LeetCode Solution118
1213Minimum Swaps To Make Sequences Increasing LeetCode Solution118
1214Queries on Probability of Even or Odd Number in given Ranges118
1215Lowest Common Ancestor of a Binary Tree Leetcode Solution118
1216LRU Cache Leetcode Solution117
1217Integer Break LeetCode Solution117
1218Perfect Squares LeetCode Solution117
1219Check if all levels of two Binary Tree are anagrams or not117
1220Guess The Word117
1221Divide Two Integers Leetcode Solution117
1222Array Queries for multiply replacements and product117
1223Replace two consecutive equal values with one greater116
1224Maximum sum of a path in a Right Number Triangle116
1225Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution116
1226Flatten 2D Vector LeetCode Solution116
1227Valid Perfect Square LeetCode Solution116
1228Sliding Window Median Leetcode Solution116
1229Mean of range in array116
1230Maximize Elements Using Another Array116
1231Maximum Value at a Given Index in a Bounded Array LeetCode Solution116
1232Design Skiplist LeetCode Solution115
1233Arithmetic Slices II – Subsequence LeetCode Solution115
1234Power of Two115
1235New 21 Game115
1236Range Sum Query using Sparse Table115
1237The kth Factor of n Leetcode Solution115
1238Maximum Array from Two given Arrays Keeping Order Same115
1239Check for Identical BSTs without building the trees114
1240Parallel Courses II LeetCode Solution114
1241Missing Number114
1242Bold Words in String LeetCode Solution114
1243Graph Cloning114
1244Find k-th smallest element in BST (Order Statistics in BST)114
1245Longest Common Prefix Using Word by Word Matching114
1246Find Minimum in Rotated Sorted Array II LeetCode Solution114
1247Check Completeness of a Binary Tree LeetCode Solution114
1248Check if each internal node of a BST has exactly one child114
1249Print modified array after multiple array range increment operations113
1250Count Subsets Having Distinct Even Numbers113
1251Largest Plus Sign Leetcode Solution113
1252Contiguous Array113
1253Maximum Product Subarray113
1254Find minimum number of merge operations to make an array palindrome112
1255Print Ancestors of a Given Binary Tree Node Without Recursion112
1256Symmetric Tree LeetCode Solution Leetcode Solution112
1257Merge k Sorted Lists Leetcode Solution112
1258Check if two nodes are on the same path in a Tree112
1259Print n terms of Newman-Conway Sequence112
1260Minimum Remove to Make Valid Parentheses LeetCode Solution111
1261Image Overlap LeetCode Solution111
1262Excel Sheet Column Title LeetCode Solution110
1263Smallest Range II Leetcode Solution110
1264Verify Preorder Serialization of a Binary Tree110
1265Number of elements less than or equal to a given number in a given subarray110
1266Count and Toggle Queries on a Binary Array110
1267Next greater element109
1268Check If a String Can Break Another String Leetcode Solution108
1269Orderly Queue LeetCode Solution108
1270Minimum Time to Collect All Apples in a Tree LeetCode Solution108
1271Palindrome Partitioning108
1272Different Ways to Add Parentheses Leetcode Solution107
1273Min Cost Climbing Stairs LeetCode Solution107
1274Koko Eating Bananas LeetCode Solution107
1275Longest Substring Without Repeating Characters Leetcode Solution106
1276Check in binary array the number represented by a subarray is odd or even106
1277Peeking Iterator LeetCode Solution106
1278Largest Submatrix With Rearrangements LeetCode Solution106
1279Check if X can give change to every person in the Queue105
1280Merge Sorted Array105
1281Newman–Shanks–Williams prime105
1282Queries for Decimal Values of Subarrays of a Binary Array104
1283Range Minimum Query (Square Root Decomposition and Sparse Table)103
1284Encoded String With Shortest Length LeetCode Solution102
1285Maximum Sum Increasing Subsequence102
1286Array Nesting Leetcode Solution102
1287Find maximum average subarray of k length101
1288Arranging Coins Leetcode Solution101
1289Number of indexes with equal elements in given range101
1290Check given array of size n can represent BST of n levels or not100
1291Convert a BST to a Binary Tree such that sum of all greater keys is added to every key100
1292Maximum product of an increasing subsequence100
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
1296Continuous Subarray Sum LeetCode Solution98
1297Random Pick Index LeetCode Solution98
1298Minimum Number of People to Teach LeetCode Solution98
1299Binary Tree to Binary Search Tree Conversion using STL set97
1300Add Two Numbers II Leetcode Solution97
1301Jump Game IV LeetCode Solution97
1302Reach a Number LeetCode Solution97
1303Queries on XOR of greatest odd divisor of the range96
1304Vertical Order Traversal of Binary Tree LeetCode Solution96
1305Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution96
1306Palindrome Number LeetCode Solution95
1307Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution94
1308Insert Delete GetRandom O(1) Leetcode Solution94
1309Design Underground System Leetcode Solution90
1310Shifting Letters LeetCode Solution89
1311Print Maximum Length Chain of Pairs89
1312Detect Capital Leetcode Solution88
1313Design A Leaderboard Leetcode Solution87
1314Substring with Concatenation of All Words Leetcode Solution85
1315Count Sub Islands LeetCode Solution83
1316Minimum Swaps to Group All 1’s Together Leetcode Solution83
1317Top K Frequent Elements LeetCode Solution83
1318Minimum Path Sum Leetcode Solution81
1319Binary Tree Inorder Traversal LeetCode Solution81
1320Longest Common Subsequence LeetCode Solution78
1321Maximum Population Year LeetCode Solution77
1322Find the Town Judge LeetCode Solution77
1323Odd Even Linked List Leetcode Solution77
1324Find the Town Judge LeetCode Solution76
1325Decode String Leetcode Solution76
1326Best Meeting Point LeetCode Solution76
1327Shortest Unsorted Continuous Subarray LeetCode Solution75
1328Sum Root to Leaf Numbers LeetCode Solution74
1329Rectangle Overlap LeetCode Solution71
1330Maximum Population Year LeetCode Solution71
1331Design Add and Search Words Data Structure LeetCode Solution71
1332Flatten Binary Tree to Linked List LeetCode Solution69
1333Score of Parenthesis LeetCode Solution68
1334Insert into a Sorted Circular Linked List LeetCode Solution67
1335Stone Game IV LeetCode Solution67
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution65
1338Valid Triangle Number LeetCode Solution64
1339Is Graph Bipartite? LeetCode Solution63
1340Divide Chocolate LeetCode Solution57
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution52
1342Reverse Integer Leetcode Solution47
1343Range Sum of BST LeetCode Solution46
1344Sort Colors LeetCode Solution43
1345Find K Closest Elements LeetCode Solution43
1346Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution40
1347Rotate String 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
1354Group Shifted Strings Leetcode Solution13
1355Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution12
1356Peak Index in a Mountain Array LeetCode Solution12
1357Unique Binary Search Trees LeetCode Solution11
1358Valid Triangle Number LeetCode Solution10
1359Next Greater Element I Leetcode Solution10
1360Next Permutation LeetCode Solution9
1361Isomorphic Strings LeetCode Solution9
1362Flatten Binary Tree to Linked List LeetCode Solution9
1363Closest Binary Search Tree Value II LeetCode Solution8
1364Valid Anagram Leetcode Solution8
1365Minimum Number of Arrows to Burst Balloons LeetCode Solution8
1366Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution8
1367Sentence Screen Fitting LeetCode Solution7
1368Swim in Rising Water LeetCode Solution7
1369Paint House LeetCode Solution5
Translate »