Break a Palindrome LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Expedia Facebook GoDaddy Goldman Sachs JPMorgan LinkedIn Visa VMware ZillowViews 25

Problem Statement:

Break a Palindrome LeetCode Solution: Given a palindromic string of lowercase English letters palindrome, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.

Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.

A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, a has a character strictly smaller than the corresponding character in b. For example, "abcc" is lexicographically smaller than "abcd" because the first position they differ is at the fourth character, and 'c' is smaller than 'd'.


Example 1:


 palindrome = "abccba"




 There are many ways to make "abccba" not a palindrome, such as "zbccba", "aaccba", and "abacba".
Of all the ways, "aaccba" is the lexicographically smallest.

Example 2:


 palindrome = "a"




 There is no way to replace a single character to make "a" not a palindrome, so return an empty string.



The idea is to first traverse the first half of the string and check if we can replace any character of the string with the character ‘a’. If we can, then the resulting string will be our answer. If not, then we will iterate over the later half of the string and will check if we can replace any character with the smallest ASCII character starting from ‘a’ to ‘z’. We are doing this to get the lexicographically smallest string.

This problem may sound difficult but breaking it into several test cases will lead to an easy/intuitive one.

  1. The base case is if the input of 1 length, we can’t break that palindrome then return “”.
  2. Now think how we can break a palindrome and a new string is lexicographically smallest.
    -> If we just find the first non ‘a’ character and replace it with ‘a’
    e.g. abccba
    first non- ‘a’ character is ‘b’ at position 1 (0-indexing)
    Replacing it with ‘a’ will suffice for this scenario — aaccba
  3.  Logic is not over yet, what if the input String contains only ‘a’s?
    ->Does replacing the last character with ‘b’ helps? Bingo!!!
    e.g. aaaa
    Replace the last character with ‘b’ — aaab


Break a Palindrome C++ Solution:

