Group Shifted Strings Leetcode Solution

Difficulty Level Medium
Frequently asked in Amazon Bloomberg Facebook Google Uber
WixViews 7

Problem Statement

Group Shifted Strings Leetcode Solution – We can shift a string by shifting each of its letters to its successive letter.

  • For example, "abc" can be shifted to be "bcd".

We can keep shifting the string to form a sequence.

  • For example, we can keep shifting "abc" to form the sequence: "abc" -> "bcd" -> ... -> "xyz".

Given an array of strings strings, group all strings[i] that belong to the same shifting sequence. You may return the answer in any order.

Example 1:

Input:

 strings = ["abc","bcd","acef","xyz","az","ba","a","z"]

Output:

 [["acef"],["a","z"],["abc","bcd","xyz"],["az","ba"]]

Example 2:

Input:

 strings = ["a"]

Output:

 [["a"]]

Constraints:

  • 1 <= strings.length <= 200
  • 1 <= strings[i].length <= 50
  • strings[i] consists of lowercase English letters.

Approach

Idea:

  1. The basic idea of this problem is to set a key for each string
  2. how do we set a key for any string?
  3. we can say that if 2 strings belong to the same group then distance b/w adjacent characters in both remains the same
  4. for example bc and xyz.
  5. if s[i] – s[i – 1] is negative, we need to do (dis+26)%26 to it to make it positive and give the correct result
  6. we make an unordered map <string, vector<string> >    we store the string corresponding to the key in a hashmap.

Group Shifted Strings Leetcode SolutionPin

Code

C++ Program of  Group Shifted Strings

class Solution {
public:
    vector<vector<string>> groupStrings(vector<string>& strings) {

        unordered_map<string,vector<string> > mp;
        
        for(int i=0;i<strings.size();i++)
        {
            string key="-";
            string s=strings[i];
            
            for(int j=1;j<s.length();j++)
            {
               int dis=(s[j]-s[j-1]+26)%26;
               key.append(to_string(dis));
               key+='-';
            }
            mp[key].push_back(s);
        }
    
        vector<vector<string> > ans;
        for(auto itr:mp)
        {
            ans.push_back(itr.second);
        }  
        return ans;  
    }
};

Java  Program of  Group Shifted Strings

class Solution {
    public List<List<String>> groupStrings(String[] strings) {
        Map<String,List<String>> mp = new HashMap<>();
        for(int i=0;i<strings.length;i++)
        {    
            String s=strings[i];
            StringBuilder key  = new StringBuilder();
            key.append("-");
            for(int j = 1; j < s.length();j++)
            {
                int dis= (s.charAt(j) - s.charAt(j-1) + 26) % 26;
                // in case [0,1,11] [0,11,1], so i add "." to key.
                key.append(Integer.toString(dis));
                key.append("-");
               
           }
            String k = key.toString();
            if(!mp.containsKey(k)){
                List<String> value = new ArrayList<>();
                mp.put(k,value);
            }
            mp.get(k).add(s);
        }     
        List<List<String>> ans = new ArrayList<>();
        for(String key: mp.keySet()){
           ans.add(mp.get(key));
        }
        return ans;
    }
}

Complexity Analysis for Group Shifted Strings Leetcode Solution

Time Complexity

The time complexity of the above code is O(n*m)  where n is the size of the strings array and m is the   length of  string whose length is maximum in the array

Space Complexity

