Shifting Letters LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Facebook Microsoft Oracle
Array StringViews 82

Problem Statement

Shifting Letters says that we have given a string s and an array shifts.

Now for each shifts[i] = x, we want to shift the first i + 1 letters of sx times. We have to return the final string after all shifts are applied.

Example 1:

Input:

 s = "abc", shifts = [3,5,9]

Output:

 "rpl"

Explanation:

  • We start with “abc”.
  • After Shifting the first 1 letter of s by 3, we have “dbc”.
  • After shifting the first 2 letters of s by 5, we have “igc”.
  • After shifting the first 3 letters of s by 9, we have “rpl”.
  • Hence “rpl” is our final answer.

Example 2:

Input:

 s = "aaa", shifts = [1,2,3]

Output:

 "gfd"

Constraints:

  • 1 <= s.length <= 105
  • s consists of lowercase English letters.
  • shifts.length == s.length
  • 0 <= shifts[i] <= 109

Approach

Idea

  1. We have to calculate how many times i-th character is shifted.
  2. So just calculate the number of shifts on each position, by shifts[i] += shift[i+1].
  3. We will do the task in reverse order.
  4. We have to maintain a  reverse prefix sum of the shift array and this will be equal to the number of shifts for each character.
  5. One thing we should focus if we found that our character ASCII score exceeds the value of the ASCII score of ‘z’ we should start counting from ‘a.

Code

Shifting Letters LeetCode C++ Solution

class Solution {
public:
    #define ll int
    string shiftingLetters(string s, vector<int>& shifts) {
        ll i,n=s.size();   
        for(i=n-1;i>=0;i--)
        {   if(i+1<n)
            shifts[i]+=shifts[i+1];
            shifts[i]=shifts[i]%26;
            ll ind=s[i]-'a';
            ind=ind+shifts[i];
            if(ind>25)
            { 
                ind=ind-26;
            }
              
            s[i]=char('a'+ind);
        }
       
        return s;
    }
};

Shifting Letters LeetCode Java Solution

class Solution {
    public String shiftingLetters(String s, int[] shifts) {
        int i,n=shifts.length;
        
        char[] str = s.toCharArray();

        for(i=n-1;i>=0;i--)
        {  if(i+1<n)
            shifts[i]+=shifts[i+1];
            shifts[i]=shifts[i]%26;
            int ind=s.charAt(i)-'a';
            ind=ind+shifts[i];
            if(ind>25)
            {
                ind=ind-26;
            }               
            str[i] = (char)('a'+ind);
        }

        
         return new String(str);
    }
}

Complexity Analysis of Shifting Letters LeetCode Solution:

Time Complexity

Time complexity is O(N). N is the length of the array. We are traversing the array only once.

Space Complexity

For C++ code space complexity is O(1) as we are not taking any extra space. For Java code, it is O(N) as we are making a new string.

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