class Solution {
    string breakPalindrome(string pd) {
        int n=pd.length();
            return "";
            for(int i=0;i<n/2;i++){
                    return pd;
            for(int j=0;j<26;j++){
                for(int i=n-1;i>=n/2;i--){
                        return pd;
            for(int i=0;i<n/2;i++){
                    return pd;
            for(int j=0;j<26;j++){
                for(int i=n-1;i>n/2;i--){
                        return pd;
        return "";

Complexity Analysis of Break a Palindrome LeetCode Solution:

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2887
2Palindrome using Recursion2619
3Java program to find the number of Nodes in a Binary Tree2543
4Reverse a string without affecting special characters2526
5Delete a node of a linked list at given position2022
6Quick Sort1769
7Insert nodes in a linked list in a sorted way (Ascending Order)1711
8Find elements pair from array whose sum equal to number1690
9Sort Elements by Frequency of Occurrences1672
10Write a program to print all permutations of a given string1656
11Find Minimum Distance Between Two Numbers in an Array1518
12Create a Doubly Linked List1484
13Reverse an Array1466
14Smallest window in a string containing all characters of another string1440
15Recursively remove all adjacent duplicates1410
16Find a Triplet That Sum to a Given Value1392
17First Repeating Element1387
18Sum of numbers in String1364
19Arrange Even and Odd number such that Odd comes after Even1357
20Smallest Positive Number Missing in an Unsorted Array1326
21Check if the Elements of an Array are Consecutive1294
22Detect a loop in the Linked List1273
23Largest Sum Contiguous Subarray1263
24Quick Sort on SIngly Linked List1259
25Recursive function to do substring search1250
26Print all Possible Combinations of R Elements in a given Array of size N1249
27Subarray with Given Sum1248
28Find the Maximum Repeating Number in Array1206
29Find the First and Second Smallest Elements1155
30Binary Tree Level order traversal in Java1155
31Check if two linked lists are identical1143
32Maximum Subarray Sum using Divide and Conquer1141
33Remove characters from first string which are in second1115
34Find Leaders in an Array1094
35Swap nodes in the linked list1086
36Find the second most frequent character1036
37Find the Number Occurring Odd Number of Times in an Array1036
38Arrange given Numbers to Form the Biggest Number II1027
39Given a string find its first non-repeating character1016
40Find Triplet in Array With a Given Sum1002
41Given a sorted array and a number x, find the pair in array whose sum is closest to x995
42A Program to check if strings are rotations of each other or not992
43Total number of occurrences of a given item in the linked list991
44Print all possible words from phone digits974
45Find the Missing Number966
46Rearrange Positive and Negative Numbers Alternatively in Array953
47Longest Palindromic Substring946
48Segregate even and odd nodes in a linked list937
49Print Longest common subsequence926
50Transform one string to another using minimum number of given operations915
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome899
53Rearrange given Array in Maximum Minimum Form879
54Iterative Implementation of Quick Sort869
55Insertion Sort858
56Count Possible Triangles856
57Multiplication of Two Matrices843
58Count of Triplets With Sum Less than Given Value830
59Rotate a Linked List828
60Check if the linked list is palindrome827
61Stock Buy Sell to Maximize Profit827
62Concatenation of two strings807
63Tug of War799
64Print all duplicates in the input string798
65Count Number of Substrings with K Distinct Character’s796
66Find Nearest Greater and Smaller Element784
67Reverse String Without Temporary Variable778
68Remove ‘b’ and ‘ac’ from a given string771
69The Celebrity Problem771
70Find Pythagorean Triplets from Array770
71Find all Common Elements in Given Three Sorted Arrays763
72Remove all duplicates in an unsorted linked list741
73Find the Row with Maximum Number of 1’s739
74Find the subarray whose sum is equal to a given number X738
75Remove Minimum Characters so that Two Strings Become Anagrams738
76Find the Peak Element from an Array735
77Addition of Two Matrices730
78Generate all Binary Strings Without Consecutive 1’s727
79Find Smallest Missing Number in a Sorted Array726
80A Product Array Puzzle724
81Maximum Sum of Non Consecutive Elements710
82Implement Two Stacks in an Array707
83Lexicographic rank of string701
84Check if Two given Matrices are Identical692
85Maximum Product Subarray II687
86Multiplication of Previous and Next682
87Subtraction of Two Matrices674
88Merge K Sorted Arrays and Print Sorted Output668
89Divide a string in N equal parts667
90Move All the Zeros to the End of the Given Array667
91Form Minimum Number from Given Sequence of D’s and I’s665
92Online Algorithm for Checking Palindrome in a Stream665
93Check whether two strings are anagram of each other659
94Remove recurring digits in a given number657
95Sort a stack using a temporary stack652
96Maximum Circular Subarray Sum651
97Sort a linked list that is sorted alternating ascending and descending645
98Subarray and Subsequence640
99Find the Minimum Element in a Sorted and Rotated Array637
100Move last element of the Linked List at first place635
101First Circular Tour to Visit all the Petrol Bunks633
102Compare two strings(linked lists)629
1033Sum Leetcode Solution629
104Maximum Element in an Array which is Increasing and then Decreasing628
105Largest Subarray with Equal Number of 0’s and 1’s627
106Palindrome Permutations of a String627
107Palindromes in a given range623
108Flattening a linked list623
109Pangram Checking619
110Minimum insertions to form a shortest palindrome619
111Majority Element618
112Print all permutations with repetition616
113Run length encoding616
114Elements Appear more than N/K times in Array611
115Minimum Characters to be Added at Front to Make String Palindrome609
116Most repeating character in a string606
117Two Sum Leetcode Solution605
118Repeated Subsequence of Length Two or More603
119Rotate string to get lexicographically minimum string603
120Merge a linked list into another at alternate positions596
121Remove all duplicates in a sorted linked list595
122Rearrange a given linked list in-place594
123Minimum number of Merge Operations to make an Array Palindrome593
124Print all anagrams together in a sequence of words592
125Pancake Sorting Problem582
126Reorder an Array According to the Given Indexes582
127Remove duplicates from a string568
128Transpose of a Matrix568
129Merge Overlapping Intervals II568
130Longest Palindrome can be Formed by Removing or Rearranging Characters568
131Smallest Palindrome after Replacement568
132Clone a Linked List with next and random pointer566
133Remove Extra Spaces from a String565
134Removing Spaces from a String using stringstream561
135Maximum Sum Increasing Subsequence560
136Check if a given string is a rotation of a palindrome560
137Size of The Subarray With Maximum Sum558
138Partition Problem552
139Check whether Strings are K Distance Apart or Not549
140Generate all Binary Strings from Given Pattern547
141Length of Longest valid Substring542
142Delete Last Occurrence541
143Check if Two given Strings are Isomorphic to each other539
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized535
145Insert Node in the Sorted Linked List533
146Program to Toggle all Characters in a String531
147Given string is interleaving of two other strings or not526
148Maximum difference between two elements such as larger element comes after smaller525
149Check length of a String is Equal to the Number Appended at its Last517
150Count Minimum Steps to Get the given Array515
151Number of Smaller Elements on Right Side512
152Check if all Rows of a Matrix are Circular Rotations of Each Other509
153Longest Common Prefix using Divide and Conquer508
154Find Pair with Given Difference507
155Merge sort better than quick sort for linked lists505
156Compare Two Version Numbers503
157Print all interleavings of given two strings499
158Find nth node of the Linked list from the end499
159Find a Fixed Point in a Given Array496
160Median of Two Sorted Arrays LeetCode Solution496
161Print Reverse of a string (Recursion)496
162Sort 0s 1s and 2s in an Array496
163Reverse words in a given string494
164Reorder Array Using Given Indexes493
165Merge two sorted linked lists such that merged list is in reverse order486
166Find the Subarray of given length with Least Average486
167Split linked list using alternate nodes484
168Print all Palindromic Partitions of a String477
169Print string of odd length in ‘X’ format475
170Find Element Using Binary Search in Sorted Array469
171Find K Length Subarray of Maximum Average467
172Swap Kth Node from beginning with Kth Node from End465
173Find Duplicates in an Array in Most Efficient Way460
174Shortest Superstring Problem458
175print all palindromic partitions455
176Check if String Follows Order of Characters by a Pattern or not452
177Maximum Length of Chain Pairs449
178Sort a String According to Another String448
179Flatten a multilevel linked list445
180Sorting a K Sorted Array440
181Program to add two binary digits435
182Recursively print all the sentences that can be formed from list of word lists431
183Caesar Cipher430
184Find a Sorted Subsequence of size 3429
185Longest Common Prefix Using Binary Search II427
186Longest Span with same Sum in two Binary Arrays II427
187Reverse a Linked List in groups426
188Find the two Numbers with Odd Occurrences in an Unsorted Array425
189Kth Non-repeating Character422
190Reverse a Singly Linked List (Iterative/Non-Recursive)421
191Check if String can Become Empty by Recursively Deleting given Substring418
192Longest Common Prefix Word by Word Matching414
193Rearrange a linked list in Zig-Zag412
194Permutations of a Given String Using STL408
195Rotate Image by 90 degrees407
196Perfect Reversible String406
197Pancake Sorting405
198Merging Two Sorted Arrays405
199Find First non-repeating character in a string402
2001`s and 2`s complement of binary number401
201List items containing all characters of a given word396
202Maximum occurring character in a string396
203Increasing Subsequence of Length three with Maximum Product395
204Find the point where a monotonically increasing function becomes positive first time394
205Four Elements that Sum to Given391
206Sort a linked list with 0s, 1s and 2s390
207Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes388
208Longest Common Prefix using Character by Character Matching387
209Count Number of Occurrences in a Sorted Array384
210Palindrome string (number)384
211Valid Parentheses LeetCode Solution382
212Delete N nodes after M382
213Minimum Characters to be Removed to Make a Binary String Alternate381
214Even Substring Count377
215Split a string377
216Recursive Implementation of atoi()374
217Sorting the array of strings373
218Convert a String that is Repetition of a Substring of Length K370
219Print Shortest Path to Print a String on Screen368
220Check if a Linked list of Strings form a Palindrome367
221Nth Character in Concatenated Decimal String364
222Maximum Subarray Leetcode Solution364
223Convert string1 to string2 in one edit363
224Print All Distinct Elements of the Array360
225Count the number of words360
226Reverse a singly linked list recursively360
227Reverse a String using Stack359
228Find the first Repeating Number in a Given Array358
229wildcard character matching358
230Matrix Chain Multiplication using Dynamic Programming358
231Lower Case To Upper Case355
232Can we reverse a linked list in less than O(n) time ?352
233Binary Tree to Doubly linked list350
234Longest Common Subsequence with Permutations347
235Sort Elements by Frequency II346
236Find the Lost Element From a Duplicated Array344
237Split Four Distinct Strings343
238Merge Two Sorted Arrays341
239Find middle of the Linked List338
240Roman to Integer Leetcode Solution338
241Count the Pairs at Same Distance as in English Alphabets336
242Toeplitz Matrix333
243N queen problem329
244Palindrome Permutation328
245Word Search Leetcode Solution326
246Next Greater Element in an Array325
247Move all negative elements to one side of array324
248First non Repeating Element320
249Sudoku Solver319
250Searching a node in a Binary Search Tree318
251Find All Pairs With a Given Difference318
252Count Pairs With Given Sum316
253Reverse Bits316
254Print all Possible Ways to Break a String in Bracket Form316
255String(represents an integer) to value316
256Find Nth Node315
257Number of Islands LeetCode Solution314
258Change Gender of a given String313
259Reverse a String313
260Types of Binary Tree312
261Repeated Substring Pattern312
262Triplet from three linked lists with given sum312
263Delete a Tree311
264Sort an array of strings310
265Fibonacci numbers310
266Number of sub-strings which recursively add up to 9308
267Min Stack308
268Reverse a linked list308
269How to Efficiently Implement k Stacks in a Single Array?308
270Meeting Rooms II LeetCode Solution308
271Most Frequent Element in an Array307
272Delete a node under given conditions307
273Longest Palindromic Substring LeetCode Solution305
274Dijkstra Algorithm304
275Cuckoo sequence program304
276Longest Common Extension302
277Max stack299
278Binary Tree299
279House Robber Leetcode Solution298
280Remove spaces from a string298
281Best Time to Buy and Sell Stock  II Leetcode Solution293
282Subset Leetcode293
283Word Search292
284Shuffle a given Array290
285KMP Algorithm290
286Minimize the maximum difference between the heights289
287Expression Evaluation289
288Find, second, frequent, character288
289Remove middle points in a linked list of line segments288
290Plus One Leetcode Solution287
291Number Of 1 bits286
292Combination Sum Leetcode Solution285
293Search Insert Position Leetcode Solution284
294Reverse words in a string284
295Pair of Positive Negative Values in an Array282
296Evaluation of Postfix Expression282
297Sliding Window Technique282
298Subarray with 0 sum279
299Min Stack Leetcode Solution279
300Set Matrix Zeroes279
301Rabin Karp Algorithm278
302Valid Palindrome Leetcode Solution278
303Backspace String Compare277
304Common elements in all rows of a given matrix274
305Sort linked which is sorted on absolute values273
306Clone a linked list with next and random pointer (Hashing)272
307Merge Sorted Arrays Leetcode Solution272
308Sqrt(x) Leetcode Solution270
309Reversing a Queue269
310Delete middle element of a stack269
311Tower Of Hanoi267
312Contains Duplicate267
313Implementation of Deque using Doubly Linked List266
314String Compression266
315Count subarrays with equal number of 1’s and 0’s265
316Product of array except self265
317Count of index pairs with equal elements in an array265
318Contains Duplicate II Leetcode Solution265
319Intersection of Two Arrays II Leetcode Solution264
320Combination Sum264
321Count Odd Numbers in an Interval Range Leetcode Solution264
322How to Delete a Linked List264
323Find Top K (or Most Frequent) Numbers in a Stream264
324Reverse individual words264
325Page Replacement Algorithms in Operating Systems264
326Pascal Triangle Leetcode263
327Minimum swaps required to bring all elements less than or equal to k together263
328Segregate even and odd numbers261
329Integer to Roman Leetcode Solution261
330Find sum of non-repeating elements (distinct) elements in an array260
331Group Words With Same Set of Characters260
332Single Number Leetcode Solution259
333Smallest Subarray with k Distinct Numbers259
334Postfix to Infix Conversion259
335Minimum Value to Get Positive Step by Step Sum Leetcode Solution258
336Sort elements by frequency258
337Second Most Repeated Word in a Sequence258
338Sum of minimum and maximum elements of all subarrays of size k258
339Bellman Ford Algorithm258
340Sorting array using Stacks258
341Arithmetic Expression Evaluation257
342Next Permutation257
343Count subarrays having total distinct elements same as original array257
344Top K Frequent Words256
345Add Binary Leetcode Solution256
346K-th Smallest Element in a Sorted Matrix255
347Maximum Number of Balloons Leetcode Solution255
348Minimum operation to make all elements equal in array254
349Given two unsorted arrays find all pairs whose sum is x254
350Convex Hull Algorithm253
351Construct Binary Tree from Given Inorder and Preorder Traversals253
352Scramble String252
353Longest Common Prefix Leetcode Solution252
354First element occurring k times in an array252
355Special Number251
356Pow(x, n) Leetcode Solution251
357Palindrome Linked List Leetcode Solution251
358Design a stack that supports getMin() in O(1) time and O(1) extra space250
359Majority Element Leetcode Solution250
360Longest Substring Without Repeating Characters LeetCode Solution250
361Find duplicates in a given array when elements are not limited to a range250
362Find Lucky Integer in an Array Leetcode Solution250
363Evaluate Division249
364Permutations Leetcode Solution248
365Kruskal Algorithm248
366Running Sum of 1d Array Leetcode Solution247
367Third Maximum Number Leetcode Solution246
368Check if two arrays are equal or not244
369Fizz Buzz Leetcode244
370Maximum possible difference of two subsets of an array244
371Reversing the First K elements of a Queue244
372Minimum Path Sum244
373Spiral Matrix LeetCode Solution244
374Maximum Distance Between two Occurrences of Same Element in Array243
375Reverse a Number Using Stack243
376Prefix to Infix Conversion243
377Maximum Subarray243
378Number of Good Pairs Leetcode Solution243
379Range Sum Query 2D – Immutable Leetcode Solution242
380Huffman Coding242
381Smallest Element Repeated Exactly K Times242
382Unique Paths241
383Count Primes Leetcode Solutions241
384Maximal Square241
385Minimum Steps to reach target by a Knight241
386Find Numbers with Even Number of Digits Leetcode Solution241
387Group Anagrams240
388Minimum Absolute Difference Leetcode Solution240
389Find the Closest Palindrome number240
390Single Number240
391Find the Town Judge Leetcode Solution240
392Swap Nodes in Pairs Leetcode Solutions240
393Convert String To Int240
394Palindrome Substring Queries240
395Find All Numbers Disappeared in an Array Leetcode Solution239
396Find the first repeating element in an array of integers239
397Find Number of Employees Under every Employee239
398Sorting using trivial hash function239
399Remove Minimum Number of Elements Such That no Common Element Exist in both Array239
400Find top three repeated in array239
401Zigzag Conversion238
402Sort Array by Increasing Frequency Leetcode Solution238
403Cumulative Frequency of Count of Each Element in an Unsorted Array238
404Leetcode Permutations236
405Implement Stack and Queue using Deque236
406Power of Two Leetcode Solution236
407Print All Distinct Elements of a Given Integer Array236
408Check if Array Contains Contiguous Integers With Duplicates Allowed236
409Pascal’s Triangle II Leetcode Solution236
410How to Implement Stack Using Priority Queue or Heap?235
411Length of the largest subarray with contiguous elements235
412Missing Number Leetcode Solution235
413Expression Contains Redundant Bracket or Not235
414Count Substrings with equal number of 0s, 1s and 2s235
415Print all subarrays with 0 sum235
416Merge Two Sorted Lists Leetcode Solutions235
417Matrix Diagonal Sum Leetcode Solution234
418Sort Integers by The Number of 1 Bit Leetcode Solution234
419House Robber II Leetcode Solution234
420Fizz Buzz234
421Difference between highest and least frequencies in an array234
422Bipartite Graph234
423Letter Case Permutation234
424Decode String234
425Prim’s Algorithm233
426LRU Cache Implementation233
427Sort a stack using recursion233
428Unique Paths Leetcode Solution233
429Subarray Sum Equals k233
430Happy Number Leetcode Solution233
431Top K Frequent Elements232
432Maximum Depth of Binary Tree Leetcode Solution232
433Subset sum problem232
434Subarrays with distinct elements231
435Find all pairs (a, b) in an array such that a % b = k231
436Search in Rotated Sorted Array Leetcode Solution231
437Coin Change 2 Leetcode Solution231
438Count pairs from two linked lists whose sum is equal to a given value231
439Reverse Integer231
440Find Median from data Stream231
441Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution230
442Find Winner on a Tic Tac Toe Game Leetcode Solution230
443Check If N and Its Double Exist Leetcode Solution229
444Pair with given product229
445Capacity To Ship Packages Within D Days Leetcode Solution228
446Find elements which are present in first array and not in second228
447Monotonic Array LeetCode Solution228
448Find the Difference Leetcode Solution228
449Max Consecutive Ones Leetcode Solution228
450Nth Catalan Number228
451Reverse a Stack Using Recursion228
452How Many Numbers Are Smaller Than the Current Number Leetcode Solution228
453Find The Duplicate Number227
454Integer to English words226
455Text Justification LeetCode Solution226
456Edit Distance226
457Find distinct elements common to all rows of a matrix226
458Subarray Sum Equals K LeetCode Solution226
459Fibonacci Number LeetCode Solution226
460Count and Say226
461Reverse a String225
462Valid Parenthesis String225
463Longest subarray not having more than K distinct elements225
464Find Minimum In Rotated Sorted Array225
465Priority Queue Using Singly Linked List225
466Find Index of Closing Bracket for a Given Opening Bracket in an Expression225
467Sum of Subarray Ranges Leetcode Solution225
468Trapping Rain Water Leetcode Solution225
469Longest Common Prefix using Trie224
470Check if a given array contains duplicate elements within k distance from each other224
471Find four elements that sum to a given value (Hashmap)224
472Remove Duplicates from Sorted Array Leetcode Solution224
473Floyd Warshall Algorithm224
474Rearrange a binary string as alternate x and y occurrences224
475Reverse Vowels of a String Leetcode Solution224
476Find any one of the multiple repeating elements in read only array224
477Subtract the Product and Sum of Digits of an Integer Leetcode Solution224
478Best Time to Buy and Sell Stock III Leetcode Solution224
479Kth largest element in an Array Leetcode Solutions223
480Target Sum223
481Design Parking System Leetcode Solution223
482The K Weakest Rows in a Matrix Leetcode Solution222
483Intersection of Two Arrays222
484MiniMax Algorithm222
485Delete a Node from linked list without head pointer221
486Jump Game Leetcode Solution221
487Count number of triplets with product equal to given number221
488Generate a String With Characters That Have Odd Counts Leetcode Solution221
489Find missing elements of a range221
490Prefix to Postfix Conversion221
491Degree of an array220
492Shuffle the Array Leetcode Solution220
493Sorting a Queue without Extra Space220
494Shuffle String Leetcode Solution220
495Find subarray with given sum (Handles Negative Numbers)220
496Word Ladder LeetCode Solution220
497Find Common Characters Leetcode Solution220
498Multiply Strings Leetcode Solution219
499Substring With Concatenation Of All Words219
500Top View of Binary Tree219
501Flood Fill LeetCode219
502The Stock Span Problem219
503Best Time to Buy and Sell Stock LeetCode Solution218
504Slowest Key Leetcode Solution218
506K-th Distinct Element in an Array218
507Shortest Palindrome218
508Iterative Tower of Hanoi218
509Merge Two Sorted Linked Lists218
510Check for Balanced Parentheses in an Expression218
511Excel Sheet Column Number Leetcode Solution218
512Balanced Binary Tree Leetcode Solution218
513Next Greater Element I Leetcode Solution217
514Postfix to Prefix Conversion217
515Iterative Inorder Traversal of a Binary Tree217
516Minimum Delete Operations to make all Elements of Array Same217
517Priority Queue in C++217
518Longest Common Prefix using Sorting217
519Implement Stack using Queues217
520Implement a stack using single queue217
521Number of Steps to Reduce a Number to Zero Leetcode Solution217
522Kids With the Greatest Number of Candies Leetcode Solution217
523Peak Index in a Mountain Array217
524Move Zeroes LeetCode Solution216
525Reverse Words in a String III LeetCode Solution216
526Minimum Knight Moves LeetCode Solution216
527Sum of Left Leaves Leetcode Solutions216
528Concatenation of Array LeetCode Solution216
529Container with Most Water216
530Longest Common Subsequence216
531Count and Say Leetcode Solution216
532Find the Duplicate Element216
533Valid Sudoku216
534Next Greater Frequency Element215
535Arrange given numbers to form the biggest number215
536Convert array into Zig-Zag fashion215
537Max Area of Island215
538Linked List Cycle II LeetCode Solution215
539Minimum Moves to Equal Array Elements Leetcode Solution215
540Find Sum of all unique sub-array sum for a given array215
541Hamming Distance215
542Jewels and Stones Leetcode Solution214
543Find First and Last Position of Element in Sorted Array Leetcode Solution214
544Check if a queue can be sorted into another queue using a stack214
545Largest Sum Contiguous Subarray214
546Change the Array into Permutation of Numbers From 1 to N214
547Group Multiple Occurrence of Array Elements Ordered by first Occurrence213
548Smallest Subarray With all Occurrences of a Most Frequent Element213
549Gold Mine Problem213
550Merge Overlapping Intervals213
551How to check if two given sets are disjoint?213
552Kth Largest Element in a Stream Leetcode Solution213
553Is Subsequence Leetcode Solution212
554Largest Perimeter Triangle Leetcode Solution212
555Find N Unique Integers Sum up to Zero Leetcode Solution212
556Excel Sheet Column Title Leetcode Solution212
557Isomorphic Strings Leetcode Solution212
558Zigzag Conversion LeetCode Solution212
559Count the number of nodes at given level in a tree using BFS212
560Shuffle an Array211
561Last Stone Weight211
562Delete Node in a Linked List Leetcode Solution211
563Minimum number of subsets with distinct elements211
564Contiguous Array Leetcode211
565Maximum sum rectangle in a 2D matrix210
566Summary Ranges Leetcode Solution210
567N-th Tribonacci Number Leetcode Solution210
568Minimum Bracket Reversals210
569Smallest Good Base210
570Convert a normal BST to Balanced BST210
571Valid Anagrams210
572Minimum Cost to Hire K Workers210
573Koko Eating Bananas Leetcode Solution210
574Integer to Roman209
575Maximum path sum in a triangle209
576Find if an Expression has Duplicate Parenthesis or Not209
577Length of Last Word Leetcode Solution208
578Best Time to Buy and Sell Stock208
5793Sum Closest LeetCode Solution208
580Implementation of Deque using circular array208
581Distribute Candies to People Leetcode Solution208
582Shortest Path in a Grid with Obstacles Elimination LeetCode Solution208
583Number of Provinces Leetcode Solution208
584Mobile Numeric Keypad Problem208
585Find Words That Can Be Formed by Characters Leetcode Solution207
586Build Array From Permutation Leetcode Solution207
587Relative Sort Array Leetcode Solution207
588Decode Ways207
589Longest Increasing Subsequence207
590Frog Jump Leetcode Solution207
591Maximum Distance in Array207
592First negative integer in every window of size k206
593Rotate Image LeetCode Solution206
594Island Perimeter Leetcode Solution206
595Iterative Method to find Height of Binary Tree206
596Non-overlapping sum of two sets206
597Word Pattern206
598Trapping Rain Water LeetCode Solution206
59901 Matrix LeetCode Solution205
600Remove All Occurrences of a Substring LeetCode Solution205
601Remove Linked List Elements Leetcode Solution205
602LRU Cache LeetCode Solution205
603Maximum difference between first and last indexes of an element in array205
604Minimum Operations to convert X to Y205
605Delete consecutive same words in a sequence205
606Combinations Leetcode Solution205
607Maximum Number of Occurrences of a Substring Leetcode Solution205
608Sort Characters By Frequency LeetCode Solution205
609Count all subsequences having product less than K204
610Sieve of Eratosthenes204
611The Knapsack Problem204
612XOR Operation in an Array Leetcode Solution204
613Assign Cookies Leetcode Solution204
614Minimum number of distinct elements after removing m items204
615Find the smallest positive integer value that cannot be represented as sum of any subset of a given array203
616GCD Of Two Numbers203
617Bubble sort using two Stacks203
618Minimum insertions to form a palindrome with permutations allowed203
619Reverse a stack without using extra space in O(n)203
620Maximum Number of Chocolates to be Distributed Equally Among k Students202
621Find Largest d in Array such that a + b + c = d202
622Permutation in String Leetcode Solution202
623Rotate List Leetcode Solution202
624Isomorphic Strings202
625Find minimum difference between any two elements202
626Form minimum number from given sequence202
627Convert Sorted Array to Binary Search Tree Leetcode Solution201
628How to Create Mergable Stack?201
629Tracking current Maximum Element in a Stack201
630Insert Interval Leetcode Solution201
631Stone Game LeetCode201
632Unique Binary Search Trees201
633Sum of f(a[i], a[j]) over all pairs in an array of n integers201
634Defanging an IP Address Leetcode Solution200
635Longest Increasing Path in a Matrix LeetCode Solution200
636Reorganize String200
637Find the Duplicate Number LeetCode Solution200
638Convert an array to reduced form200
639Same Tree LeetCode Solution200
640K Empty Slots200
641Applications of Breadth First Search and Depth First Search200
642Optimal Account Balancing LeetCode Solution200
643Count Good Nodes in Binary Tree Leetcode Solution199
644Employee Free Time LeetCode Solution199
645Distance Between Bus Stops Leetcode Solution199
646Convert a Number to Hexadecimal Leetcode Solution198
647Merge Two Balanced Binary Search Trees198
648Find Pair with Greatest Product in Array198
649License Key Formatting Leetcode Solution198
650Minimum Depth of Binary Tree Leetcode Solution198
651Word Wrap Problem198
652Largest subarray with equal number of 0s and 1s198
653First Unique Character in a String LeetCode Solution198
654Find pairs with given sum such that elements of pair are in different rows198
655Printing brackets in Matrix Chain Multiplication Problem198
656Replace Elements with Greatest Element on Right Side Leetcode Solution197
657Letter Combinations of a Phone Number197
658Longest Substring with At Most K Distinct Characters LeetCode Solution197
659Painting Fence Algorithm197
660Flipping an Image LeetCode Solution196
661Robot Room Cleaner Leetcode Solution196
662Check If It Is a Straight Line Leetcode Solution196
663Sort Array By Parity LeetCode Solution196
664Moving Average from Data Stream Leetcode Solution196
665Find the Distance Value Between Two Arrays Leetcode Solution196
666Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
667Segregate 0s and 1s in an Array196
668Reducing Dishes LeetCode Solution196
669House Robber196
670Coin Change Problem196
671Find the node with minimum value in a Binary Search Tree195
672Strobogrammatic Number LeetCode Solution195
673Partition Labels LeetCode Solution195
674Valid Palindrome195
675K Empty Slots LeetCode195
676Kth Missing Positive Number Leetcode Solution195
677Print the Fibonacci numbers in reverse order195
678Longest Span with same Sum in two Binary arrays195
679Maximum Consecutive Numbers Present in an Array195
680Reservoir Sampling194
681Queries for counts of array elements with values in given range194
682Valid Palindrome II Leetcode Solution194
683k-th missing element in increasing sequence which is not present in a given sequence194
684String to Integer (atoi) LeetCode Solution194
685Dynamic Programming Basics194
686Find Leaves of Binary Tree LeetCode Solution194
687String Compression LeetCode Solution194
688Distance of nearest cell having 1 in a binary matrix194
689Longest Substring with At Least K Repeating Characters LeetCode Solution193
690Sum of All Odd Length Subarrays Leetcode Solution193
691Power of Four Leetcode Solution193
692Best Time to Buy and Sell Stock with Cooldown Leetcode Solution193
693Partition Array Into Three Parts With Equal Sum Leetcode Solution193
694Find Maximum Level sum in Binary Tree193
695Find unique character in a string193
696Maximum Product of Two Elements in an Array Leetcode Solution193
697Generate all possible sorted arrays from alternate elements of two given sorted arrays192
698Find whether an array is subset of another array192
699Binary Tree Maximum Path Sum LeetCode Solution192
700Numbers with prime frequencies greater than or equal to k192
701Check If Two String Arrays are Equivalent Leetcode Solution192
702Reverse Only Letters LeetCode Solution192
703Count quadruples from four sorted arrays whose sum is equal to a given value x191
704Remove brackets from an algebraic string containing + and – operators191
705Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest191
706Find the largest multiple of 3191
707Remove Invalid Parentheses Leetcode Solution191
708Edit Distance LeetCode Solution191
709Find the Smallest Divisor given a Threshold Leetcode Solution191
710To Lower Case Leetcode Solution191
711Increasing Decreasing String Leetcode Solution191
712Unique Paths II Leetcode Solution191
713Maximum Number of Coins You Can Get Leetcode Solution191
714Path With Maximum Minimum Value LeetCode Solution191
715Check for Palindrome after every character replacement Query190
716Delete Nth node from the end of the given linked list190
717Elements to be added so that all elements of a range are present in array190
718Merge Two Binary Trees LeetCode Solution190
719Inorder Successor of a node in Binary Tree190
720Sort Array by Increasing Frequency Leetcode Solution190
721Subset Sum Leetcode190
722Stack Permutations (Check if an array is stack permutation of other)190
723Wiggle Sort190
724Permutation Sequence LeetCode Solution190
725Base 7 Leetcode Solution190
726Snakes and Ladders LeetCode Solution190
727Valid Perfect Square Leetcode Solution190
728Bulb Switcher LeetCode Solution190
729Number of Dice Rolls With Target Sum LeetCode Solution190
730Find if Path Exists in Graph Leetcode Solution189
731Factorial Trailing Zeroes Leetcode Solution189
732Growable array based stack189
733Minimum Cost For Tickets Leetcode Solution189
734BFS vs DFS for Binary Tree189
735Race Car LeetCode Solution189
736Lucky Numbers in a Matrix Leetcode Solution189
737Valid Number189
738Non-decreasing Array LeetCode Solution189
739Populating Next Right Pointers in Each Node189
740Recover Binary Search Tree189
741Binary Tree zigzag level order Traversal189
742Number of NGEs to the Right188
743Maximum Length of a Concatenated String with Unique Characters Leetcode Solution188
744Find Maximum Depth of Nested Parenthesis in a String188
745Merge Sorted Array LeetCode Solution188
746Ugly Number Leetcode Solution188
747Perform String Shifts Leetcode188
748Keyboard Row Leetcode Solution188
749Reversing a Queue using Recursion188
750Tiling Problem188
751Minimum sum of multiplications of n numbers187
752Evaluate Reverse Polish Notation LeetCode Solution187
753Construct BST from given Preorder Traversal187
754Student Attendance Record I Leetcode Solution187
755Binary Tree Zigzag Level Order Traversal LeetCode Solution187
756Program for Bridge and Torch problem187
757Maximum 69 Number Leetcode Solution187
758Morris Traversal187
759Restore IP Addresses Leetcode Solution187
760Add and Search Word – Data structure design LeetCode187
761Majority Element II Leetcode Solution187
762String comparison containing wildcards187
763Best Meeting Point LeetCode Solution187
764Check if Two Expressions With Brackets are Same186
765Print a Binary Tree in Vertical Order186
766Split a String in Balanced Strings Leetcode Solution186
767Priority Queue using doubly linked list186
768Word Pattern LeetCode Solution186
769N-Queens LeetCode Solution186
770Maximum Profit in Job Scheduling Leetcode Solution186
771Rank Transform of an Array Leetcode Solution186
772Check If Array Pairs Are Divisible by k LeetCode Solution186
773Regular Expression Matching186
774Find All Possible Recipes from Given Supplies LeetCode Solution185
775Find Median from Data Stream LeetCode Solution185
776Binomial Coefficient185
777Brick Wall LeetCode Solution185
778Number of Days Between Two Dates LeetCode Solution185
779Symmetric Tree Leetcode Solution185
780Maximum Product of Three Numbers LeetCode Solution185
781Sorted Linked List to Balanced BST185
782Jump Game185
783Hamming Distance Leetcode Solution185
784Top K Frequent Words LeetCode Solution185
785Count items common to both the lists but with different prices185
786Finding K closest element185
787Minimize Maximum Pair Sum in Array LeetCode Solution184
788Search in a Binary Search Tree Leetcode Solution184
789Minimum Height Trees184
790Maximum Nesting Depth of the Parentheses Leetcode Solution184
791Find All Duplicates in an Array LeetCode Solution184
792Special Array With X Elements Greater Than or Equal X Leetcode Solution184
793Sort an array according to the order defined by another array184
794Partition to K Equal Sum Subsets Leetcode Solution184
795Minimum Time Visiting All Points Leetcode Solution184
796Largest Rectangle in Histogram LeetCode Solution184
797Queue based approach for first non-repeating character in a stream184
798Longest Subarray Having Count of 1s One More than Count of 0s184
799Kth ancestor of a node in binary tree183
800Linked List Cycle183
801Decompress Run-Length Encoded List Leetcode Solution183
802Maximum Depth of N-ary Tree Leetcode Solution183
803Form Minimum Number From Given Sequence183
804Merge K Sorted Linked Lists183
805Minimum Distance Between BST Nodes Leetcode Solution183
806Total Numbers With no Repeated Digits in a Range183
807Maximum Difference Between Increasing Elements LeetCode Solution182
808Largest rectangular sub-matrix whose sum is 0182
809Number of Islands II LeetCode Solution182
810Balanced Expression with Replacement182
811Given an Array of Pairs Find all Symmetric Pairs in it182
812Circular Queue182
813Remove Nth Node From End of List Leetcode Solution182
814Nested List Weight Sum II LeetCode Solution182
815One Edit Distance LeetCode Solution182
816Invert Binary Tree LeetCode Solution182
817Nearest Exit from Entrance in Maze LeetCode Solution182
818Identify and Mark Unmatched Parenthesis in an Expression181
819Final Prices With a Special Discount in a Shop Leetcode Solution181
820Relative Ranks Leetcode Solution181
821Repeated Substring Pattern LeetCode Solution181
822Diagonal Traversal of Binary Tree181
823Lemonade Change Leetcode Solution180
824Minimum time required to rot all oranges180
825A Space Optimized DP solution for 0-1 Knapsack Problem180
826Subarray Product Less Than K LeetCode Solution180
827Transpose Graph180
828Last Stone Weight II LeetCode Solution180
829Check if a given array can represent Preorder Traversal of Binary Search Tree179
830Clone Graph LeetCode Solution179
831Minimum Swaps to Make Strings Equal Leetcode Solution179
832Insert Delete GetRandom179
833Subsequence of Size K With the Largest Even Sum LeetCode Solution179
834Permutation Coefficient179
835Reorder Data in Log Files LeetCode Solution179
836Daily Temperatures Leetcode Solution179
837Split Array Into Consecutive Subsequences179
838Minimum Number of Taps to Open to Water a Garden LeetCode Solution179
839Missing Element in Sorted Array LeetCode Solution179
840Find all permuted rows of a given row in a matrix179
841Deletion in a Binary Tree179
842Course Schedule II – LeetCode179
843LCS (Longest Common Subsequence) of three strings179
844Sliding Window Maximum179
845Minimum Jumps to Reach Home LeetCode Solution179
846Crawler Log Folder Leetcode Solution179
847Search a 2D Matrix II Leetcode Solution179
848Iterative Preorder Traversal179
849Design Browser History LeetCode Solution179
850Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution179
851Number Complement Leetcode Solution178
852Sort Array By Parity II Leetcode Solution178
853Guess Number Higher or Lower LeetCode Solution178
854Sum of nearest smaller and greater number178
855Binary Search Tree Search and Insertion178
856Find the Only Repetitive Element Between 1 to N-1178
857Check if an Array is Stack Sortable178
858Find Maximum Sum Possible Equal Sum of Three Stacks178
859Distinct adjacent elements in an array178
860Remove Duplicates from Sorted List LeetCode Solution178
861Valid Parentheses Leetcode Solution178
862Remove Duplicates from Sorted List II178
863Tree Traversal (Preorder, Inorder & Postorder)178
864Alien Dictionary LeetCode Solution178
865Count Distinct Elements in Every Window of Size K177
866Spiral Matrix II Leetcode Solution177
867An Interesting Method to generate Binary Numbers from 1 to n177
868Iterative Postorder Traversal Using Two Stacks177
869Check if stack elements are pairwise consecutive177
870Interval Tree177
871Partition List Leetcode Solution177
872Get Maximum in Generated Array Leetcode Solution177
873Minimum Sum Path in a Triangle177
874Minimum number of jumps to reach end177
875Maximum Score After Splitting a String Leetcode Solution176
876Minimum swaps to make sequences increasing176
877Range LCM Queries176
878Union and Intersection of two Linked Lists176
879Subset with sum divisible by m176
880Matrix Chain Multiplication176
881Sort Colors176
882Find the subarray with least average176
883Path with maximum average value176
884Dividing Array into Pairs With Sum Divisible by K176
885Brightest Position on Street LeetCode Solution176
886Count Negative Numbers in a Sorted Matrix LeetCode Solution176
887Can Place Flowers LeetCode Solution176
888Convert BST to Min Heap175
889Friends Pairing Problem175
890Diagonal Traversal LeetCode Solution175
891Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i175
892Design a Stack With Increment Operation Leetcode Solution175
893Sequences of given length where every element is more than or equal to twice of previous175
894Minesweeper LeetCode Solution175
895Count ways to reach the nth stair using step 1, 2 or 3175
896Infix to Postfix175
897Pattern Occurrences using Stack175
898Insert into a Binary Search Tree Leetcode Solution175
899Least Number of Unique Integers after K Removals Leetcode Solution175
900GCDs of given index ranges in an array175
901Sorted Array to Balanced BST175
902Water Bottles Leetcode Solution175
903Find all triplets with zero sum175
904Level order Traversal in Spiral Form175
905Time Based Key-Value Store LeetCode Solution175
906Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution174
907Check whether a given Binary Tree is Complete or not174
908Number of Distinct Islands Leetcode Solution174
909All Unique Triplets that Sum up to a Given Value174
910Maximum size subarray sum equals k174
911Diagonal Traverse LeetCode Solution174
912Delete And Earn174
913Find distance between two nodes of a Binary Tree174
914Median of Two Sorted Arrays174
915Destination City Leetcode Solution173
916Shortest Word Distance Leetcode Solution173
917A program to check if a binary tree is BST or not173
918Guess Number Higher or Lower II173
919Set Matrix Zeroes Leetcode Solution173
920Range sum queries without updates173
921Check if any two intervals overlap among a given set of intervals172
922Lexicographical Numbers Leetcode Solution172
923Difference Array | Range update query in O(1)172
924Binary array after M range toggle operations172
925Robot Bounded In Circle LeetCode Solution172
926Rearrange Spaces Between Words Leetcode Solution172
927Count Submatrices With All Ones LeetCode Solution172
928Find Common Characters Leetcode Solution172
929Rearrange an Array Such that arr[i] is equal to i172
930Binary Tree Longest Consecutive Sequence LeetCode Solution172
931Product of Array Except Self LeetCode Solution171
932Three way partitioning of an array around a given range171
933Alien Dictionary171
934Check if the given array can represent Level Order Traversal of Binary Search Tree171
935Queue using Stacks171
936Averages of Levels in Binary Tree171
937Convert Sorted List to Binary Search Tree171
938Special Positions in a Binary Matrix Leetcode Solution171
940Construct the Rectangle Leetcode Solution171
941My Calendar I LeetCode Solution171
942K’th Largest Element in BST when modification to BST is not allowed171
9433 Sum170
944Analyze User Website Visit Pattern LeetCode Solution170
945Construct Complete Binary Tree from its Linked List Representation170
946Palindrome Partitioning Leetcode Solution170
947Longest Palindromic Subsequence170
948Spiral Matrix III LeetCode Solution170
949Count Subarrays with Same Even and Odd Elements170
950Three Consecutive Odds Leetcode Solution170
951Trim a Binary Search Tree170
952Create Maximum Number169
953Remove Duplicates from Sorted List II LeetCode Solution169
954BFS for Disconnected Graph169
955Number of Equivalent Domino Pairs Leetcode Solution169
956Word Break169
957Intersection of Two Linked Lists LeetCode Solution169
958Minimum Height Trees LeetCode Solution169
959Vertical sum in a given binary tree169
960Largest area rectangular sub-matrix with equal number of 1’s and 0’s169
961Merge Two Sorted Lists Leetcode169
962Maximum Frequency Stack Leetcode Solution169
963Symmetric Tree168
964Maximize Sum of Array after K Negations Leetcode Solution168
965Print Fibonacci sequence using 2 variables168
966Strongly Connected Component168
967Count Primes in Ranges168
968Construct BST from its given Level Order Traversal168
969Queries for GCD of all numbers of an array except elements in a given range168
970Climbing stairs168
971Design Hit Counter LeetCode Solution167
972Asteroid Collision LeetCode Solution167
973Depth First Search (DFS) for a Graph167
974Kth Smallest Element in a BST Leetcode Solution167
975Serialize and Deserialize Binary Tree167
976Combination Sum IV LeetCode Solution167
977Sign of the Product of an Array LeetCode Solution167
978Reverse Nodes in K-Group167
979Merging Intervals167
980Maximum Product Subarray167
981Longest subsequence such that difference between adjacents is one167
982Unique Paths II167
983Find Maximum of Minimum for Every Window Size in a Given Array167
984Count subarrays where second highest lie before highest167
985Count pair with Given Sum167
986Number of palindromic paths in a matrix167
987Maximum Subarray Sum Excluding Certain Elements167
988K maximum sums of overlapping contiguous sub-arrays166
989Stone Game II Leetcode166
990Breadth First Search (BFS) for a Graph166
991K Closest Points to Origin Leetcode Solution166
992Largest Number Leetcode Solution166
993Valid Boomerang Leetcode Solution166
994Longest Nice Substring LeetCode Solution166
995Maximum Length of Repeated Subarray166
996String Matching in an Array Leetcode Solution166
997Next Permutation Leetcode Solution165
998Maximum difference between frequency of two elements such that element having greater frequency is also greater165
999Can Make Arithmetic Progression From Sequence Leetcode Solution165
1000Largest Substring Between Two Equal Characters Leetcode Solution165
1001Collect maximum points in a grid using two traversals165
1002Binary Search Tree Delete Operation165
1003Count pairs from two sorted arrays whose sum is equal to a given value x165
1004Find number of pairs in an array such that their XOR is 0165
1005Height of a generic tree from parent array165
1006Find the First Circular Tour that visits all the Petrol Pumps165
1007The Maze III LeetCode Solution165
1008Scramble String LeetCode Solution165
1009Maximum length subsequence with difference between adjacent elements as either 0 or 1165
1010Kth Smallest Element in a Sorted Matrix LeetCode Solution164
1011Palindrome Partitioning164
1012Shuffle 2n integers as without using extra space164
1013Remove Duplicates from Sorted Array II Leetcode Solution164
1014Newman-Conway Sequence164
1015Find postorder traversal of BST from preorder traversal164
1016Segment Tree164
1017Print Next Greater Number of Q queries164
1018Shortest Completing Word Leetcode Solution164
1019Find the Difference Leetcode Solution164
1020Maximum Product of Indexes of Next Greater on Left and Right164
1021The Painter’s Partition Problem163
1022Level Order Traversal of Binary Tree163
1023Generate Parentheses Leetcode Solution163
1024Graph Valid Tree LeetCode Solution163
1025Length of Longest Fibonacci Subsequence163
1026Construct Binary Tree from given Parent Array representation163
1027Minimum Index Sum of Two Lists163
1028Invalid Transactions LeetCode Solution163
1029Balanced Binary Tree163
1030Consecutive Characters LeetCode Solution163
1031Friends Of Appropriate Ages LeetCode Solution163
1032Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution162
1033Validate Binary Search Tree162
1034Boundary Traversal of binary tree162
1035Maximum Sum of 3 Non-Overlapping Subarrays162
1036Merge Sort162
1037Path Sum II LeetCode Solution162
1038Rearrange array such that even positioned are greater than odd162
1039Boolean Parenthesization Problem162
1040Find Duplicate Subtrees162
1041Bitwise AND of Numbers Range LeetCode Solution162
1042Move all negative elements to end in order with extra space allowed162
1043Find a Peak Element II LeetCode Solution162
1044Decrypt String from Alphabet to Integer Mapping Leetcode Solution162
1045Maximum Number of Ways to Partition an Array LeetCode Solution162
1046Largest divisible pairs subset162
1047Custom Sort String Leetcode Solution161
1048Next Greater Element III LeetCode Solution161
1049Number Of Longest Increasing Subsequence161
1050Make The String Great Leetcode Solution161
1051Construction of Longest Increasing Subsequence (N log N)161
1052Build an Array With Stack Operations Leetcode Solution161
1053Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’161
1054First missing positive161
1055Available Captures for Rook Leetcode Solution161
1056Binary Search Tree161
1057Kill Process LeetCode Solution160
1058Iterative Depth First Traversal of Graph160
1059Double the first element and move zero to end160
1060Compute nCr % p160
1061Advantages of BST over Hash Table160
1062Insertion in a Binary Tree160
1063Print Right View of a Binary Tree159
1064Rearrange array such that even index elements are smaller and odd index elements are greater159
1065Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution159
1066Count minimum steps to get the given desired array159
1067Minimum Size Subarray Sum159
1068Subarrays with K Different Integers Leetcode Solution159
1069Add two numbers159
1070Recover Binary Search Tree Leetcode Solution159
1071Find Peak Element159
1072Ugly Numbers159
1073Defanging an IP Address LeetCode Solution158
1074Partition Equal Subset Sum158
1075Maximum subsequence sum such that no three are consecutive158
1076Smallest Common Region Leetcode Solution158
1077Remove Palindromic Subsequences Leetcode Solution158
1078Regular Expression Matching Regular Expression Matching LeetCode Solution158
1079Morris Inorder Traversal158
1080Employee Importance LeetCode Solution158
1081Largest BST Subtree LeetCode Solution158
1082Ugly Number II LeetCode Solution157
1083Find maximum difference between nearest left and right smaller elements157
1084Lowest Common Ancestor157
1085Find whether a subarray is in form of a mountain or not157
1086Maximum weight transformation of a given string157
1087Remove duplicates from sorted array157
1088Cells with Odd Values in a Matrix LeetCode Solution157
1089Level order traversal using two Queues157
1090Palindromic Substrings Leetcode Solution156
1091Valid Tic-Tac-Toe State LeetCode Solution156
1092Find Three Element From Different Three Arrays Such That a + b + c = sum156
1093Populating Next Right Pointers in Each Node Leetcode Solution156
1094Longest Bitonic Subsequence156
1095Binary Tree Right Side View LeetCode Solution156
1096Maximize Distance to Closest Person LeetCode Solution156
1097Implement Trie (Prefix Tree) Leetcode Solution156
1098Palindrome Permutation LeetCode Solution156
1099Super Ugly Number156
1100Number of siblings of a given Node in n-ary Tree156
1101Number of Closed Islands Leetcode Solution155
1102Find the minimum distance between two numbers155
1103Increasing Triplet Subsequence LeetCode Solution155
1104Path Sum155
1105Search in Sorted Rotated Array155
1106Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution155
1107Print all triplets in sorted array that form AP155
1108Kth Smallest Product of Two Sorted Arrays LeetCode Solution155
1109Bus Routes Leetcode Solution155
1110Iterative method to find ancestors of a given binary tree154
1111Serialize and Deserialize Binary Tree LeetCode Solution154
1112Binary Tree Data Structure154
1113Clone a Binary Tree with Random Pointers154
1114Sum of Even Numbers After Queries154
1115Products of ranges in an array154
1116Reformat The String Leetcode Solution154
1117Divisible Pairs Counting154
1118Number of Students Doing Homework at a Given Time Leetcode Solution154
1119Thousand Separator Leetcode Solution153
1120Search Insert Position153
1121Day of the Year Leetcode Solution153
1122Moser-de Bruijn Sequence153
1123Distinct Subsequences153
1124Find Smallest Range Containing Elements from k Lists153
1125Prime Palindrome LeetCode Solution153
1126Count Largest Group Leetcode Solution152
1127Longest Repeated Subsequence152
1128Diameter of N-Ary Tree LeetCode Solution152
1129Reformat Date LeetCode Solution152
1130Bottom View of a Binary Tree152
1131Longest Subarray of 1’s After Deleting One Element LeetCode Solution152
1132Queries for Number of Distinct Elements in a Subarray152
1133Minimum sum of squares of character counts in a given string after removing k characters152
1134Root to Leaf path with target sum Leetcode Solutions152
1135Mean of Array After Removing Some Elements Leetcode Solution152
1136Minimum Absolute Difference in BST Leetcode Solution152
1137Minimum Score Triangulation of Polygon Leetcode Solution152
1138Level of Each node in a Tree from source node152
1139Maximum Product of Splitted Binary Tree LeetCode Solution151
1140Maximum Product Subarray151
1141Write Code to Determine if Two Trees are Identical151
1142Golomb sequence151
1143Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution151
1144Construct K Palindrome Strings LeetCode Solution151
1145Third Maximum Number Leetcode Solution151
1146Longest Increasing Consecutive Subsequence151
1147Maximum Depth Of Binary Tree151
1148Minimum Moves to Equal Array Elements LeetCode Solution150
1149Print modified array after executing the commands of addition and subtraction150
1150Constant time range add operation on an array150
1151Search an Element in Sorted Rotated Array150
1152Find maximum length Snake sequence150
1153Compare Strings by Frequency of the Smallest Character Leetcode Solution150
1154Find Largest Value in Each Tree Row LeetCode Solution150
1155Priority Queue150
1156Convert BST into a Min-Heap without using array150
1157Topological Sorting150
1158Closest Leaf in a Binary Tree LeetCode Solution150
1159Kth Smallest Number in Multiplication Table Leetcode Solution149
1160Subset Sum Problem in O(sum) space149
1161Swap Nodes In Pairs149
1162Contiguous Array LeetCode Solution149
1163Search Suggestions System LeetCode Solution149
1164Rotate Array149
1165Count even length binary sequences with same sum of first and second half bits148
1166Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution148
1167Maximize sum of consecutive differences in a circular array148
1168Maximum Binary Tree148
1169Check Array Formation Through Concatenation Leetcode Solution148
1170Web Crawler LeetCode Solution148
1171Cutting a Rod148
1172Closest Binary Search Tree Value Leetcode Solution148
1173Factorial Trailing Zeroes LeetCode Solution148
1174Delete Nodes and Return Forest Leetcode Solution147
1175Reverse a Path in BST using Queue147
1176Find a sorted subsequence of size 3 in linear time147
1177Possible Bipartition LeetCode Solution147
1178Decision Tree147
1179Perfect Squares LeetCode Solution147
1180First Bad Version146
1181Red-Black Tree Introduction146
1182Valid Triangle Number146
1183Decrease Elements To Make Array Zigzag LeetCode Solution146
1184Count Pairs Whose Products Exist in Array146
1185Binary Tree to Binary Search Tree Conversion146
1186Merge two BSTs with limited extra space146
1187Matchsticks to Square Leetcode Solution146
1188Minimum Sideway Jumps LeetCode Solution146
1189Given a binary tree, how do you remove all the half nodes?146
1190Concatenation of Array LeetCode Solution146
1191Transform a BST to Greater sum Tree146
1192Minimum Swaps To Make Sequences Increasing LeetCode Solution146
1193Replace two consecutive equal values with one greater146
1194Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1195Path Crossing Leetcode Solution145
1196Sum of Left Leaves LeetCode Solution145
1197Maximum number of segments of lengths a, b and c145
1198Maximum sum of a path in a Right Number Triangle145
1199Queries on Probability of Even or Odd Number in given Ranges145
1200K’th Largest element in BST using constant extra space145
1201Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution144
1202Find the smallest binary digit multiple of given number144
1203Divide Two Integers Leetcode Solution144
1204Number of Orders in the Backlog Leetcode Solution144
1205Maximum sum bitonic subarray144
1206Maximum Value at a Given Index in a Bounded Array LeetCode Solution144
1207Print n terms of Newman-Conway Sequence143
1208Swapping Nodes in a Linked List Leetcode Solution143
1209Convert Sorted Array to Binary Search Tree LeetCode Solutions143
1210Maximum sum of pairs with specific difference143
1211Valid Perfect Square LeetCode Solution143
1212Queue Reconstruction by Height143
1213Sliding Window Median Leetcode Solution143
1214Lowest Common Ancestor of a Binary Tree Leetcode Solution143
1215New 21 Game142
1216Moving Stones Until Consecutive Leetcode Solution142
1217Guess The Word142
1218Integer Break LeetCode Solution142
1219How to print maximum number of A’s using given four keys142
1220Find minimum number of merge operations to make an array palindrome142
1221Array Queries for multiply replacements and product141
1222Find Minimum in Rotated Sorted Array II LeetCode Solution141
1223Graph and its representation141
1224Range Sum Query using Sparse Table141
1225Champagne Tower LeetCode Solution141
1226Longest Common Prefix Using Word by Word Matching141
1227LRU Cache Leetcode Solution140
1228Bold Words in String LeetCode Solution140
1229Check if all levels of two Binary Tree are anagrams or not140
1230Flatten 2D Vector LeetCode Solution140
1231Kth Smallest Element in a BST140
1232Range Queries for Longest Correct Bracket Subsequence140
1233Lowest Common Ancestor in Binary Search Tree140
1234Contiguous Array139
1235Merge k Sorted Lists Leetcode Solution139
1236Mean of range in array139
1237Maximum Sum Increasing Subsequence139
1238Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution139
1239Maximum Array from Two given Arrays Keeping Order Same139
1240The kth Factor of n Leetcode Solution138
1241BST to a Tree with Sum of all Smaller Keys138
1242Maximum Product Subarray138
1243Missing Number138
1244Largest Plus Sign Leetcode Solution138
1245Maximize Elements Using Another Array138
1246Print modified array after multiple array range increment operations138
1247Design Skiplist LeetCode Solution138
1248Write a function to get the intersection point of two Linked Lists138
1249Minimum Remove to Make Valid Parentheses LeetCode Solution137
1250Arithmetic Slices II – Subsequence LeetCode Solution137
1251Count Subsets Having Distinct Even Numbers137
1252Parallel Courses II LeetCode Solution137
1253Find k-th smallest element in BST (Order Statistics in BST)137
1254Image Overlap LeetCode Solution136
1255Graph Cloning136
1256Different Ways to Add Parentheses Leetcode Solution136
1257Min Cost Climbing Stairs LeetCode Solution136
1258Power of Two135
1259Check in binary array the number represented by a subarray is odd or even135
1260Check if each internal node of a BST has exactly one child135
1261Check for Identical BSTs without building the trees134
1262Symmetric Tree LeetCode Solution Leetcode Solution134
1263Check Completeness of a Binary Tree LeetCode Solution134
1264Verify Preorder Serialization of a Binary Tree134
1265Koko Eating Bananas LeetCode Solution134
1266Minimum Time to Collect All Apples in a Tree LeetCode Solution134
1267Check if two nodes are on the same path in a Tree134
1268Smallest Range II Leetcode Solution133
1269Print Ancestors of a Given Binary Tree Node Without Recursion133
1270Excel Sheet Column Title LeetCode Solution132
1271Orderly Queue LeetCode Solution132
1272Longest Substring Without Repeating Characters Leetcode Solution132
1273Count and Toggle Queries on a Binary Array132
1274Next greater element132
1275Merge Sorted Array131
1276Number of elements less than or equal to a given number in a given subarray130
1277Vertical Order Traversal of Binary Tree LeetCode Solution130
1278Arranging Coins Leetcode Solution130
1279Array Nesting Leetcode Solution130
1280Largest Submatrix With Rearrangements LeetCode Solution129
1281Palindrome Partitioning129
1282Palindrome Number LeetCode Solution129
1283Check if X can give change to every person in the Queue127
1284Peeking Iterator LeetCode Solution127
1285Add Two Numbers II Leetcode Solution127
1286Maximum product of an increasing subsequence126
1287Continuous Subarray Sum LeetCode Solution126
1288Find the Winner of the Circular Game LeetCode Solution126
1289Newman–Shanks–Williams prime126
1290Check If a String Can Break Another String Leetcode Solution126
1291Find maximum average subarray of k length126
1292Insert Delete GetRandom O(1) Leetcode Solution125
1293Queries for Decimal Values of Subarrays of a Binary Array125
1294Range Minimum Query (Square Root Decomposition and Sparse Table)125
1295Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution124
1296Check given array of size n can represent BST of n levels or not123
1297Encoded String With Shortest Length LeetCode Solution123
1298Jump Game IV LeetCode Solution122
1299Minimum Number of People to Teach LeetCode Solution121
1300Convert to Base -2 LeetCode Solution121
1301Number of indexes with equal elements in given range121
1302Binary Tree to Binary Search Tree Conversion using STL set121
1303Random Pick Index LeetCode Solution121
1304Reach a Number LeetCode Solution121
1305Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution121
1306Convert a BST to a Binary Tree such that sum of all greater keys is added to every key119
1307Minimum Total Space Wasted With K Resizing Operations LeetCode Solution118
1308Design A Leaderboard Leetcode Solution116
1309Design Underground System Leetcode Solution116
1310Shifting Letters LeetCode Solution115
1311Queries on XOR of greatest odd divisor of the range115
1312Detect Capital Leetcode Solution112
1313Print Maximum Length Chain of Pairs111
1314Minimum Swaps to Group All 1’s Together Leetcode Solution110
1315Top K Frequent Elements LeetCode Solution110
1316Substring with Concatenation of All Words Leetcode Solution109
1317Minimum Path Sum Leetcode Solution108
1318Count Sub Islands LeetCode Solution108
1319Odd Even Linked List Leetcode Solution107
1320Monotonic Array Leetcode Solution106
1321Maximum Population Year LeetCode Solution104
1322Binary Tree Inorder Traversal LeetCode Solution104
1323Decode String Leetcode Solution103
1324Longest Common Subsequence LeetCode Solution103
1325Find the Town Judge LeetCode Solution102
1326Shortest Unsorted Continuous Subarray LeetCode Solution98
1327Best Meeting Point LeetCode Solution96
1328Rectangle Overlap LeetCode Solution96
1329Sum Root to Leaf Numbers LeetCode Solution93
1330Maximum Population Year LeetCode Solution93
1331Flatten Binary Tree to Linked List LeetCode Solution93
1332Design Add and Search Words Data Structure LeetCode Solution92
1333Insert into a Sorted Circular Linked List LeetCode Solution92
1334Find the Town Judge LeetCode Solution92
1335Stone Game IV LeetCode Solution90
1336Is Graph Bipartite? LeetCode Solution89
1337Score of Parenthesis LeetCode Solution89
1338Valid Triangle Number LeetCode Solution88
1339Range Sum Query 2D – Immutable LeetCode Solution88
1340Reveal Cards In Increasing Order Leetcode Solution88
1341Divide Chocolate LeetCode Solution82
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution76
1343Range Sum of BST LeetCode Solution71
1344Reverse Integer Leetcode Solution69
1345Rotate String LeetCode Solution66
1346Find K Closest Elements LeetCode Solution66
1347Sort Colors LeetCode Solution65
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution63
1349Excel Sheet Column Number LeetCode Solution60
1350Maximum Size Subarray Sum Equals k Leetcode Solution52
1351H-Index Leetcode Solution47
1352Camelcase Matching Leetcode Solution45
1353Valid Anagram Leetcode Solution45
1354Most Stones Removed with Same Row or Column LeetCode Solution45
1355Sliding Window Maximum LeetCode Solution44
1356High Five LeetCode Solution43
1357Container With Most Water LeetCode Solution43
1358Find Peak Element LeetCode Solution43
1359Next Permutation LeetCode Solution42
1360Group Anagrams LeetCode Solution42
1361Binary Search LeetCode Solution41
1362Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution41
1363Paint House LeetCode Solution40
1364Sentence Screen Fitting LeetCode Solution37
1365Minimum Number of Arrows to Burst Balloons LeetCode Solution37
1366Flatten Binary Tree to Linked List LeetCode Solution37
1367Group Shifted Strings Leetcode Solution37
1368Next Greater Element I Leetcode Solution36
1369Valid Triangle Number LeetCode Solution36
1370Split Linked List in Parts Leetcode Solution36
1371The Number of Weak Characters in the Game LeetCode Solution35
1372Unique Binary Search Trees LeetCode Solution35
1373Isomorphic Strings LeetCode Solution35
1374Count Good Nodes in Binary Tree LeetCode Solution34
1375Peak Index in a Mountain Array LeetCode Solution33
1376Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution33
1377Closest Binary Search Tree Value II LeetCode Solution32
1378Swim in Rising Water LeetCode Solution32
1379Single Element in a Sorted Array LeetCode Solution31
1380Best Time to Buy and Sell Stock IV LeetCode Solution31
1381Find First and Last Position of Element in Sorted Array LeetCode Solution29
1382Max Sum of Two Non-Overlapping Subarrays LeetCode Solution29
1383Minimum Increment to Make Array Unique Leetcode Solution29
1384Lowest Common Ancestor of a Binary Search Tree Leetcode Solution28
1385All Possible Full Binary Trees LeetCode Solution28
1386Contains Duplicate LeetCode Solution28
1387Greatest Sum Divisible by Three LeetCode Solution27
1388Remove All Ones With Row and Column Flips Leetcode Solution27
1389Validate Stack Sequences LeetCode Solution27
1390Detect Squares LeetCode Solution26
1391Trapping Rain Water II LeetCode Solution26
1392Implement Rand10() Using Rand7() Leetcode Solution26
1393Stone Game IV LeetCode Solution25
1394Reverse Nodes in k-Group LeetCode Solution25
1395Implement strStr() LeetCode Solution25
1396Break a Palindrome LeetCode Solution25
1397Invert Binary Tree LeetCode Solution24
1398Fibonacci Number LeetCode Solution22
1399Design Bounded Blocking Queue LeetCode Solution21
1400Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution21
1401Total Hamming Distance LeetCode Solution19
1402Unique Paths III LeetCode Solution19
1403Candy LeetCode Solution18
Translate »