The space complexity of the above code is O(n) because we are using a hash map to store the groups.

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 Tree2508
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
9Write a program to print all permutations of a given string1614
10Quick Sort1546
11Find Minimum Distance Between Two Numbers in an Array1479
12Create a Doubly Linked List1454
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 duplicates1362
17First Repeating Element1346
18Arrange Even and Odd number such that Odd comes after Even1327
19Sum of numbers in String1324
20Smallest Positive Number Missing in an Unsorted Array1292
21Check if the Elements of an Array are Consecutive1261
22Detect a loop in the Linked List1246
23Largest Sum Contiguous Subarray1235
24Quick Sort on SIngly Linked List1223
25Subarray with Given Sum1217
26Print all Possible Combinations of R Elements in a given Array of size N1209
27Recursive function to do substring search1206
28Find the Maximum Repeating Number in Array1160
29Binary Tree Level order traversal in Java1131
30Find the First and Second Smallest Elements1126
31Check if two linked lists are identical1112
32Maximum Subarray Sum using Divide and Conquer1108
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 II997
38Find the second most frequent character994
39Given a string find its first non-repeating character976
40Find Triplet in Array With a Given Sum968
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 not952
44Print all possible words from phone digits940
45Find the Missing Number931
46Rearrange Positive and Negative Numbers Alternatively in Array926
47Longest Palindromic Substring910
48Segregate even and odd nodes in a linked list892
49Print Longest common subsequence888
50Union and Intersection of Two Linked Lists879
51Transform one string to another using minimum number of given operations873
52Check rearranged string can form a palindrome855
53Rearrange given Array in Maximum Minimum Form851
54Iterative Implementation of Quick Sort841
55Count Possible Triangles826
56Multiplication of Two Matrices808
57Rotate a Linked List801
58Check if the linked list is palindrome801
59Count of Triplets With Sum Less than Given Value800
60Stock Buy Sell to Maximize Profit797
61Insertion Sort770
62Concatenation of two strings768
63Tug of War766
64Print all duplicates in the input string762
65Count Number of Substrings with K Distinct Character’s761
66Find Nearest Greater and Smaller Element751
67The Celebrity Problem744
68Find Pythagorean Triplets from Array742
69Reverse String Without Temporary Variable738
70Remove ‘b’ and ‘ac’ from a given string737
71Find all Common Elements in Given Three Sorted Arrays735
72Remove all duplicates in an unsorted linked list714
73Find the Row with Maximum Number of 1’s712
74Find the Peak Element from an Array704
75Find the subarray whose sum is equal to a given number X702
76Remove Minimum Characters so that Two Strings Become Anagrams697
77Addition of Two Matrices692
78Find Smallest Missing Number in a Sorted Array691
79A Product Array Puzzle689
80Generate all Binary Strings Without Consecutive 1’s683
81Implement Two Stacks in an Array682
82Maximum Sum of Non Consecutive Elements676
83Lexicographic rank of string662
84Maximum Product Subarray II661
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 parts631
91Online Algorithm for Checking Palindrome in a Stream629
92Form Minimum Number from Given Sequence of D’s and I’s628
93Remove recurring digits in a given number622
94Check whether two strings are anagram of each other621
95Sort a linked list that is sorted alternating ascending and descending617
96Maximum Circular Subarray Sum616
97Sort a stack using a temporary stack613
98Move last element of the Linked List at first place610
99Find the Minimum Element in a Sorted and Rotated Array610
100Subarray and Subsequence606
101First Circular Tour to Visit all the Petrol Bunks604
102Largest Subarray with Equal Number of 0’s and 1’s602
103Compare two strings(linked lists)599
104Flattening a linked list599
105Maximum Element in an Array which is Increasing and then Decreasing596
106Palindrome Permutations of a String591
107Palindromes in a given range585
108Elements Appear more than N/K times in Array585
109Print all permutations with repetition583
110Majority Element582
111Run length encoding582
112Pangram Checking578
113Minimum insertions to form a shortest palindrome578
114Minimum Characters to be Added at Front to Make String Palindrome572
115Remove all duplicates in a sorted linked list570
116Merge a linked list into another at alternate positions570
117Rearrange a given linked list in-place569
118Most repeating character in a string569
119Minimum number of Merge Operations to make an Array Palindrome567
120Rotate string to get lexicographically minimum string564
121Repeated Subsequence of Length Two or More561
122Print all anagrams together in a sequence of words559
123Reorder an Array According to the Given Indexes557
124Pancake Sorting Problem548
125Two Sum Leetcode Solution544
126Merge Overlapping Intervals II542
127Clone a Linked List with next and random pointer542
1283Sum Leetcode Solution540
129Size of The Subarray With Maximum Sum533
130Transpose of a Matrix533
131Remove Extra Spaces from a String530
132Removing Spaces from a String using stringstream528
133Remove duplicates from a string526
134Check if a given string is a rotation of a palindrome525
135Longest Palindrome can be Formed by Removing or Rearranging Characters524
136Partition Problem524
137Smallest Palindrome after Replacement523
138Maximum Sum Increasing Subsequence522
139Check whether Strings are K Distance Apart or Not514
140Generate all Binary Strings from Given Pattern511
141Length of Longest valid Substring510
142Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized507
143Insert Node in the Sorted Linked List506
144Delete Last Occurrence504
145Check if Two given Strings are Isomorphic to each other501
146Maximum difference between two elements such as larger element comes after smaller494
147Program to Toggle all Characters in a String492
148Given string is interleaving of two other strings or not489
149Count Minimum Steps to Get the given Array485
150Merge sort better than quick sort for linked lists483
151Number of Smaller Elements on Right Side481
152Find Pair with Given Difference480
153Check if all Rows of a Matrix are Circular Rotations of Each Other479
154Check length of a String is Equal to the Number Appended at its Last479
155Find nth node of the Linked list from the end476
156Longest Common Prefix using Divide and Conquer475
157Print all interleavings of given two strings467
158Find a Fixed Point in a Given Array467
159Sort 0s 1s and 2s in an Array466
160Compare Two Version Numbers465
161Reverse words in a given string462
162Find the Subarray of given length with Least Average461
163Reorder Array Using Given Indexes459
164Print Reverse of a string (Recursion)459
165Merge two sorted linked lists such that merged list is in reverse order459
166Split linked list using alternate nodes458
167Median of Two Sorted Arrays LeetCode Solution456
168Print string of odd length in ‘X’ format445
169Print all Palindromic Partitions of a String440
170Find K Length Subarray of Maximum Average440
171Find Element Using Binary Search in Sorted Array439
172Swap Kth Node from beginning with Kth Node from End437
173Find Duplicates in an Array in Most Efficient Way433
174print all palindromic partitions426
175Flatten a multilevel linked list424
176Shortest Superstring Problem421
177Maximum Length of Chain Pairs420
178Check if String Follows Order of Characters by a Pattern or not419
179Sorting a K Sorted Array415
180Sort a String According to Another String412
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 lists398
185Program to add two binary digits397
186Find the two Numbers with Odd Occurrences in an Unsorted Array394
187Longest Common Prefix Using Binary Search II392
188Reverse a Singly Linked List (Iterative/Non-Recursive)391
189Caesar Cipher388
190Kth Non-repeating Character387
191Rearrange a linked list in Zig-Zag386
192Check if String can Become Empty by Recursively Deleting given Substring383
193Pancake Sorting380
194Longest Common Prefix Word by Word Matching380
195Rotate Image by 90 degrees380
196Permutations of a Given String Using STL373
197Perfect Reversible String372
198Merging Two Sorted Arrays368
199Increasing Subsequence of Length three with Maximum Product368
200Sort a linked list with 0s, 1s and 2s366
201Find the point where a monotonically increasing function becomes positive first time366
2021`s and 2`s complement of binary number366
203Find First non-repeating character in a string365
204Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes363
205Four Elements that Sum to Given362
206List items containing all characters of a given word360
207Delete N nodes after M357
208Longest Common Prefix using Character by Character Matching353
209Count Number of Occurrences in a Sorted Array351
210Palindrome string (number)350
211Split a string347
212Minimum Characters to be Removed to Make a Binary String Alternate343
213Recursive Implementation of atoi()341
214Check if a Linked list of Strings form a Palindrome341
215Print All Distinct Elements of the Array338
216Sorting the array of strings337
217Even Substring Count336
218Maximum occurring character in a string335
219Convert a String that is Repetition of a Substring of Length K334
220Valid Parentheses LeetCode Solution333
221Reverse a singly linked list recursively333
222Find the first Repeating Number in a Given Array333
223Print Shortest Path to Print a String on Screen330
224Can we reverse a linked list in less than O(n) time ?329
225Binary Tree to Doubly linked list327
226Convert string1 to string2 in one edit327
227Reverse a String using Stack326
228wildcard character matching325
229Nth Character in Concatenated Decimal String323
230Sort Elements by Frequency II323
231Maximum Subarray Leetcode Solution322
232Lower Case To Upper Case318
233Count the number of words318
234Merge Two Sorted Arrays316
235Split Four Distinct Strings315
236Find the Lost Element From a Duplicated Array314
237Find middle of the Linked List312
238Longest Common Subsequence with Permutations309
239Count the Pairs at Same Distance as in English Alphabets307
240Matrix Chain Multiplication using Dynamic Programming305
241Next Greater Element in an Array301
242Palindrome Permutation297
243Roman to Integer Leetcode Solution292
244Find Nth Node291
245Find All Pairs With a Given Difference290
246Searching a node in a Binary Search Tree290
247Triplet from three linked lists with given sum286
248Delete a Tree285
249String(represents an integer) to value283
250Reverse a String283
251Word Search Leetcode Solution283
252Print all Possible Ways to Break a String in Bracket Form281
253Reverse Bits281
254Delete a node under given conditions280
255Change Gender of a given String278
256Binary Tree278
257How to Efficiently Implement k Stacks in a Single Array?276
258Sort an array of strings276
259Count Pairs With Given Sum274
260First non Repeating Element274
261Number of sub-strings which recursively add up to 9272
262Longest Common Extension271
263Meeting Rooms II LeetCode Solution271
264Toeplitz Matrix270
265Remove middle points in a linked list of line segments270
266Move all negative elements to one side of array270
267N queen problem269
268Repeated Substring Pattern269
269Longest Palindromic Substring LeetCode Solution266
270Remove spaces from a string266
271Shuffle a given Array264
272Min Stack262
273Number of Islands LeetCode Solution260
274Cuckoo sequence program259
275Dijkstra Algorithm258
276House Robber Leetcode Solution257
277Max stack256
278Find, second, frequent, character256
279Minimize the maximum difference between the heights254
280Most Frequent Element in an Array254
281Fibonacci numbers252
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 values249
286Valid Palindrome Leetcode Solution248
287Sudoku Solver248
288Subset Leetcode248
289Plus One Leetcode Solution247
290Word Search246
291Number Of 1 bits246
292KMP Algorithm246
293Combination Sum Leetcode Solution245
294Evaluation of Postfix Expression245
295Min Stack Leetcode Solution244
296Reverse words in a string244
297How to Delete a Linked List244
298Backspace String Compare239
299Set Matrix Zeroes238
300Sqrt(x) Leetcode Solution236
301Merge Sorted Arrays Leetcode Solution236
302Reversing a Queue235
303Rabin Karp Algorithm234
304Pair of Positive Negative Values in an Array234
305Subarray with 0 sum233
306Common elements in all rows of a given matrix233
307Tower Of Hanoi233
308Product of array except self230
309Delete middle element of a stack230
310Contains Duplicate II Leetcode Solution230
311Integer to Roman Leetcode Solution229
312Combination Sum229
313String Compression228
314Intersection of Two Arrays II Leetcode Solution228
315Pascal Triangle Leetcode227
316Reverse individual words226
317Count subarrays with equal number of 1’s and 0’s225
318Minimum swaps required to bring all elements less than or equal to k together225
319Implementation of Deque using Doubly Linked List224
320Construct Binary Tree from Given Inorder and Preorder Traversals224
321Count of index pairs with equal elements in an array224
322Bellman Ford Algorithm224
323Single Number Leetcode Solution223
324Add Binary Leetcode Solution223
325Sliding Window Technique223
326Find Top K (or Most Frequent) Numbers in a Stream223
327Minimum Value to Get Positive Step by Step Sum Leetcode Solution221
328Segregate even and odd numbers221
329Arithmetic Expression Evaluation221
330Second Most Repeated Word in a Sequence220
331Sort elements by frequency220
332Contains Duplicate220
333Palindrome Linked List Leetcode Solution219
334Page Replacement Algorithms in Operating Systems219
335Pow(x, n) Leetcode Solution219
336Count Odd Numbers in an Interval Range Leetcode Solution219
337Group Words With Same Set of Characters218
338Postfix to Infix Conversion218
339Find sum of non-repeating elements (distinct) elements in an array218
340Maximum Number of Balloons Leetcode Solution217
341Design a stack that supports getMin() in O(1) time and O(1) extra space217
342Next Permutation217
343Kruskal Algorithm217
344Smallest Subarray with k Distinct Numbers216
345Sum of minimum and maximum elements of all subarrays of size k215
346Third Maximum Number Leetcode Solution215
347Scramble String215
348Convex Hull Algorithm214
349Permutations Leetcode Solution214
350Longest Substring Without Repeating Characters LeetCode Solution214
351Find Lucky Integer in an Array Leetcode Solution213
352Maximum Subarray213
353K-th Smallest Element in a Sorted Matrix213
354Top K Frequent Words213
355Minimum operation to make all elements equal in array212
356Find the Town Judge Leetcode Solution212
357Longest Common Prefix Leetcode Solution211
358Find Numbers with Even Number of Digits Leetcode Solution211
359Sorting array using Stacks211
360Count subarrays having total distinct elements same as original array210
361Majority Element Leetcode Solution210
362Evaluate Division210
363Given two unsorted arrays find all pairs whose sum is x209
364Special Number209
365First element occurring k times in an array209
366Number of Good Pairs Leetcode Solution209
367Spiral Matrix LeetCode Solution208
368Swap Nodes in Pairs Leetcode Solutions208
369Prefix to Infix Conversion207
370Merge Two Sorted Lists Leetcode Solutions207
371Minimum Path Sum207
372Huffman Coding207
373Pascal’s Triangle II Leetcode Solution206
374Check if two arrays are equal or not206
375Reverse a Number Using Stack206
376Missing Number Leetcode Solution206
377Count Primes Leetcode Solutions206
378Minimum Steps to reach target by a Knight205
379Best Time to Buy and Sell Stock  II Leetcode Solution205
380Reversing the First K elements of a Queue205
381Search in Rotated Sorted Array Leetcode Solution205
382House Robber II Leetcode Solution204
383Single Number204
384Maximal Square204
385Sort Array by Increasing Frequency Leetcode Solution204
386Find duplicates in a given array when elements are not limited to a range204
387Minimum Absolute Difference Leetcode Solution204
388Power of Two Leetcode Solution203
389Group Anagrams203
390Top K Frequent Elements202
391Maximum Distance Between two Occurrences of Same Element in Array202
392Find All Numbers Disappeared in an Array Leetcode Solution202
393Matrix Diagonal Sum Leetcode Solution202
394Maximum possible difference of two subsets of an array201
395Check if Array Contains Contiguous Integers With Duplicates Allowed201
396Convert String To Int201
397Palindrome Substring Queries201
398Fizz Buzz Leetcode201
399Running Sum of 1d Array Leetcode Solution201
400Expression Contains Redundant Bracket or Not201
401Unique Paths Leetcode Solution201
402Sorting using trivial hash function201
403Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution200
404Find the first repeating element in an array of integers200
405Subarray Sum Equals k200
406Find Minimum In Rotated Sorted Array200
407How to Implement Stack Using Priority Queue or Heap?200
408Unique Paths200
409Zigzag Conversion200
410Cumulative Frequency of Count of Each Element in an Unsorted Array199
411Range Sum Query 2D – Immutable Leetcode Solution199
412How Many Numbers Are Smaller Than the Current Number Leetcode Solution199
413Sort Integers by The Number of 1 Bit Leetcode Solution199
414Smallest Element Repeated Exactly K Times199
415Max Consecutive Ones Leetcode Solution199
416Happy Number Leetcode Solution198
417Find the Closest Palindrome number198
418Subset sum problem198
419Coin Change 2 Leetcode Solution198
420Leetcode Permutations198
421Find Number of Employees Under every Employee198
422Difference between highest and least frequencies in an array197
423Subarray Sum Equals K LeetCode Solution197
424Decode String197
425Print All Distinct Elements of a Given Integer Array197
426Letter Case Permutation197
427Find Winner on a Tic Tac Toe Game Leetcode Solution197
428Remove Duplicates from Sorted Array Leetcode Solution196
429Monotonic Array LeetCode Solution196
430Implement Stack and Queue using Deque196
431Best Time to Buy and Sell Stock III Leetcode Solution196
432Reverse Integer196
433Sort a stack using recursion196
434Length of the largest subarray with contiguous elements196
435Find top three repeated in array195
436Nth Catalan Number195
437Fibonacci Number LeetCode Solution195
438LRU Cache Implementation195
439Generate a String With Characters That Have Odd Counts Leetcode Solution194
440Sum of Subarray Ranges Leetcode Solution194
441Reverse a Stack Using Recursion194
442Reverse Vowels of a String Leetcode Solution194
443Count Substrings with equal number of 0s, 1s and 2s194
444Capacity To Ship Packages Within D Days Leetcode Solution194
445Reverse Words in a String III LeetCode Solution193
446Print all subarrays with 0 sum193
447Find Median from data Stream193
448Subtract the Product and Sum of Digits of an Integer Leetcode Solution193
449Maximum Depth of Binary Tree Leetcode Solution193
450Find The Duplicate Number193
451Delete a Node from linked list without head pointer192
452Subarrays with distinct elements192
453Check If N and Its Double Exist Leetcode Solution192
454Integer to English words192
455Shuffle the Array Leetcode Solution192
456Trapping Rain Water Leetcode Solution192
457Bipartite Graph192
458Prim’s Algorithm192
459Merge Two Sorted Linked Lists192
460Target Sum191
461Find the Difference Leetcode Solution191
462Find the Duplicate Element191
463Excel Sheet Column Number Leetcode Solution190
464Kth largest element in an Array Leetcode Solutions190
465Find Common Characters Leetcode Solution190
466Longest Common Subsequence190
467Count and Say190
468Iterative Tower of Hanoi190
469Priority Queue Using Singly Linked List190
470Reverse a String190
471Sorting a Queue without Extra Space190
472Find all pairs (a, b) in an array such that a % b = k190
473Fizz Buzz189
474Edit Distance189
475Text Justification LeetCode Solution189
476Balanced Binary Tree Leetcode Solution189
477Concatenation of Array LeetCode Solution189
478Minimum Moves to Equal Array Elements Leetcode Solution188
479Remove Minimum Number of Elements Such That no Common Element Exist in both Array188
480Kids With the Greatest Number of Candies Leetcode Solution188
481Next Greater Element I Leetcode Solution188
482The K Weakest Rows in a Matrix Leetcode Solution188
483Degree of an array188
484Longest Common Prefix using Trie188
485Reverse a linked list188
486Count pairs from two linked lists whose sum is equal to a given value188
487Kth Largest Element in a Stream Leetcode Solution187
488Find elements which are present in first array and not in second187
489Floyd Warshall Algorithm187
490Word Ladder LeetCode Solution187
491Find First and Last Position of Element in Sorted Array Leetcode Solution187
492Number of Steps to Reduce a Number to Zero Leetcode Solution187
493Design Parking System Leetcode Solution187
494Merge Overlapping Intervals186
495Prefix to Postfix Conversion186
496Shortest Palindrome186
497Find subarray with given sum (Handles Negative Numbers)186
498Slowest Key Leetcode Solution186
499Longest subarray not having more than K distinct elements186
500The Stock Span Problem185
501Count and Say Leetcode Solution185
502Multiply Strings Leetcode Solution185
503Flood Fill LeetCode185
504MiniMax Algorithm185
505Valid Parenthesis String185
506Find N Unique Integers Sum up to Zero Leetcode Solution185
507Top View of Binary Tree185
508Zigzag Conversion LeetCode Solution185
509Find four elements that sum to a given value (Hashmap)185
510Jump Game Leetcode Solution184
511Move Zeroes LeetCode Solution184
512Postfix to Prefix Conversion184
513Convert array into Zig-Zag fashion184
514Priority Queue in C++184
515Substring With Concatenation Of All Words184
516Max Area of Island184
517Peak Index in a Mountain Array183
518Recursion183
519Find any one of the multiple repeating elements in read only array183
520Find distinct elements common to all rows of a matrix183
521Pair with given product183
522Shuffle String Leetcode Solution183
523Find Index of Closing Bracket for a Given Opening Bracket in an Expression183
524Length of Last Word Leetcode Solution183
525Next Greater Frequency Element183
526Mobile Numeric Keypad Problem183
527Longest Common Prefix using Sorting182
528Check if a given array contains duplicate elements within k distance from each other182
529Count number of triplets with product equal to given number182
530Implement a stack using single queue182
531Iterative Inorder Traversal of a Binary Tree182
532Intersection of Two Arrays182
533Relative Sort Array Leetcode Solution181
534Implement Stack using Queues181
535Largest Sum Contiguous Subarray181
536Excel Sheet Column Title Leetcode Solution181
537Last Stone Weight181
538Contiguous Array Leetcode181
539Find missing elements of a range181
540Delete Node in a Linked List Leetcode Solution181
541Smallest Subarray With all Occurrences of a Most Frequent Element180
542Koko Eating Bananas Leetcode Solution180
543Rearrange a binary string as alternate x and y occurrences180
544Is Subsequence Leetcode Solution179
545Minimum Bracket Reversals179
546Change the Array into Permutation of Numbers From 1 to N179
547Convert a normal BST to Balanced BST179
548Valid Sudoku179
549Distribute Candies to People Leetcode Solution179
550Linked List Cycle II LeetCode Solution179
551N-th Tribonacci Number Leetcode Solution179
552Jewels and Stones Leetcode Solution178
553Minimum Operations to convert X to Y178
554K-th Distinct Element in an Array178
555Container with Most Water178
556Best Time to Buy and Sell Stock178
557Implementation of Deque using circular array178
558Group Multiple Occurrence of Array Elements Ordered by first Occurrence178
559Isomorphic Strings Leetcode Solution178
560Build Array From Permutation Leetcode Solution177
561First negative integer in every window of size k177
562Island Perimeter Leetcode Solution177
563Shuffle an Array177
564Largest Perimeter Triangle Leetcode Solution177
565Check for Balanced Parentheses in an Expression177
566Arrange given numbers to form the biggest number177
567Integer to Roman177
568Unique Binary Search Trees177
569Valid Anagrams177
570Assign Cookies Leetcode Solution177
571Sum of Left Leaves Leetcode Solutions177
572Convert Sorted Array to Binary Search Tree Leetcode Solution177
573Gold Mine Problem177
574Minimum Knight Moves LeetCode Solution177
575Find Words That Can Be Formed by Characters Leetcode Solution177
576Remove Linked List Elements Leetcode Solution176
57701 Matrix LeetCode Solution176
578Minimum Delete Operations to make all Elements of Array Same176
579Hamming Distance176
580Trapping Rain Water LeetCode Solution176
581Combinations Leetcode Solution176
582Rotate List Leetcode Solution175
583LRU Cache LeetCode Solution175
584Summary Ranges Leetcode Solution175
585Count all subsequences having product less than K175
586The Knapsack Problem175
587Find the smallest positive integer value that cannot be represented as sum of any subset of a given array175
588Decode Ways174
589Shortest Path in a Grid with Obstacles Elimination LeetCode Solution174
5903Sum Closest LeetCode Solution174
591Count the number of nodes at given level in a tree using BFS174
592Maximum sum rectangle in a 2D matrix174
593Insert Interval Leetcode Solution173
594Find minimum difference between any two elements173
595Maximum Distance in Array173
596Maximum Number of Chocolates to be Distributed Equally Among k Students173
597Maximum path sum in a triangle173
598Distance Between Bus Stops Leetcode Solution173
599Minimum number of distinct elements after removing m items173
600Minimum insertions to form a palindrome with permutations allowed172
601Same Tree LeetCode Solution172
602Sieve of Eratosthenes171
603Rotate Image LeetCode Solution171
604Stone Game LeetCode171
605Sort Characters By Frequency LeetCode Solution171
606Painting Fence Algorithm171
607Permutation in String Leetcode Solution171
608Applications of Breadth First Search and Depth First Search171
609Minimum number of subsets with distinct elements171
610Find if an Expression has Duplicate Parenthesis or Not171
611Reverse a stack without using extra space in O(n)171
612How to check if two given sets are disjoint?171
613Replace Elements with Greatest Element on Right Side Leetcode Solution171
614Word Pattern170
615Frog Jump Leetcode Solution170
616Find the Duplicate Number LeetCode Solution170
617XOR Operation in an Array Leetcode Solution170
618Remove All Occurrences of a Substring LeetCode Solution170
619K Empty Slots LeetCode170
620Longest Increasing Subsequence170
621Smallest Good Base170
622Sort Array By Parity LeetCode Solution170
623Word Wrap Problem170
624Bubble sort using two Stacks170
625Tracking current Maximum Element in a Stack169
626Isomorphic Strings169
627Defanging an IP Address Leetcode Solution169
628House Robber169
629Minimum Depth of Binary Tree Leetcode Solution169
630Minimum Cost to Hire K Workers169
631Maximum Consecutive Numbers Present in an Array169
632Printing brackets in Matrix Chain Multiplication Problem169
633Best Time to Buy and Sell Stock LeetCode Solution169
634Distance of nearest cell having 1 in a binary matrix169
635Non-overlapping sum of two sets169
636Valid Palindrome II Leetcode Solution168
637Wiggle Sort168
638Segregate 0s and 1s in an Array168
639License Key Formatting Leetcode Solution168
640Coin Change Problem168
641Optimal Account Balancing LeetCode Solution168
642Longest Substring with At Most K Distinct Characters LeetCode Solution168
643Find Sum of all unique sub-array sum for a given array168
644Moving Average from Data Stream Leetcode Solution167
645Iterative Method to find Height of Binary Tree167
646Binary Tree Zigzag Level Order Traversal LeetCode Solution167
647Sum of All Odd Length Subarrays Leetcode Solution167
648Count Good Nodes in Binary Tree Leetcode Solution167
649Find Maximum Level sum in Binary Tree167
650Maximum difference between first and last indexes of an element in array167
651How to Create Mergable Stack?167
652Kth Missing Positive Number Leetcode Solution167
653Path With Maximum Minimum Value LeetCode Solution167
654Reorganize String166
655Merge Two Balanced Binary Search Trees166
656Maximum Number of Occurrences of a Substring Leetcode Solution166
657Best Time to Buy and Sell Stock with Cooldown Leetcode Solution166
658GCD Of Two Numbers166
659Check If It Is a Straight Line Leetcode Solution166
660Strobogrammatic Number LeetCode Solution166
661Queries for counts of array elements with values in given range166
662Employee Free Time LeetCode Solution166
663Find the Distance Value Between Two Arrays Leetcode Solution166
664Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions166
665Flipping an Image LeetCode Solution165
666Convert an array to reduced form165
667Find Largest d in Array such that a + b + c = d165
668Valid Palindrome165
669Reducing Dishes LeetCode Solution165
670Delete consecutive same words in a sequence165
671Number of Provinces Leetcode Solution165
672Letter Combinations of a Phone Number165
673Longest Substring with At Least K Repeating Characters LeetCode Solution165
674Print the Fibonacci numbers in reverse order165
675Partition Labels LeetCode Solution164
676Maximum Number of Coins You Can Get Leetcode Solution164
677K Empty Slots164
678Check If Two String Arrays are Equivalent Leetcode Solution164
679Find pairs with given sum such that elements of pair are in different rows164
680Remove Invalid Parentheses Leetcode Solution164
681Factorial Trailing Zeroes Leetcode Solution164
682Partition Array Into Three Parts With Equal Sum Leetcode Solution163
683Populating Next Right Pointers in Each Node163
684Recover Binary Search Tree163
685Number of Dice Rolls With Target Sum LeetCode Solution163
686Inorder Successor of a node in Binary Tree163
687Increasing Decreasing String Leetcode Solution163
688Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest163
689To Lower Case Leetcode Solution163
690BFS vs DFS for Binary Tree163
691Longest Increasing Path in a Matrix LeetCode Solution163
692Delete Nth node from the end of the given linked list163
693Valid Perfect Square Leetcode Solution163
694Lucky Numbers in a Matrix Leetcode Solution163
695Power of Four Leetcode Solution163
696Permutation Sequence LeetCode Solution163
697Edit Distance LeetCode Solution163
698Merge Two Binary Trees LeetCode Solution162
699Maximum Product of Two Elements in an Array Leetcode Solution162
700Check if a queue can be sorted into another queue using a stack162
701Construct BST from given Preorder Traversal162
702Ugly Number Leetcode Solution162
703String to Integer (atoi) LeetCode Solution162
704Form minimum number from given sequence162
705Sort Array by Increasing Frequency Leetcode Solution162
706Dynamic Programming Basics162
707Unique Paths II Leetcode Solution162
708Robot Room Cleaner Leetcode Solution161
709Find whether an array is subset of another array161
710Reverse Only Letters LeetCode Solution161
711Binary Tree zigzag level order Traversal161
712Reversing a Queue using Recursion161
713Subset Sum Leetcode161
714Reservoir Sampling161
715Convert a Number to Hexadecimal Leetcode Solution161
716Find the Smallest Divisor given a Threshold Leetcode Solution161
717Find Leaves of Binary Tree LeetCode Solution161
718Decompress Run-Length Encoded List Leetcode Solution160
719Add and Search Word – Data structure design LeetCode160
720Finding K closest element160
721Restore IP Addresses Leetcode Solution160
722Perform String Shifts Leetcode160
723Binomial Coefficient160
724Majority Element II Leetcode Solution160
725Keyboard Row Leetcode Solution160
726Race Car LeetCode Solution159
727Find the node with minimum value in a Binary Search Tree159
728Bulb Switcher LeetCode Solution159
729Numbers with prime frequencies greater than or equal to k159
730Find the largest multiple of 3159
731Check if Two Expressions With Brackets are Same159
732Number of Islands II LeetCode Solution158
733Morris Traversal158
734Sum of f(a[i], a[j]) over all pairs in an array of n integers158
735Find Pair with Greatest Product in Array158
736Minimum Distance Between BST Nodes Leetcode Solution158
737Maximum 69 Number Leetcode Solution158
738Merge K Sorted Linked Lists158
739Generate all possible sorted arrays from alternate elements of two given sorted arrays158
740Rank Transform of an Array Leetcode Solution158
741Minimum Height Trees158
742Maximum Product of Three Numbers LeetCode Solution158
743Hamming Distance Leetcode Solution158
744Minimum Cost For Tickets Leetcode Solution158
745Sorted Linked List to Balanced BST157
746Diagonal Traversal of Binary Tree157
747First Unique Character in a String LeetCode Solution157
748Maximum Depth of N-ary Tree Leetcode Solution157
749String Compression LeetCode Solution157
750Non-decreasing Array LeetCode Solution157
751Find Maximum Depth of Nested Parenthesis in a String157
752Student Attendance Record I Leetcode Solution157
753Find if Path Exists in Graph Leetcode Solution157
754Tiling Problem157
755Word Pattern LeetCode Solution157
756Longest Span with same Sum in two Binary arrays157
757Invert Binary Tree LeetCode Solution157
758Total Numbers With no Repeated Digits in a Range156
759Symmetric Tree Leetcode Solution156
760Find unique character in a string156
761Special Array With X Elements Greater Than or Equal X Leetcode Solution156
762Check If Array Pairs Are Divisible by k LeetCode Solution156
763Elements to be added so that all elements of a range are present in array156
764Find All Duplicates in an Array LeetCode Solution156
765Kth ancestor of a node in binary tree156
766Binary Tree Maximum Path Sum LeetCode Solution156
767Queue based approach for first non-repeating character in a stream156
768Minimum time required to rot all oranges156
769Remove brackets from an algebraic string containing + and – operators156
770Minimize Maximum Pair Sum in Array LeetCode Solution156
771Stack Permutations (Check if an array is stack permutation of other)156
772Snakes and Ladders LeetCode Solution156
773Remove Nth Node From End of List Leetcode Solution156
774Largest subarray with equal number of 0s and 1s156
775Best Meeting Point LeetCode Solution156
776Linked List Cycle155
777Evaluate Reverse Polish Notation LeetCode Solution155
778Partition to K Equal Sum Subsets Leetcode Solution155
779Find Median from Data Stream LeetCode Solution155
780Largest Rectangle in Histogram LeetCode Solution155
781Final Prices With a Special Discount in a Shop Leetcode Solution155
782Largest rectangular sub-matrix whose sum is 0155
783Search a 2D Matrix II Leetcode Solution155
784Maximum Length of a Concatenated String with Unique Characters Leetcode Solution155
785Jump Game155
786Count items common to both the lists but with different prices154
787Search in a Binary Search Tree Leetcode Solution154
788Valid Number154
789Split a String in Balanced Strings Leetcode Solution154
790Check for Palindrome after every character replacement Query154
791Transpose Graph154
792N-Queens LeetCode Solution154
793Interval Tree154
794Number of NGEs to the Right154
795Maximum Difference Between Increasing Elements LeetCode Solution154
796k-th missing element in increasing sequence which is not present in a given sequence154
797Program for Bridge and Torch problem154
798Deletion in a Binary Tree154
799Minimum number of jumps to reach end153
800Last Stone Weight II LeetCode Solution153
801Get Maximum in Generated Array Leetcode Solution153
802Sort an array according to the order defined by another array153
803Base 7 Leetcode Solution153
804Growable array based stack153
805Circular Queue153
806Nearest Exit from Entrance in Maze LeetCode Solution153
807Print a Binary Tree in Vertical Order153
808One Edit Distance LeetCode Solution153
809String comparison containing wildcards153
810Minimum Jumps to Reach Home LeetCode Solution153
811Minimum Time Visiting All Points Leetcode Solution153
812Count quadruples from four sorted arrays whose sum is equal to a given value x153
813A Space Optimized DP solution for 0-1 Knapsack Problem152
814Number Complement Leetcode Solution152
815Longest Subarray Having Count of 1s One More than Count of 0s152
816Minimum swaps to make sequences increasing152
817Iterative Preorder Traversal152
818Remove Duplicates from Sorted List II152
819Reorder Data in Log Files LeetCode Solution152
820Subarray Product Less Than K LeetCode Solution152
821Course Schedule II – LeetCode152
822Remove Duplicates from Sorted List LeetCode Solution152
823Find all triplets with zero sum152
824Nested List Weight Sum II LeetCode Solution152
825Priority Queue using doubly linked list152
826Crawler Log Folder Leetcode Solution152
827Maximum Profit in Job Scheduling Leetcode Solution152
828Merge Sorted Array LeetCode Solution152
829Relative Ranks Leetcode Solution152
830Sort Array By Parity II Leetcode Solution151
831Spiral Matrix II Leetcode Solution151
832Form Minimum Number From Given Sequence151
833Maximum size subarray sum equals k151
834Top K Frequent Words LeetCode Solution150
835Alien Dictionary LeetCode Solution150
836Minimum Number of Taps to Open to Water a Garden LeetCode Solution150
837Path with maximum average value150
838Given an Array of Pairs Find all Symmetric Pairs in it150
839Brick Wall LeetCode Solution150
840Find the subarray with least average150
841Check if a given array can represent Preorder Traversal of Binary Search Tree150
842Insert into a Binary Search Tree Leetcode Solution150
843Maximum Nesting Depth of the Parentheses Leetcode Solution150
844Regular Expression Matching150
845Subset with sum divisible by m150
846Can Place Flowers LeetCode Solution150
847Convert BST to Min Heap150
848Sum of nearest smaller and greater number150
849Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution150
850Valid Parentheses Leetcode Solution150
851Minimum Sum Path in a Triangle149
852Friends Pairing Problem149
853Check whether a given Binary Tree is Complete or not149
854Permutation Coefficient149
855Brightest Position on Street LeetCode Solution149
856Subsequence of Size K With the Largest Even Sum LeetCode Solution149
857Binary Search Tree Search and Insertion149
858Balanced Expression with Replacement149
859Partition List Leetcode Solution149
860Sort Colors149
861Count Distinct Elements in Every Window of Size K149
862Count Negative Numbers in a Sorted Matrix LeetCode Solution149
863Level order Traversal in Spiral Form149
864Find All Possible Recipes from Given Supplies LeetCode Solution149
865Guess Number Higher or Lower LeetCode Solution149
866Tree Traversal (Preorder, Inorder & Postorder)149
867Matrix Chain Multiplication149
868Design a Stack With Increment Operation Leetcode Solution149
869Clone Graph LeetCode Solution149
870Find the Only Repetitive Element Between 1 to N-1148
871Range LCM Queries148
872Find Maximum Sum Possible Equal Sum of Three Stacks148
873An Interesting Method to generate Binary Numbers from 1 to n148
874LCS (Longest Common Subsequence) of three strings148
875Missing Element in Sorted Array LeetCode Solution148
876Diagonal Traverse LeetCode Solution148
877Sorted Array to Balanced BST148
878Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution148
879Check if stack elements are pairwise consecutive148
880Sequences of given length where every element is more than or equal to twice of previous148
881Identify and Mark Unmatched Parenthesis in an Expression147
882Convert Sorted List to Binary Search Tree147
883Repeated Substring Pattern LeetCode Solution147
884Three way partitioning of an array around a given range147
885Diagonal Traversal LeetCode Solution147
886Time Based Key-Value Store LeetCode Solution147
887Union and Intersection of two Linked Lists147
888Distinct adjacent elements in an array147
889Insert Delete GetRandom147
890Design Browser History LeetCode Solution147
891Water Bottles Leetcode Solution147
892Number of Days Between Two Dates LeetCode Solution147
893K’th Largest Element in BST when modification to BST is not allowed147
894Rearrange an Array Such that arr[i] is equal to i146
895Special Positions in a Binary Matrix Leetcode Solution146
896Delete And Earn146
897Destination City Leetcode Solution146
898Check if an Array is Stack Sortable146
899Minimum Swaps to Make Strings Equal Leetcode Solution146
900Maximum Score After Splitting a String Leetcode Solution146
901Guess Number Higher or Lower II146
902Robot Bounded In Circle LeetCode Solution146
903Spiral Matrix III LeetCode Solution146
904GCDs of given index ranges in an array146
905BFS for Disconnected Graph146
906Daily Temperatures Leetcode Solution146
907Minimum sum of multiplications of n numbers146
908Shortest Word Distance Leetcode Solution146
909Find distance between two nodes of a Binary Tree145
910Count ways to reach the nth stair using step 1, 2 or 3145
911Construct Complete Binary Tree from its Linked List Representation145
912Find Common Characters Leetcode Solution145
913Check if the given array can represent Level Order Traversal of Binary Search Tree145
914Lemonade Change Leetcode Solution145
915Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i145
916Least Number of Unique Integers after K Removals Leetcode Solution145
917Queue using Stacks145
918Range sum queries without updates145
919Number of Distinct Islands Leetcode Solution145
920Rearrange Spaces Between Words Leetcode Solution144
921Print Fibonacci sequence using 2 variables144
922Vertical sum in a given binary tree144
923Set Matrix Zeroes Leetcode Solution144
9244Sum144
925Alien Dictionary144
926Palindrome Partitioning Leetcode Solution144
927Merge Two Sorted Lists Leetcode144
928Construct BST from its given Level Order Traversal144
929Construct the Rectangle Leetcode Solution143
930Difference Array | Range update query in O(1)143
931Queries for GCD of all numbers of an array except elements in a given range143
932Maximum Frequency Stack Leetcode Solution143
933Maximum Subarray Sum Excluding Certain Elements143
934Check if any two intervals overlap among a given set of intervals143
935Averages of Levels in Binary Tree143
9363 Sum143
937Iterative Postorder Traversal Using Two Stacks143
938Stone Game II Leetcode143
939Split Array Into Consecutive Subsequences143
940Lexicographical Numbers Leetcode Solution143
941Create Maximum Number143
942Minimum Height Trees LeetCode Solution143
943A program to check if a binary tree is BST or not143
944Trim a Binary Search Tree142
945Infix to Postfix142
946Number of Equivalent Domino Pairs Leetcode Solution142
947Count Subarrays with Same Even and Odd Elements142
948Strongly Connected Component142
949Longest Palindromic Subsequence142
950Largest area rectangular sub-matrix with equal number of 1’s and 0’s142
951Binary Tree Longest Consecutive Sequence LeetCode Solution142
952Analyze User Website Visit Pattern LeetCode Solution142
953Remove Duplicates from Sorted List II LeetCode Solution142
954Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space141
955Find postorder traversal of BST from preorder traversal141
956Median of Two Sorted Arrays141
957Find all permuted rows of a given row in a matrix141
958Collect maximum points in a grid using two traversals141
959My Calendar I LeetCode Solution141
960Count Submatrices With All Ones LeetCode Solution141
961All Unique Triplets that Sum up to a Given Value141
962Sliding Window Maximum141
963Unique Paths II141
964Dividing Array into Pairs With Sum Divisible by K141
965Binary array after M range toggle operations141
966Merging Intervals140
967Pattern Occurrences using Stack140
968Minesweeper LeetCode Solution140
969Three Consecutive Odds Leetcode Solution140
970Sign of the Product of an Array LeetCode Solution140
971Maximum Product Subarray140
972Can Make Arithmetic Progression From Sequence Leetcode Solution140
973Word Break140
974Reverse Nodes in K-Group140
975Count subarrays where second highest lie before highest140
976Count pair with Given Sum140
977Kth Smallest Element in a BST Leetcode Solution140
978Intersection of Two Linked Lists LeetCode Solution140
979Height of a generic tree from parent array140
980The Painter’s Partition Problem140
981K Closest Points to Origin Leetcode Solution140
982Maximize Sum of Array after K Negations Leetcode Solution140
983Count Primes in Ranges140
984Length of Longest Fibonacci Subsequence139
985Longest Nice Substring LeetCode Solution139
986Friends Of Appropriate Ages LeetCode Solution139
987Symmetric Tree139
988Palindrome Partitioning139
989Binary Search Tree Delete Operation139
990Level Order Traversal of Binary Tree139
991Find Maximum of Minimum for Every Window Size in a Given Array139
992Product of Array Except Self LeetCode Solution139
993Newman-Conway Sequence139
994Find the Difference Leetcode Solution139
995Valid Boomerang Leetcode Solution138
996Largest divisible pairs subset138
997Segment Tree138
998Minimum Index Sum of Two Lists138
999Asteroid Collision LeetCode Solution138
1000Find number of pairs in an array such that their XOR is 0138
1001Largest Number Leetcode Solution138
1002Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution138
1003Climbing stairs138
1004Number Of Longest Increasing Subsequence138
1005Number of palindromic paths in a matrix137
1006Maximum subsequence sum such that no three are consecutive137
1007Find Duplicate Subtrees137
1008Shortest Completing Word Leetcode Solution137
1009Maximum Length of Repeated Subarray137
1010Merge Sort137
1011Maximum Product of Indexes of Next Greater on Left and Right137
1012String Matching in an Array Leetcode Solution137
1013Largest Substring Between Two Equal Characters Leetcode Solution137
1014Breadth First Search (BFS) for a Graph137
1015Depth First Search (DFS) for a Graph137
1016Insertion in a Binary Tree137
1017Find the First Circular Tour that visits all the Petrol Pumps137
1018Construction of Longest Increasing Subsequence (N log N)137
1019Boundary Traversal of binary tree137
1020Graph Valid Tree LeetCode Solution137
1021Compute nCr % p137
1022Construct Binary Tree from given Parent Array representation137
1023The Maze III LeetCode Solution137
1024Double the first element and move zero to end137
1025Maximum Number of Ways to Partition an Array LeetCode Solution136
1026Next Greater Element III LeetCode Solution136
1027Partition Equal Subset Sum136
1028Kill Process LeetCode Solution136
1029Morris Inorder Traversal136
1030Decrypt String from Alphabet to Integer Mapping Leetcode Solution136
1031Serialize and Deserialize Binary Tree136
1032Scramble String LeetCode Solution136
1033Make The String Great Leetcode Solution136
1034Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’136
1035Boolean Parenthesization Problem136
1036Maximum weight transformation of a given string136
1037Count minimum steps to get the given desired array136
1038First missing positive136
1039Level order traversal using two Queues136
1040Binary Search Tree136
1041Maximum Sum of 3 Non-Overlapping Subarrays135
1042K maximum sums of overlapping contiguous sub-arrays135
1043Build an Array With Stack Operations Leetcode Solution135
1044Advantages of BST over Hash Table135
1045Longest subsequence such that difference between adjacents is one135
1046Invalid Transactions LeetCode Solution135
1047Design Hit Counter LeetCode Solution135
1048Iterative Depth First Traversal of Graph135
1049Validate Binary Search Tree134
1050Rearrange array such that even positioned are greater than odd134
1051Add two numbers134
1052Maximum difference between frequency of two elements such that element having greater frequency is also greater134
1053Ugly Numbers134
1054Employee Importance LeetCode Solution134
1055Available Captures for Rook Leetcode Solution134
1056Balanced Binary Tree134
1057Custom Sort String Leetcode Solution134
1058Path Sum II LeetCode Solution134
1059Implement Trie (Prefix Tree) Leetcode Solution133
1060Kth Smallest Element in a Sorted Matrix LeetCode Solution133
1061Super Ugly Number133
1062Bitwise AND of Numbers Range LeetCode Solution133
1063Ugly Number II LeetCode Solution133
1064Recover Binary Search Tree Leetcode Solution133
1065Count pairs from two sorted arrays whose sum is equal to a given value x133
1066Maximum length subsequence with difference between adjacent elements as either 0 or 1133
1067Defanging an IP Address LeetCode Solution133
1068Generate Parentheses Leetcode Solution133
1069Remove Duplicates from Sorted Array II Leetcode Solution132
1070Find Peak Element132
1071Regular Expression Matching Regular Expression Matching LeetCode Solution132
1072Lowest Common Ancestor132
1073Root to Leaf path with target sum Leetcode Solutions132
1074Search in Sorted Rotated Array132
1075Move all negative elements to end in order with extra space allowed132
1076Populating Next Right Pointers in Each Node Leetcode Solution132
1077Number of Closed Islands Leetcode Solution131
1078Find a Peak Element II LeetCode Solution131
1079Minimum Size Subarray Sum131
1080Rearrange array such that even index elements are smaller and odd index elements are greater131
1081Number of Students Doing Homework at a Given Time Leetcode Solution131
1082Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution131
1083Largest BST Subtree LeetCode Solution131
1084Subarrays with K Different Integers Leetcode Solution131
1085Longest Bitonic Subsequence131
1086Binary Tree Right Side View LeetCode Solution131
1087Maximize Distance to Closest Person LeetCode Solution130
1088Minimum Absolute Difference in BST Leetcode Solution130
1089Types of Binary Tree130
1090Find whether a subarray is in form of a mountain or not130
1091Smallest Common Region Leetcode Solution130
1092Day of the Year Leetcode Solution130
1093Remove Palindromic Subsequences Leetcode Solution130
1094Combination Sum IV LeetCode Solution130
1095Number of siblings of a given Node in n-ary Tree130
1096Kth Smallest Product of Two Sorted Arrays LeetCode Solution130
1097Clone a Binary Tree with Random Pointers130
1098Find the minimum distance between two numbers129
1099Find maximum difference between nearest left and right smaller elements129
1100Count Largest Group Leetcode Solution129
1101Level of Each node in a Tree from source node129
1102Convert BST into a Min-Heap without using array129
1103Distinct Subsequences129
1104Binary Tree Data Structure129
1105Find Smallest Range Containing Elements from k Lists129
1106Consecutive Characters LeetCode Solution129
1107Increasing Triplet Subsequence LeetCode Solution129
1108Next Permutation Leetcode Solution129
1109Palindrome Permutation LeetCode Solution129
1110Serialize and Deserialize Binary Tree LeetCode Solution129
1111Find Three Element From Different Three Arrays Such That a + b + c = sum128
1112Construct K Palindrome Strings LeetCode Solution128
1113Valid Tic-Tac-Toe State LeetCode Solution128
1114Remove duplicates from sorted array128
1115Maximum Product Subarray128
1116Iterative method to find ancestors of a given binary tree128
1117Constant time range add operation on an array128
1118Path Sum128
1119Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution128
1120Cutting a Rod128
1121Print all triplets in sorted array that form AP128
1122Third Maximum Number Leetcode Solution128
1123Divisible Pairs Counting128
1124Delete Nodes and Return Forest Leetcode Solution127
1125Sum of Even Numbers After Queries127
1126Reformat The String Leetcode Solution127
1127Mean of Array After Removing Some Elements Leetcode Solution127
1128Longest Subarray of 1’s After Deleting One Element LeetCode Solution127
1129Bottom View of a Binary Tree127
1130Products of ranges in an array127
1131Prime Palindrome LeetCode Solution127
1132Print Next Greater Number of Q queries127
1133Cells with Odd Values in a Matrix LeetCode Solution126
1134Minimum sum of squares of character counts in a given string after removing k characters126
1135Search Insert Position126
1136Write Code to Determine if Two Trees are Identical126
1137Thousand Separator Leetcode Solution126
1138Print Right View of a Binary Tree126
1139Minimum Score Triangulation of Polygon Leetcode Solution126
1140Moser-de Bruijn Sequence126
1141Longest Increasing Consecutive Subsequence126
1142Find maximum length Snake sequence126
1143Maximum Product of Splitted Binary Tree LeetCode Solution125
1144Palindromic Substrings Leetcode Solution125
1145Topological Sorting125
1146Merge two BSTs with limited extra space125
1147Swap Nodes In Pairs125
1148Search an Element in Sorted Rotated Array125
1149Check Array Formation Through Concatenation Leetcode Solution124
1150Subset Sum Problem in O(sum) space124
1151Closest Binary Search Tree Value Leetcode Solution124
1152Diameter of N-Ary Tree LeetCode Solution124
1153Priority Queue124
1154Maximum Binary Tree124
1155Red-Black Tree Introduction124
1156Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution124
1157Print modified array after executing the commands of addition and subtraction123
1158Possible Bipartition LeetCode Solution123
1159Queries for Number of Distinct Elements in a Subarray123
1160Find Largest Value in Each Tree Row LeetCode Solution123
1161Golomb sequence123
1162Minimum Sideway Jumps LeetCode Solution123
1163Bus Routes Leetcode Solution123
1164Find a sorted subsequence of size 3 in linear time122
1165Kth Smallest Number in Multiplication Table Leetcode Solution122
1166Minimum Cost to Move Chips to The Same Position LeetCode Solution122
1167Longest Repeated Subsequence122
1168Search Suggestions System LeetCode Solution122
1169Count even length binary sequences with same sum of first and second half bits122
1170Rotate Array122
1171Transform a BST to Greater sum Tree122
1172Web Crawler LeetCode Solution122
1173Maximize sum of consecutive differences in a circular array122
1174Binary Tree to Binary Search Tree Conversion122
1175Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution122
1176Matchsticks to Square Leetcode Solution121
1177Swapping Nodes in a Linked List Leetcode Solution121
1178Decision Tree121
1179Graph and its representation121
1180Compare Strings by Frequency of the Smallest Character Leetcode Solution121
1181Find the smallest binary digit multiple of given number121
1182K’th Largest element in BST using constant extra space120
1183Number of Orders in the Backlog Leetcode Solution120
1184Factorial Trailing Zeroes LeetCode Solution120
1185Convert Sorted Array to Binary Search Tree LeetCode Solutions120
1186First Bad Version120
1187Decrease Elements To Make Array Zigzag LeetCode Solution120
1188Lowest Common Ancestor in Binary Search Tree120
1189Minimum Moves to Equal Array Elements LeetCode Solution120
1190Contiguous Array LeetCode Solution120
1191Reformat Date LeetCode Solution120
1192Valid Triangle Number119
1193Count Pairs Whose Products Exist in Array119
1194Sum of Left Leaves LeetCode Solution119
1195Reverse a Path in BST using Queue119
1196Given a binary tree, how do you remove all the half nodes?119
1197How to print maximum number of A’s using given four keys119
1198Queue Reconstruction by Height119
1199Maximum sum bitonic subarray119
1200Moving Stones Until Consecutive Leetcode Solution118
1201Maximum number of segments of lengths a, b and c118
1202Range Queries for Longest Correct Bracket Subsequence118
1203Closest Leaf in a Binary Tree LeetCode Solution118
1204Lowest Common Ancestor of a Binary Tree Leetcode Solution118
1205Maximum sum of pairs with specific difference118
1206Champagne Tower LeetCode Solution118
1207Path Crossing Leetcode Solution117
1208Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution117
1209Guess The Word117
1210Array Queries for multiply replacements and product117
1211Minimum Swaps To Make Sequences Increasing LeetCode Solution117
1212Kth Smallest Element in a BST117
1213BST to a Tree with Sum of all Smaller Keys117
1214Maximum Depth Of Binary Tree117
1215Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution116
1216Write a function to get the intersection point of two Linked Lists116
1217Concatenation of Array LeetCode Solution116
1218LRU Cache Leetcode Solution116
1219Integer Break LeetCode Solution116
1220Replace two consecutive equal values with one greater116
1221Arithmetic Slices II – Subsequence LeetCode Solution115
1222Flatten 2D Vector LeetCode Solution115
1223Queries on Probability of Even or Odd Number in given Ranges115
1224Range Sum Query using Sparse Table115
1225Maximum Array from Two given Arrays Keeping Order Same115
1226Maximum sum of a path in a Right Number Triangle115
1227New 21 Game115
1228Valid Perfect Square LeetCode Solution115
1229Perfect Squares LeetCode Solution115
1230Power of Two115
1231Maximum Value at a Given Index in a Bounded Array LeetCode Solution115
1232Check if each internal node of a BST has exactly one child114
1233The kth Factor of n Leetcode Solution114
1234Maximize Elements Using Another Array114
1235Design Skiplist LeetCode Solution114
1236Check Completeness of a Binary Tree LeetCode Solution114
1237Divide Two Integers Leetcode Solution114
1238Mean of range in array114
1239Sliding Window Median Leetcode Solution114
1240Print modified array after multiple array range increment operations113
1241Longest Common Prefix Using Word by Word Matching113
1242Check if all levels of two Binary Tree are anagrams or not113
1243Bold Words in String LeetCode Solution113
1244Largest Plus Sign Leetcode Solution113
1245Check for Identical BSTs without building the trees113
1246Contiguous Array113
1247Find Minimum in Rotated Sorted Array II LeetCode Solution113
1248Find k-th smallest element in BST (Order Statistics in BST)112
1249Graph Cloning112
1250Parallel Courses II LeetCode Solution112
1251Print n terms of Newman-Conway Sequence112
1252Print Ancestors of a Given Binary Tree Node Without Recursion112
1253Count Subsets Having Distinct Even Numbers112
1254Find minimum number of merge operations to make an array palindrome112
1255Merge k Sorted Lists Leetcode Solution111
1256Symmetric Tree LeetCode Solution Leetcode Solution111
1257Maximum Product Subarray111
1258Missing Number111
1259Verify Preorder Serialization of a Binary Tree110
1260Image Overlap LeetCode Solution110
1261Smallest Range II Leetcode Solution110
1262Check if two nodes are on the same path in a Tree110
1263Minimum Remove to Make Valid Parentheses LeetCode Solution110
1264Excel Sheet Column Title LeetCode Solution110
1265Count and Toggle Queries on a Binary Array110
1266Next greater element109
1267Number of elements less than or equal to a given number in a given subarray109
1268Check If a String Can Break Another String Leetcode Solution108
1269Minimum Time to Collect All Apples in a Tree LeetCode Solution108
1270Orderly Queue LeetCode Solution107
1271Koko Eating Bananas LeetCode Solution107
1272Different Ways to Add Parentheses Leetcode Solution107
1273Palindrome Partitioning107
1274Min Cost Climbing Stairs LeetCode Solution107
1275Newman–Shanks–Williams prime105
1276Largest Submatrix With Rearrangements LeetCode Solution105
1277Check if X can give change to every person in the Queue105
1278Longest Substring Without Repeating Characters Leetcode Solution105
1279Peeking Iterator LeetCode Solution105
1280Check in binary array the number represented by a subarray is odd or even104
1281Merge Sorted Array103
1282Range Minimum Query (Square Root Decomposition and Sparse Table)103
1283Queries for Decimal Values of Subarrays of a Binary Array102
1284Array Nesting Leetcode Solution102
1285Maximum Sum Increasing Subsequence101
1286Arranging Coins Leetcode Solution101
1287Find maximum average subarray of k length100
1288Maximum product of an increasing subsequence100
1289Encoded String With Shortest Length LeetCode Solution100
1290Number of indexes with equal elements in given range99
1291Minimum Total Space Wasted With K Resizing Operations LeetCode Solution99
1292Convert to Base -2 LeetCode Solution98
1293Minimum Number of People to Teach LeetCode Solution98
1294Continuous Subarray Sum LeetCode Solution97
1295Add Two Numbers II Leetcode Solution97
1296Random Pick Index LeetCode Solution97
1297Reach a Number LeetCode Solution97
1298Convert a BST to a Binary Tree such that sum of all greater keys is added to every key97
1299Binary Tree to Binary Search Tree Conversion using STL set96
1300Check given array of size n can represent BST of n levels or not96
1301Find the Winner of the Circular Game LeetCode Solution96
1302Vertical Order Traversal of Binary Tree LeetCode Solution96
1303Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution95
1304Queries on XOR of greatest odd divisor of the range95
1305Jump Game IV LeetCode Solution95
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
1310Print Maximum Length Chain of Pairs89
1311Detect Capital Leetcode Solution87
1312Design A Leaderboard Leetcode Solution87
1313Substring with Concatenation of All Words Leetcode Solution83
1314Top K Frequent Elements LeetCode Solution83
1315Minimum Swaps to Group All 1’s Together Leetcode Solution83
1316Binary Tree Inorder Traversal LeetCode Solution81
1317Count Sub Islands LeetCode Solution81
1318Minimum Path Sum Leetcode Solution80
1319Shifting Letters LeetCode Solution79
1320Odd Even Linked List Leetcode Solution77
1321Longest Common Subsequence LeetCode Solution77
1322Find the Town Judge LeetCode Solution76
1323Best Meeting Point LeetCode Solution76
1324Decode String Leetcode Solution76
1325Find the Town Judge LeetCode Solution75
1326Maximum Population Year LeetCode Solution75
1327Sum Root to Leaf Numbers LeetCode Solution74
1328Shortest Unsorted Continuous Subarray LeetCode Solution73
1329Maximum Population Year LeetCode Solution71
1330Rectangle Overlap LeetCode Solution71
1331Design Add and Search Words Data Structure LeetCode Solution70
1332Flatten Binary Tree to Linked List LeetCode Solution68
1333Score of Parenthesis LeetCode Solution67
1334Stone Game IV LeetCode Solution67
1335Insert into a Sorted Circular Linked List LeetCode Solution67
1336Range Sum Query 2D – Immutable LeetCode Solution66
1337Reveal Cards In Increasing Order Leetcode Solution63
1338Valid Triangle Number LeetCode Solution63
1339Is Graph Bipartite? LeetCode Solution62
1340Divide Chocolate LeetCode Solution56
1341Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution48
1342Reverse Integer Leetcode Solution46
1343Range Sum of BST LeetCode Solution45
1344Sort Colors LeetCode Solution42
1345Find K Closest Elements LeetCode Solution40
1346Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution38
1347Rotate String LeetCode Solution38
1348Excel Sheet Column Number LeetCode Solution37
1349Maximum Size Subarray Sum Equals k Leetcode Solution20
1350H-Index Leetcode Solution20
1351High Five LeetCode Solution19
1352Monotonic Array Leetcode Solution14
1353Camelcase Matching Leetcode Solution12
1354Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution11
1355Unique Binary Search Trees LeetCode Solution11
1356Peak Index in a Mountain Array LeetCode Solution11
1357Valid Triangle Number LeetCode Solution9
1358Swim in Rising Water LeetCode Solution7
1359Isomorphic Strings LeetCode Solution7
1360Group Shifted Strings Leetcode Solution7
Translate »