Invert Binary Tree LeetCode Solution

Difficulty Level Easy
Frequently asked in Adobe Amazon Apple Bloomberg ByteDance eBay Facebook Goldman Sachs Google LinkedIn Microsoft Oracle PayPal Uber VMware YahooViews 3

Problem Statement:

Invert Binary Tree LeetCode Solution : Given the root of a binary tree, invert the tree, and return its root.

An inverted form of a Binary Tree is another Binary Tree with left and right children of all non-leaf nodes interchanged. You may also call it the mirror of the input tree. NOTE: The tree is binary so there could be a maximum of two child nodes. To put it simply, inverting a binary tree means creating its mirror image. More formally, it means swapping the children of each of its non-leaf nodes. Therefore, the left child of a node will take the place of the right child and vice-versa.


Example 1:

Invert Binary Tree LeetCode SolutionPin


 root = [4,2,7,1,3,6,9]



Example 2:

Invert Binary Tree LeetCode SolutionPin


 root = [2,1,3]



Example 3:


 root = []





We will solve the problem with the help of recursion. We only need to swap the left and right child pointers and do the same for the child pointers recursively.

One way to invert a binary tree is to use the power of recursion. Every node contains a value (in our case, an integer) and two pointers, one for each of the node’s children. Our algorithm will begin at the root node.

First, we will check whether the current node exists. This might seem counter-intuitive but bear with me. If it doesn’t exist (this will be expressed in C as the node is equal to NULL), we are done inverting. Fulfilling this condition will be the base case for our recursive calls.

If the current node exists (i.e. it’s not NULL), we swap its left child for its right child. We then perform the above steps recursively on both of the node’s children.


Invert Binary Tree C++ Solution:

 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
class Solution {
    TreeNode* invertTree(TreeNode* root) {
            return root;
        TreeNode* temp= root->right;
        root->right = root->left;
        root->left = temp;
        return root;            

Complexity Analysis of  Invert Binary Tree LeetCode Solution:

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2885
2Java program to find the number of Nodes in a Binary Tree2540
3Reverse a string without affecting special characters2522
4Palindrome using Recursion2487
5Delete a node of a linked list at given position2022
6Quick Sort1767
7Insert nodes in a linked list in a sorted way (Ascending Order)1708
8Find elements pair from array whose sum equal to number1686
9Sort Elements by Frequency of Occurrences1671
10Write a program to print all permutations of a given string1654
11Find Minimum Distance Between Two Numbers in an Array1516
12Create a Doubly Linked List1483
13Reverse an Array1461
14Smallest window in a string containing all characters of another string1435
15Recursively remove all adjacent duplicates1403
16Find a Triplet That Sum to a Given Value1391
17First Repeating Element1384
18Sum of numbers in String1361
19Arrange Even and Odd number such that Odd comes after Even1357
20Smallest Positive Number Missing in an Unsorted Array1325
21Check if the Elements of an Array are Consecutive1290
22Detect a loop in the Linked List1270
23Largest Sum Contiguous Subarray1260
24Quick Sort on SIngly Linked List1256
25Subarray with Given Sum1247
26Print all Possible Combinations of R Elements in a given Array of size N1245
27Recursive function to do substring search1245
28Find the Maximum Repeating Number in Array1203
29Find the First and Second Smallest Elements1155
30Binary Tree Level order traversal in Java1154
31Check if two linked lists are identical1140
32Maximum Subarray Sum using Divide and Conquer1139
33Remove characters from first string which are in second1112
34Find Leaders in an Array1092
35Swap nodes in the linked list1081
36Find the second most frequent character1034
37Find the Number Occurring Odd Number of Times in an Array1033
38Arrange given Numbers to Form the Biggest Number II1026
39Given a string find its first non-repeating character1014
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 x993
42Total number of occurrences of a given item in the linked list990
43A Program to check if strings are rotations of each other or not987
44Print all possible words from phone digits970
45Find the Missing Number962
46Rearrange Positive and Negative Numbers Alternatively in Array950
47Longest Palindromic Substring944
48Segregate even and odd nodes in a linked list933
49Print Longest common subsequence924
50Transform one string to another using minimum number of given operations910
51Union and Intersection of Two Linked Lists905
52Check rearranged string can form a palindrome895
53Rearrange given Array in Maximum Minimum Form875
54Iterative Implementation of Quick Sort867
55Insertion Sort855
56Count Possible Triangles855
57Multiplication of Two Matrices840
58Count of Triplets With Sum Less than Given Value829
59Stock Buy Sell to Maximize Profit827
60Rotate a Linked List825
61Check if the linked list is palindrome823
62Concatenation of two strings803
63Tug of War795
64Count Number of Substrings with K Distinct Character’s793
65Print all duplicates in the input string793
66Find Nearest Greater and Smaller Element782
67Reverse String Without Temporary Variable775
68The Celebrity Problem771
69Remove ‘b’ and ‘ac’ from a given string768
70Find Pythagorean Triplets from Array767
71Find all Common Elements in Given Three Sorted Arrays763
72Remove all duplicates in an unsorted linked list738
73Find the Row with Maximum Number of 1’s737
74Find the subarray whose sum is equal to a given number X735
75Remove Minimum Characters so that Two Strings Become Anagrams735
76Find the Peak Element from an Array732
77Addition of Two Matrices727
78Find Smallest Missing Number in a Sorted Array724
79Generate all Binary Strings Without Consecutive 1’s722
80A Product Array Puzzle720
81Maximum Sum of Non Consecutive Elements709
82Implement Two Stacks in an Array702
83Lexicographic rank of string695
84Check if Two given Matrices are Identical689
85Maximum Product Subarray II686
86Multiplication of Previous and Next680
87Subtraction of Two Matrices672
88Merge K Sorted Arrays and Print Sorted Output667
89Move All the Zeros to the End of the Given Array664
90Online Algorithm for Checking Palindrome in a Stream663
91Form Minimum Number from Given Sequence of D’s and I’s663
92Divide a string in N equal parts660
93Check whether two strings are anagram of each other655
94Remove recurring digits in a given number652
95Sort a stack using a temporary stack651
96Maximum Circular Subarray Sum647
97Sort a linked list that is sorted alternating ascending and descending642
98Subarray and Subsequence638
99Find the Minimum Element in a Sorted and Rotated Array636
100First Circular Tour to Visit all the Petrol Bunks632
101Move last element of the Linked List at first place631
102Maximum Element in an Array which is Increasing and then Decreasing626
103Largest Subarray with Equal Number of 0’s and 1’s626
104Compare two strings(linked lists)626
1053Sum Leetcode Solution625
106Palindrome Permutations of a String624
107Flattening a linked list621
108Palindromes in a given range619
109Majority Element615
110Pangram Checking615
111Run length encoding615
112Minimum insertions to form a shortest palindrome614
113Print all permutations with repetition612
114Elements Appear more than N/K times in Array610
115Minimum Characters to be Added at Front to Make String Palindrome606
116Most repeating character in a string604
117Two Sum Leetcode Solution601
118Rotate string to get lexicographically minimum string599
119Repeated Subsequence of Length Two or More596
120Remove all duplicates in a sorted linked list593
121Rearrange a given linked list in-place593
122Minimum number of Merge Operations to make an Array Palindrome592
123Merge a linked list into another at alternate positions591
124Print all anagrams together in a sequence of words585
125Reorder an Array According to the Given Indexes579
126Pancake Sorting Problem576
127Merge Overlapping Intervals II566
128Clone a Linked List with next and random pointer565
129Transpose of a Matrix564
130Remove Extra Spaces from a String563
131Remove duplicates from a string562
132Smallest Palindrome after Replacement562
133Longest Palindrome can be Formed by Removing or Rearranging Characters561
134Maximum Sum Increasing Subsequence559
135Removing Spaces from a String using stringstream557
136Size of The Subarray With Maximum Sum555
137Check if a given string is a rotation of a palindrome555
138Partition Problem551
139Check whether Strings are K Distance Apart or Not544
140Generate all Binary Strings from Given Pattern543
141Length of Longest valid Substring540
142Delete Last Occurrence536
143Check if Two given Strings are Isomorphic to each other535
144Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized533
145Insert Node in the Sorted Linked List531
146Maximum difference between two elements such as larger element comes after smaller525
147Program to Toggle all Characters in a String524
148Given string is interleaving of two other strings or not521
149Count Minimum Steps to Get the given Array514
150Number of Smaller Elements on Right Side512
151Check length of a String is Equal to the Number Appended at its Last511
152Check if all Rows of a Matrix are Circular Rotations of Each Other507
153Find Pair with Given Difference505
154Longest Common Prefix using Divide and Conquer504
155Merge sort better than quick sort for linked lists503
156Compare Two Version Numbers496
157Print all interleavings of given two strings495
158Print Reverse of a string (Recursion)495
159Median of Two Sorted Arrays LeetCode Solution494
160Find nth node of the Linked list from the end494
161Sort 0s 1s and 2s in an Array493
162Find a Fixed Point in a Given Array493
163Reorder Array Using Given Indexes491
164Reverse words in a given string489
165Merge two sorted linked lists such that merged list is in reverse order482
166Find the Subarray of given length with Least Average481
167Split linked list using alternate nodes480
168Print all Palindromic Partitions of a String473
169Print string of odd length in ‘X’ format470
170Find Element Using Binary Search in Sorted Array468
171Find K Length Subarray of Maximum Average464
172Swap Kth Node from beginning with Kth Node from End461
173Find Duplicates in an Array in Most Efficient Way457
174Shortest Superstring Problem452
175print all palindromic partitions451
176Check if String Follows Order of Characters by a Pattern or not450
177Maximum Length of Chain Pairs448
178Sort a String According to Another String446
179Flatten a multilevel linked list444
180Sorting a K Sorted Array438
181Program to add two binary digits431
182Find a Sorted Subsequence of size 3426
183Recursively print all the sentences that can be formed from list of word lists425
184Caesar Cipher425
185Longest Span with same Sum in two Binary Arrays II424
186Longest Common Prefix Using Binary Search II423
187Find the two Numbers with Odd Occurrences in an Unsorted Array422
188Reverse a Linked List in groups422
189Kth Non-repeating Character420
190Reverse a Singly Linked List (Iterative/Non-Recursive)416
191Check if String can Become Empty by Recursively Deleting given Substring413
192Rearrange a linked list in Zig-Zag407
193Longest Common Prefix Word by Word Matching407
194Rotate Image by 90 degrees405
195Perfect Reversible String403
196Permutations of a Given String Using STL403
197Pancake Sorting401
198Find First non-repeating character in a string398
199Merging Two Sorted Arrays398
2001`s and 2`s complement of binary number398
201Increasing Subsequence of Length three with Maximum Product394
202Maximum occurring character in a string391
203List items containing all characters of a given word391
204Find the point where a monotonically increasing function becomes positive first time390
205Sort a linked list with 0s, 1s and 2s388
206Four Elements that Sum to Given388
207Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes386
208Longest Common Prefix using Character by Character Matching385
209Count Number of Occurrences in a Sorted Array382
210Palindrome string (number)382
211Valid Parentheses LeetCode Solution379
212Delete N nodes after M376
213Minimum Characters to be Removed to Make a Binary String Alternate376
214Split a string373
215Even Substring Count372
216Convert a String that is Repetition of a Substring of Length K369
217Recursive Implementation of atoi()369
218Sorting the array of strings369
219Check if a Linked list of Strings form a Palindrome363
220Print Shortest Path to Print a String on Screen363
221Maximum Subarray Leetcode Solution361
222Convert string1 to string2 in one edit359
223Reverse a String using Stack358
224Print All Distinct Elements of the Array358
225Find the first Repeating Number in a Given Array356
226Matrix Chain Multiplication using Dynamic Programming356
227Reverse a singly linked list recursively356
228wildcard character matching355
229Nth Character in Concatenated Decimal String355
230Lower Case To Upper Case352
231Count the number of words352
232Can we reverse a linked list in less than O(n) time ?349
233Binary Tree to Doubly linked list345
234Sort Elements by Frequency II344
235Longest Common Subsequence with Permutations343
236Find the Lost Element From a Duplicated Array343
237Split Four Distinct Strings339
238Merge Two Sorted Arrays339
239Find middle of the Linked List335
240Count the Pairs at Same Distance as in English Alphabets334
241Roman to Integer Leetcode Solution334
242Toeplitz Matrix327
243Palindrome Permutation325
244Word Search Leetcode Solution324
245Next Greater Element in an Array323
246Move all negative elements to one side of array322
247N queen problem321
248Sudoku Solver315
249Find All Pairs With a Given Difference315
250Find Nth Node314
251Number of Islands LeetCode Solution313
252First non Repeating Element313
253Reverse Bits312
254String(represents an integer) to value312
255Print all Possible Ways to Break a String in Bracket Form312
256Searching a node in a Binary Search Tree312
257Count Pairs With Given Sum312
258Triplet from three linked lists with given sum311
259Reverse a String311
260Types of Binary Tree310
261Repeated Substring Pattern309
262How to Efficiently Implement k Stacks in a Single Array?308
263Change Gender of a given String308
264Delete a Tree308
265Meeting Rooms II LeetCode Solution307
266Sort an array of strings305
267Number of sub-strings which recursively add up to 9305
268Fibonacci numbers304
269Longest Palindromic Substring LeetCode Solution304
270Min Stack303
271Delete a node under given conditions303
272Reverse a linked list303
273Most Frequent Element in an Array302
274Cuckoo sequence program301
275Dijkstra Algorithm300
276Longest Common Extension297
277Binary Tree296
278House Robber Leetcode Solution296
279Max stack294
280Remove spaces from a string294
281Best Time to Buy and Sell Stock  II Leetcode Solution293
282Subset Leetcode290
283Shuffle a given Array289
284Word Search289
285KMP Algorithm287
286Minimize the maximum difference between the heights286
287Expression Evaluation286
288Plus One Leetcode Solution286
289Find, second, frequent, character286
290Remove middle points in a linked list of line segments286
291Combination Sum Leetcode Solution284
292Number Of 1 bits282
293Reverse words in a string281
294Search Insert Position Leetcode Solution281
295Evaluation of Postfix Expression280
296Pair of Positive Negative Values in an Array280
297Set Matrix Zeroes278
298Valid Palindrome Leetcode Solution276
299Min Stack Leetcode Solution276
300Sliding Window Technique276
301Rabin Karp Algorithm273
302Subarray with 0 sum273
303Backspace String Compare273
304Sort linked which is sorted on absolute values272
305Common elements in all rows of a given matrix271
306Clone a linked list with next and random pointer (Hashing)270
307Sqrt(x) Leetcode Solution268
308Merge Sorted Arrays Leetcode Solution268
309Delete middle element of a stack267
310Reversing a Queue266
311Implementation of Deque using Doubly Linked List264
312Contains Duplicate II Leetcode Solution264
313Count of index pairs with equal elements in an array263
314Product of array except self263
315Combination Sum262
316Contains Duplicate262
317Tower Of Hanoi262
318String Compression261
319Pascal Triangle Leetcode261
320Intersection of Two Arrays II Leetcode Solution261
321Count subarrays with equal number of 1’s and 0’s261
322Find Top K (or Most Frequent) Numbers in a Stream260
323Minimum swaps required to bring all elements less than or equal to k together260
324Integer to Roman Leetcode Solution259
325Reverse individual words259
326Count Odd Numbers in an Interval Range Leetcode Solution259
327Page Replacement Algorithms in Operating Systems258
328How to Delete a Linked List258
329Segregate even and odd numbers256
330Group Words With Same Set of Characters256
331Postfix to Infix Conversion256
332Second Most Repeated Word in a Sequence255
333Single Number Leetcode Solution255
334Sort elements by frequency255
335Minimum Value to Get Positive Step by Step Sum Leetcode Solution255
336Find sum of non-repeating elements (distinct) elements in an array255
337Sorting array using Stacks254
338Bellman Ford Algorithm254
339Arithmetic Expression Evaluation254
340Sum of minimum and maximum elements of all subarrays of size k254
341Smallest Subarray with k Distinct Numbers254
342Add Binary Leetcode Solution253
343Next Permutation252
344Top K Frequent Words252
345K-th Smallest Element in a Sorted Matrix252
346Construct Binary Tree from Given Inorder and Preorder Traversals251
347Pow(x, n) Leetcode Solution251
348Minimum operation to make all elements equal in array251
349Maximum Number of Balloons Leetcode Solution250
350Longest Common Prefix Leetcode Solution249
351Palindrome Linked List Leetcode Solution249
352Given two unsorted arrays find all pairs whose sum is x248
353Convex Hull Algorithm248
354First element occurring k times in an array248
355Count subarrays having total distinct elements same as original array248
356Design a stack that supports getMin() in O(1) time and O(1) extra space247
357Scramble String247
358Kruskal Algorithm247
359Special Number246
360Longest Substring Without Repeating Characters LeetCode Solution246
361Find Lucky Integer in an Array Leetcode Solution245
362Majority Element Leetcode Solution245
363Evaluate Division245
364Permutations Leetcode Solution244
365Third Maximum Number Leetcode Solution244
366Reversing the First K elements of a Queue243
367Reverse a Number Using Stack242
368Find duplicates in a given array when elements are not limited to a range242
369Running Sum of 1d Array Leetcode Solution242
370Spiral Matrix LeetCode Solution242
371Number of Good Pairs Leetcode Solution242
372Prefix to Infix Conversion241
373Fizz Buzz Leetcode241
374Maximum possible difference of two subsets of an array241
375Minimum Path Sum240
376Find the Town Judge Leetcode Solution240
377Huffman Coding240
378Find Numbers with Even Number of Digits Leetcode Solution240
379Check if two arrays are equal or not240
380Maximum Subarray240
381Swap Nodes in Pairs Leetcode Solutions239
382Group Anagrams239
383Maximal Square239
384Unique Paths238
385Minimum Absolute Difference Leetcode Solution238
386Maximum Distance Between two Occurrences of Same Element in Array238
387Minimum Steps to reach target by a Knight238
388Single Number238
389Count Primes Leetcode Solutions238
390Find the Closest Palindrome number238
391Sort Array by Increasing Frequency Leetcode Solution237
392Smallest Element Repeated Exactly K Times236
393Find top three repeated in array236
394Range Sum Query 2D – Immutable Leetcode Solution236
395Palindrome Substring Queries236
396Sorting using trivial hash function235
397Zigzag Conversion235
398Convert String To Int235
399Find the first repeating element in an array of integers235
400Pascal’s Triangle II Leetcode Solution235
401Implement Stack and Queue using Deque234
402Remove Minimum Number of Elements Such That no Common Element Exist in both Array234
403Leetcode Permutations233
404Merge Two Sorted Lists Leetcode Solutions233
405Matrix Diagonal Sum Leetcode Solution233
406Cumulative Frequency of Count of Each Element in an Unsorted Array233
407Missing Number Leetcode Solution233
408Find Number of Employees Under every Employee233
409Power of Two Leetcode Solution233
410Find All Numbers Disappeared in an Array Leetcode Solution232
411Letter Case Permutation232
412Length of the largest subarray with contiguous elements232
413Check if Array Contains Contiguous Integers With Duplicates Allowed232
414How to Implement Stack Using Priority Queue or Heap?232
415Expression Contains Redundant Bracket or Not232
416Sort Integers by The Number of 1 Bit Leetcode Solution232
417Happy Number Leetcode Solution231
418LRU Cache Implementation231
419Print all subarrays with 0 sum231
420House Robber II Leetcode Solution231
421Count Substrings with equal number of 0s, 1s and 2s231
422Bipartite Graph231
423Top K Frequent Elements231
424Print All Distinct Elements of a Given Integer Array231
425Fizz Buzz230
426Decode String230
427Maximum Depth of Binary Tree Leetcode Solution230
428Difference between highest and least frequencies in an array230
429Search in Rotated Sorted Array Leetcode Solution229
430Subarray Sum Equals k229
431Unique Paths Leetcode Solution229
432Subset sum problem229
433Sort a stack using recursion229
434Prim’s Algorithm229
435Find all pairs (a, b) in an array such that a % b = k229
436Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution228
437Find Winner on a Tic Tac Toe Game Leetcode Solution228
438Count pairs from two linked lists whose sum is equal to a given value228
439Coin Change 2 Leetcode Solution228
440Find Median from data Stream227
441Check If N and Its Double Exist Leetcode Solution227
442Max Consecutive Ones Leetcode Solution227
443Nth Catalan Number227
444Reverse Integer227
445Capacity To Ship Packages Within D Days Leetcode Solution227
446How Many Numbers Are Smaller Than the Current Number Leetcode Solution226
447Find elements which are present in first array and not in second225
448Monotonic Array LeetCode Solution225
449Trapping Rain Water Leetcode Solution225
450Reverse a Stack Using Recursion225
451Integer to English words225
452Find the Difference Leetcode Solution224
453Find The Duplicate Number224
454Text Justification LeetCode Solution224
455Target Sum223
456Pair with given product223
457Fibonacci Number LeetCode Solution223
458Subarrays with distinct elements223
459Subarray Sum Equals K LeetCode Solution223
460Edit Distance223
461Valid Parenthesis String223
462Sum of Subarray Ranges Leetcode Solution223
463Subtract the Product and Sum of Digits of an Integer Leetcode Solution223
464Reverse Vowels of a String Leetcode Solution223
465Priority Queue Using Singly Linked List223
466Best Time to Buy and Sell Stock III Leetcode Solution222
467Floyd Warshall Algorithm222
468Find Index of Closing Bracket for a Given Opening Bracket in an Expression222
469Find distinct elements common to all rows of a matrix221
470Remove Duplicates from Sorted Array Leetcode Solution221
471Kth largest element in an Array Leetcode Solutions221
472Longest subarray not having more than K distinct elements221
473Reverse a String221
474Count and Say221
475Generate a String With Characters That Have Odd Counts Leetcode Solution220
476Longest Common Prefix using Trie220
477The K Weakest Rows in a Matrix Leetcode Solution220
478Design Parking System Leetcode Solution220
479Find Minimum In Rotated Sorted Array219
480Delete a Node from linked list without head pointer219
481Find Common Characters Leetcode Solution219
482Intersection of Two Arrays219
483Find four elements that sum to a given value (Hashmap)219
484Jump Game Leetcode Solution219
485Multiply Strings Leetcode Solution218
486Flood Fill LeetCode218
487Check if a given array contains duplicate elements within k distance from each other218
488Shuffle String Leetcode Solution218
489MiniMax Algorithm218
490Top View of Binary Tree218
491Count number of triplets with product equal to given number218
492Find any one of the multiple repeating elements in read only array218
493Prefix to Postfix Conversion218
494Rearrange a binary string as alternate x and y occurrences218
495Shuffle the Array Leetcode Solution217
496The Stock Span Problem217
497Shortest Palindrome217
498Word Ladder LeetCode Solution217
499Find missing elements of a range217
500Substring With Concatenation Of All Words217
501Iterative Tower of Hanoi216
502Balanced Binary Tree Leetcode Solution216
503Iterative Inorder Traversal of a Binary Tree216
504Next Greater Element I Leetcode Solution216
505Excel Sheet Column Number Leetcode Solution216
506Move Zeroes LeetCode Solution215
507Best Time to Buy and Sell Stock LeetCode Solution215
508Sorting a Queue without Extra Space215
509Degree of an array215
510Find subarray with given sum (Handles Negative Numbers)215
511Merge Two Sorted Linked Lists215
512Number of Steps to Reduce a Number to Zero Leetcode Solution215
513K-th Distinct Element in an Array214
514Check for Balanced Parentheses in an Expression214
516Priority Queue in C++214
517Reverse Words in a String III LeetCode Solution214
518Valid Sudoku214
519Slowest Key Leetcode Solution214
520Longest Common Subsequence214
521Count and Say Leetcode Solution214
522Peak Index in a Mountain Array214
523Kids With the Greatest Number of Candies Leetcode Solution214
524Longest Common Prefix using Sorting214
525Concatenation of Array LeetCode Solution214
526Minimum Knight Moves LeetCode Solution213
527Merge Overlapping Intervals213
528Find First and Last Position of Element in Sorted Array Leetcode Solution213
529Kth Largest Element in a Stream Leetcode Solution213
530Implement a stack using single queue213
531Find the Duplicate Element213
532Implement Stack using Queues213
533Max Area of Island213
534Sum of Left Leaves Leetcode Solutions212
535Minimum Moves to Equal Array Elements Leetcode Solution212
536Minimum Delete Operations to make all Elements of Array Same212
537Jewels and Stones Leetcode Solution212
538Largest Sum Contiguous Subarray212
539Largest Perimeter Triangle Leetcode Solution211
540Convert array into Zig-Zag fashion211
541Container with Most Water211
542Gold Mine Problem211
543Postfix to Prefix Conversion211
544Smallest Subarray With all Occurrences of a Most Frequent Element210
545Is Subsequence Leetcode Solution210
546Next Greater Frequency Element210
547Find N Unique Integers Sum up to Zero Leetcode Solution210
548Isomorphic Strings Leetcode Solution210
549Excel Sheet Column Title Leetcode Solution210
550Change the Array into Permutation of Numbers From 1 to N210
551Zigzag Conversion LeetCode Solution209
552Last Stone Weight209
553Linked List Cycle II LeetCode Solution209
554Arrange given numbers to form the biggest number209
555Hamming Distance209
556Minimum Bracket Reversals209
557Contiguous Array Leetcode209
558Delete Node in a Linked List Leetcode Solution209
559Maximum sum rectangle in a 2D matrix208
560Mobile Numeric Keypad Problem208
561How to check if two given sets are disjoint?208
562Check if a queue can be sorted into another queue using a stack208
563Find Sum of all unique sub-array sum for a given array208
564Koko Eating Bananas Leetcode Solution208
565Shuffle an Array208
566Group Multiple Occurrence of Array Elements Ordered by first Occurrence208
567Distribute Candies to People Leetcode Solution208
568Summary Ranges Leetcode Solution208
569Count the number of nodes at given level in a tree using BFS207
570Minimum Cost to Hire K Workers207
571Convert a normal BST to Balanced BST207
572Implementation of Deque using circular array206
573Length of Last Word Leetcode Solution206
5743Sum Closest LeetCode Solution206
575Best Time to Buy and Sell Stock206
576Shortest Path in a Grid with Obstacles Elimination LeetCode Solution206
577Rotate Image LeetCode Solution205
578First negative integer in every window of size k205
579Valid Anagrams205
580Number of Provinces Leetcode Solution205
581Find Words That Can Be Formed by Characters Leetcode Solution205
582Maximum path sum in a triangle205
583Trapping Rain Water LeetCode Solution205
584Maximum Distance in Array205
585Integer to Roman205
586LRU Cache LeetCode Solution204
587Frog Jump Leetcode Solution204
588N-th Tribonacci Number Leetcode Solution204
589Remove All Occurrences of a Substring LeetCode Solution204
590Minimum number of subsets with distinct elements204
59101 Matrix LeetCode Solution204
592Decode Ways204
593Find if an Expression has Duplicate Parenthesis or Not204
594Relative Sort Array Leetcode Solution204
595Longest Increasing Subsequence203
596Delete consecutive same words in a sequence203
597Maximum Number of Occurrences of a Substring Leetcode Solution203
598Minimum Operations to convert X to Y203
599Combinations Leetcode Solution203
600Build Array From Permutation Leetcode Solution203
601Island Perimeter Leetcode Solution203
602Word Pattern203
603Maximum difference between first and last indexes of an element in array202
604Sort Characters By Frequency LeetCode Solution202
605Minimum number of distinct elements after removing m items202
606Iterative Method to find Height of Binary Tree202
607Sieve of Eratosthenes202
608Remove Linked List Elements Leetcode Solution201
609Smallest Good Base201
610Insert Interval Leetcode Solution201
611Convert Sorted Array to Binary Search Tree Leetcode Solution201
612Assign Cookies Leetcode Solution201
613Non-overlapping sum of two sets201
614GCD Of Two Numbers201
615Tracking current Maximum Element in a Stack200
616Rotate List Leetcode Solution200
617The Knapsack Problem200
618Find minimum difference between any two elements200
619Minimum insertions to form a palindrome with permutations allowed200
620Count all subsequences having product less than K200
621Same Tree LeetCode Solution200
622Find the smallest positive integer value that cannot be represented as sum of any subset of a given array200
623XOR Operation in an Array Leetcode Solution200
624Find the Duplicate Number LeetCode Solution199
625Sum of f(a[i], a[j]) over all pairs in an array of n integers199
626Bubble sort using two Stacks199
627Reverse a stack without using extra space in O(n)199
628Permutation in String Leetcode Solution199
629Stone Game LeetCode198
630Unique Binary Search Trees198
631Printing brackets in Matrix Chain Multiplication Problem198
632Applications of Breadth First Search and Depth First Search198
633Count Good Nodes in Binary Tree Leetcode Solution198
634Isomorphic Strings198
635Optimal Account Balancing LeetCode Solution198
636Longest Increasing Path in a Matrix LeetCode Solution197
637Distance Between Bus Stops Leetcode Solution197
638Maximum Number of Chocolates to be Distributed Equally Among k Students197
639Defanging an IP Address Leetcode Solution197
640Reorganize String197
641Letter Combinations of a Phone Number197
642How to Create Mergable Stack?197
643First Unique Character in a String LeetCode Solution196
644Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions196
645Replace Elements with Greatest Element on Right Side Leetcode Solution196
646Find Largest d in Array such that a + b + c = d196
647Employee Free Time LeetCode Solution196
648K Empty Slots196
649License Key Formatting Leetcode Solution195
650Robot Room Cleaner Leetcode Solution195
651Form minimum number from given sequence195
652Reducing Dishes LeetCode Solution195
653Word Wrap Problem195
654Check If It Is a Straight Line Leetcode Solution195
655Strobogrammatic Number LeetCode Solution195
656Find pairs with given sum such that elements of pair are in different rows195
657Convert an array to reduced form195
658House Robber195
659Minimum Depth of Binary Tree Leetcode Solution195
660Sort Array By Parity LeetCode Solution195
661Painting Fence Algorithm194
662Kth Missing Positive Number Leetcode Solution194
663Merge Two Balanced Binary Search Trees194
664Find Pair with Greatest Product in Array194
665Partition Labels LeetCode Solution193
666Longest Substring with At Least K Repeating Characters LeetCode Solution193
667Valid Palindrome II Leetcode Solution193
668K Empty Slots LeetCode193
669Maximum Product of Two Elements in an Array Leetcode Solution193
670Moving Average from Data Stream Leetcode Solution192
671Longest Substring with At Most K Distinct Characters LeetCode Solution192
672Print the Fibonacci numbers in reverse order192
673String to Integer (atoi) LeetCode Solution192
674Maximum Consecutive Numbers Present in an Array192
675Power of Four Leetcode Solution192
676Segregate 0s and 1s in an Array192
677Convert a Number to Hexadecimal Leetcode Solution192
678Queries for counts of array elements with values in given range191
679Find the Distance Value Between Two Arrays Leetcode Solution191
680Best Time to Buy and Sell Stock with Cooldown Leetcode Solution191
681Reservoir Sampling191
682Remove Invalid Parentheses Leetcode Solution191
683Dynamic Programming Basics191
684Find Maximum Level sum in Binary Tree191
685Partition Array Into Three Parts With Equal Sum Leetcode Solution191
686Largest subarray with equal number of 0s and 1s191
687Check If Two String Arrays are Equivalent Leetcode Solution191
688Coin Change Problem191
689Distance of nearest cell having 1 in a binary matrix191
690Valid Palindrome191
691To Lower Case Leetcode Solution190
692Find unique character in a string190
693Longest Span with same Sum in two Binary arrays190
694Sum of All Odd Length Subarrays Leetcode Solution190
695Inorder Successor of a node in Binary Tree190
696Binary Tree Maximum Path Sum LeetCode Solution190
697Flipping an Image LeetCode Solution190
698String Compression LeetCode Solution190
699Find the node with minimum value in a Binary Search Tree190
700Path With Maximum Minimum Value LeetCode Solution190
701Find the largest multiple of 3190
702Wiggle Sort190
703Find Leaves of Binary Tree LeetCode Solution190
704Numbers with prime frequencies greater than or equal to k189
705Number of Dice Rolls With Target Sum LeetCode Solution189
706Find the Smallest Divisor given a Threshold Leetcode Solution189
707Maximum Number of Coins You Can Get Leetcode Solution189
708Increasing Decreasing String Leetcode Solution189
709Unique Paths II Leetcode Solution189
710Race Car LeetCode Solution188
711Non-decreasing Array LeetCode Solution188
712Permutation Sequence LeetCode Solution188
713Sort Array by Increasing Frequency Leetcode Solution188
714Edit Distance LeetCode Solution188
715Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest188
716Generate all possible sorted arrays from alternate elements of two given sorted arrays188
717Reverse Only Letters LeetCode Solution188
718Majority Element II Leetcode Solution187
719Reversing a Queue using Recursion187
720BFS vs DFS for Binary Tree187
721Bulb Switcher LeetCode Solution187
722Factorial Trailing Zeroes Leetcode Solution187
723Subset Sum Leetcode187
724Delete Nth node from the end of the given linked list187
725Lucky Numbers in a Matrix Leetcode Solution187
726Valid Perfect Square Leetcode Solution187
727Find Maximum Depth of Nested Parenthesis in a String187
728Binary Tree Zigzag Level Order Traversal LeetCode Solution186
729Find whether an array is subset of another array186
730Keyboard Row Leetcode Solution186
731Stack Permutations (Check if an array is stack permutation of other)186
732Ugly Number Leetcode Solution186
733Recover Binary Search Tree186
734Merge Two Binary Trees LeetCode Solution186
735Count quadruples from four sorted arrays whose sum is equal to a given value x186
736Maximum Length of a Concatenated String with Unique Characters Leetcode Solution186
737Snakes and Ladders LeetCode Solution186
738Perform String Shifts Leetcode185
739Number of NGEs to the Right185
740Maximum 69 Number Leetcode Solution185
741Find if Path Exists in Graph Leetcode Solution185
742Minimum Cost For Tickets Leetcode Solution185
743Morris Traversal185
744Valid Number185
745Print a Binary Tree in Vertical Order185
746Restore IP Addresses Leetcode Solution185
747Finding K closest element185
748Rank Transform of an Array Leetcode Solution185
749Base 7 Leetcode Solution185
750Elements to be added so that all elements of a range are present in array185
751Remove brackets from an algebraic string containing + and – operators185
752Tiling Problem185
753k-th missing element in increasing sequence which is not present in a given sequence185
754Populating Next Right Pointers in Each Node185
755Best Meeting Point LeetCode Solution185
756Find Median from Data Stream LeetCode Solution185
757Partition to K Equal Sum Subsets Leetcode Solution184
758Evaluate Reverse Polish Notation LeetCode Solution184
759N-Queens LeetCode Solution184
760Binary Tree zigzag level order Traversal184
761Find All Duplicates in an Array LeetCode Solution184
762String comparison containing wildcards184
763Split a String in Balanced Strings Leetcode Solution184
764Merge Sorted Array LeetCode Solution184
765Word Pattern LeetCode Solution184
766Check If Array Pairs Are Divisible by k LeetCode Solution184
767Maximum Profit in Job Scheduling Leetcode Solution184
768Check if Two Expressions With Brackets are Same184
769Student Attendance Record I Leetcode Solution184
770Regular Expression Matching183
771Construct BST from given Preorder Traversal183
772Brick Wall LeetCode Solution183
773Add and Search Word – Data structure design LeetCode183
774Program for Bridge and Torch problem183
775Special Array With X Elements Greater Than or Equal X Leetcode Solution183
776Symmetric Tree Leetcode Solution183
777Maximum Product of Three Numbers LeetCode Solution183
778Binomial Coefficient183
779Minimum Distance Between BST Nodes Leetcode Solution183
780Find All Possible Recipes from Given Supplies LeetCode Solution183
781Decompress Run-Length Encoded List Leetcode Solution182
782Growable array based stack182
783Maximum Depth of N-ary Tree Leetcode Solution182
784Largest Rectangle in Histogram LeetCode Solution182
785Hamming Distance Leetcode Solution182
786Merge K Sorted Linked Lists182
787Minimize Maximum Pair Sum in Array LeetCode Solution182
788Minimum Height Trees182
789Final Prices With a Special Discount in a Shop Leetcode Solution181
790Balanced Expression with Replacement181
791Top K Frequent Words LeetCode Solution181
792Invert Binary Tree LeetCode Solution181
793Form Minimum Number From Given Sequence181
794Kth ancestor of a node in binary tree181
795Jump Game181
796Search in a Binary Search Tree Leetcode Solution181
797Total Numbers With no Repeated Digits in a Range181
798Priority Queue using doubly linked list181
799Sorted Linked List to Balanced BST181
800Minimum Time Visiting All Points Leetcode Solution180
801Maximum Nesting Depth of the Parentheses Leetcode Solution180
802Identify and Mark Unmatched Parenthesis in an Expression180
803Diagonal Traversal of Binary Tree180
804Nested List Weight Sum II LeetCode Solution180
805Sort an array according to the order defined by another array180
806Minimum sum of multiplications of n numbers180
807Check for Palindrome after every character replacement Query180
808Maximum Difference Between Increasing Elements LeetCode Solution180
809Repeated Substring Pattern LeetCode Solution180
810One Edit Distance LeetCode Solution180
811Largest rectangular sub-matrix whose sum is 0180
812Number of Days Between Two Dates LeetCode Solution180
813Deletion in a Binary Tree179
814Longest Subarray Having Count of 1s One More than Count of 0s179
815Count items common to both the lists but with different prices179
816Nearest Exit from Entrance in Maze LeetCode Solution179
817Circular Queue179
818Relative Ranks Leetcode Solution179
819Minimum Swaps to Make Strings Equal Leetcode Solution179
820Remove Nth Node From End of List Leetcode Solution179
821Number of Islands II LeetCode Solution179
822Search a 2D Matrix II Leetcode Solution179
823Queue based approach for first non-repeating character in a stream179
824Crawler Log Folder Leetcode Solution179
825Linked List Cycle179
826Transpose Graph179
827Clone Graph LeetCode Solution178
828Course Schedule II – LeetCode178
829Minimum Number of Taps to Open to Water a Garden LeetCode Solution178
830Given an Array of Pairs Find all Symmetric Pairs in it178
831Subarray Product Less Than K LeetCode Solution178
832Number Complement Leetcode Solution177
833A Space Optimized DP solution for 0-1 Knapsack Problem177
834Minimum Jumps to Reach Home LeetCode Solution177
835Minimum time required to rot all oranges177
836Check if stack elements are pairwise consecutive177
837Binary Search Tree Search and Insertion177
838LCS (Longest Common Subsequence) of three strings177
839Distinct adjacent elements in an array177
840Check if an Array is Stack Sortable177
841Permutation Coefficient177
842Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution177
843Sort Array By Parity II Leetcode Solution177
844Reorder Data in Log Files LeetCode Solution176
845Sliding Window Maximum176
846Check if a given array can represent Preorder Traversal of Binary Search Tree176
847Split Array Into Consecutive Subsequences176
848Missing Element in Sorted Array LeetCode Solution176
849Design Browser History LeetCode Solution176
850Last Stone Weight II LeetCode Solution176
851Minimum number of jumps to reach end176
852Insert Delete GetRandom175
853Minimum Sum Path in a Triangle175
854Remove Duplicates from Sorted List II175
855Iterative Preorder Traversal175
856Remove Duplicates from Sorted List LeetCode Solution175
857Valid Parentheses Leetcode Solution175
858Tree Traversal (Preorder, Inorder & Postorder)175
859Find Maximum Sum Possible Equal Sum of Three Stacks175
860Alien Dictionary LeetCode Solution175
861Lemonade Change Leetcode Solution175
862Interval Tree175
863Partition List Leetcode Solution175
864Daily Temperatures Leetcode Solution174
865Subsequence of Size K With the Largest Even Sum LeetCode Solution174
866Spiral Matrix II Leetcode Solution174
867Can Place Flowers LeetCode Solution174
868Design a Stack With Increment Operation Leetcode Solution174
869Dividing Array into Pairs With Sum Divisible by K174
870Union and Intersection of two Linked Lists174
871Count Distinct Elements in Every Window of Size K174
872Sorted Array to Balanced BST173
873Water Bottles Leetcode Solution173
874Maximum size subarray sum equals k173
875Infix to Postfix173
876Guess Number Higher or Lower LeetCode Solution173
877An Interesting Method to generate Binary Numbers from 1 to n173
878Brightest Position on Street LeetCode Solution173
879Level order Traversal in Spiral Form173
880Get Maximum in Generated Array Leetcode Solution173
881Diagonal Traverse LeetCode Solution173
882Least Number of Unique Integers after K Removals Leetcode Solution173
883Find the Only Repetitive Element Between 1 to N-1173
884Subset with sum divisible by m173
885Minimum swaps to make sequences increasing173
886Find all permuted rows of a given row in a matrix173
887Minesweeper LeetCode Solution173
888Convert BST to Min Heap173
889Sum of nearest smaller and greater number173
890Sort Colors172
891Delete And Earn172
892GCDs of given index ranges in an array172
893Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i172
894Guess Number Higher or Lower II172
895Find all triplets with zero sum172
896Pattern Occurrences using Stack172
897Lexicographical Numbers Leetcode Solution172
898Sequences of given length where every element is more than or equal to twice of previous172
899Check whether a given Binary Tree is Complete or not172
900Count ways to reach the nth stair using step 1, 2 or 3172
901Friends Pairing Problem172
902Find the subarray with least average172
903Averages of Levels in Binary Tree171
904Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution171
905Shortest Word Distance Leetcode Solution171
906Number of Distinct Islands Leetcode Solution171
907Maximum Score After Splitting a String Leetcode Solution171
908Insert into a Binary Search Tree Leetcode Solution171
909A program to check if a binary tree is BST or not170
910Find distance between two nodes of a Binary Tree170
911Three way partitioning of an array around a given range170
912Count Negative Numbers in a Sorted Matrix LeetCode Solution170
913Time Based Key-Value Store LeetCode Solution170
914Rearrange Spaces Between Words Leetcode Solution170
915Check if any two intervals overlap among a given set of intervals170
916Range sum queries without updates170
917Check if the given array can represent Level Order Traversal of Binary Search Tree170
918Set Matrix Zeroes Leetcode Solution170
919Range LCM Queries170
920Path with maximum average value170
921My Calendar I LeetCode Solution170
922Matrix Chain Multiplication170
923All Unique Triplets that Sum up to a Given Value170
924Diagonal Traversal LeetCode Solution170
925Construct the Rectangle Leetcode Solution169
926Queue using Stacks169
927Difference Array | Range update query in O(1)169
928Iterative Postorder Traversal Using Two Stacks169
929Destination City Leetcode Solution169
930Count Submatrices With All Ones LeetCode Solution169
931Construct Complete Binary Tree from its Linked List Representation169
932Median of Two Sorted Arrays169
933Rearrange an Array Such that arr[i] is equal to i169
934Robot Bounded In Circle LeetCode Solution169
935Trim a Binary Search Tree169
936Alien Dictionary169
937Binary Tree Longest Consecutive Sequence LeetCode Solution169
938Intersection of Two Linked Lists LeetCode Solution168
939Maximum Frequency Stack Leetcode Solution168
940Convert Sorted List to Binary Search Tree168
941Binary array after M range toggle operations168
942Spiral Matrix III LeetCode Solution168
943Find Common Characters Leetcode Solution168
944Product of Array Except Self LeetCode Solution168
945Strongly Connected Component168
946Largest area rectangular sub-matrix with equal number of 1’s and 0’s168
947Number of Equivalent Domino Pairs Leetcode Solution168
948Word Break167
949Create Maximum Number167
950Climbing stairs167
951Kth Smallest Element in a BST Leetcode Solution167
9523 Sum167
953Three Consecutive Odds Leetcode Solution167
954Palindrome Partitioning Leetcode Solution167
955Remove Duplicates from Sorted List II LeetCode Solution167
956Analyze User Website Visit Pattern LeetCode Solution167
957Construct BST from its given Level Order Traversal167
958Longest subsequence such that difference between adjacents is one166
959Count Subarrays with Same Even and Odd Elements166
960Special Positions in a Binary Matrix Leetcode Solution166
961Sign of the Product of an Array LeetCode Solution166
962Vertical sum in a given binary tree166
963BFS for Disconnected Graph166
964Queries for GCD of all numbers of an array except elements in a given range166
965Merge Two Sorted Lists Leetcode166
966K’th Largest Element in BST when modification to BST is not allowed166
967Combination Sum IV LeetCode Solution166
968Unique Paths II165
969Design Hit Counter LeetCode Solution165
970Minimum Height Trees LeetCode Solution165
971Reverse Nodes in K-Group165
972Count pair with Given Sum165
973Longest Palindromic Subsequence165
975Breadth First Search (BFS) for a Graph165
976Merging Intervals165
977Count subarrays where second highest lie before highest164
978Maximize Sum of Array after K Negations Leetcode Solution164
979Count Primes in Ranges164
980Maximum Product of Indexes of Next Greater on Left and Right164
981Valid Boomerang Leetcode Solution164
982Depth First Search (DFS) for a Graph164
983Stone Game II Leetcode164
984Asteroid Collision LeetCode Solution164
985The Maze III LeetCode Solution164
986Find Maximum of Minimum for Every Window Size in a Given Array164
987Maximum Product Subarray164
988Largest Number Leetcode Solution164
989Serialize and Deserialize Binary Tree163
990Number of palindromic paths in a matrix163
991Symmetric Tree163
992Print Fibonacci sequence using 2 variables163
993Next Permutation Leetcode Solution163
994Consecutive Characters LeetCode Solution163
995Can Make Arithmetic Progression From Sequence Leetcode Solution163
996Longest Nice Substring LeetCode Solution163
997String Matching in an Array Leetcode Solution162
998Find number of pairs in an array such that their XOR is 0162
999Maximum Length of Repeated Subarray162
1000Kth Smallest Element in a Sorted Matrix LeetCode Solution162
1001Maximum Subarray Sum Excluding Certain Elements162
1002Palindrome Partitioning162
1003Level Order Traversal of Binary Tree162
1004Validate Binary Search Tree162
1005K Closest Points to Origin Leetcode Solution162
1006Minimum Index Sum of Two Lists162
1007Binary Search Tree Delete Operation162
1008Graph Valid Tree LeetCode Solution161
1009Newman-Conway Sequence161
1010Height of a generic tree from parent array161
1011Scramble String LeetCode Solution161
1012Length of Longest Fibonacci Subsequence161
1013Segment Tree161
1014Count pairs from two sorted arrays whose sum is equal to a given value x161
1015Decrypt String from Alphabet to Integer Mapping Leetcode Solution161
1016Find the Difference Leetcode Solution161
1017Collect maximum points in a grid using two traversals161
1018Balanced Binary Tree161
1019Largest divisible pairs subset161
1020Find Duplicate Subtrees161
1021Merge Sort161
1022Maximum difference between frequency of two elements such that element having greater frequency is also greater161
1023Shuffle 2n integers as without using extra space161
1024Insertion in a Binary Tree160
1025Find the First Circular Tour that visits all the Petrol Pumps160
1026Binary Search Tree160
1027Find postorder traversal of BST from preorder traversal160
1028First missing positive160
1029K maximum sums of overlapping contiguous sub-arrays160
1030The Painter’s Partition Problem160
1031Maximum Sum of 3 Non-Overlapping Subarrays160
1032Print Next Greater Number of Q queries160
1033Generate Parentheses Leetcode Solution160
1034Maximum Number of Ways to Partition an Array LeetCode Solution160
1035Number Of Longest Increasing Subsequence160
1036Construct Binary Tree from given Parent Array representation159
1037Advantages of BST over Hash Table159
1038Construction of Longest Increasing Subsequence (N log N)159
1039Custom Sort String Leetcode Solution159
1040Available Captures for Rook Leetcode Solution159
1041Invalid Transactions LeetCode Solution159
1042Largest Substring Between Two Equal Characters Leetcode Solution159
1043Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’159
1044Compute nCr % p159
1045Make The String Great Leetcode Solution159
1046Next Greater Element III LeetCode Solution159
1047Move all negative elements to end in order with extra space allowed159
1048Shortest Completing Word Leetcode Solution159
1049Friends Of Appropriate Ages LeetCode Solution159
1050Kill Process LeetCode Solution158
1051Count minimum steps to get the given desired array158
1052Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution158
1053Maximum length subsequence with difference between adjacent elements as either 0 or 1158
1054Iterative Depth First Traversal of Graph158
1055Boolean Parenthesization Problem158
1056Rearrange array such that even positioned are greater than odd158
1057Path Sum II LeetCode Solution158
1058Boundary Traversal of binary tree158
1059Remove Duplicates from Sorted Array II Leetcode Solution157
1060Rearrange array such that even index elements are smaller and odd index elements are greater157
1061Recover Binary Search Tree Leetcode Solution157
1062Defanging an IP Address LeetCode Solution157
1063Build an Array With Stack Operations Leetcode Solution157
1064Double the first element and move zero to end157
1065Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution157
1066Maximum subsequence sum such that no three are consecutive157
1067Find a Peak Element II LeetCode Solution157
1068Bitwise AND of Numbers Range LeetCode Solution157
1069Level order traversal using two Queues157
1070Subarrays with K Different Integers Leetcode Solution156
1071Palindrome Permutation LeetCode Solution156
1072Smallest Common Region Leetcode Solution156
1073Employee Importance LeetCode Solution155
1074Binary Tree Right Side View LeetCode Solution155
1075Remove Palindromic Subsequences Leetcode Solution155
1076Ugly Numbers155
1077Morris Inorder Traversal155
1078Partition Equal Subset Sum155
1079Number of Closed Islands Leetcode Solution155
1080Regular Expression Matching Regular Expression Matching LeetCode Solution155
1081Super Ugly Number155
1082Maximum weight transformation of a given string155
1083Lowest Common Ancestor155
1084Find Peak Element155
1085Implement Trie (Prefix Tree) Leetcode Solution154
1086Bus Routes Leetcode Solution154
1087Find maximum difference between nearest left and right smaller elements154
1088Ugly Number II LeetCode Solution154
1089Add two numbers154
1090Valid Tic-Tac-Toe State LeetCode Solution154
1091Remove duplicates from sorted array154
1092Populating Next Right Pointers in Each Node Leetcode Solution154
1093Minimum Size Subarray Sum154
1094Maximize Distance to Closest Person LeetCode Solution154
1095Largest BST Subtree LeetCode Solution154
1096Palindromic Substrings Leetcode Solution154
1097Print Right View of a Binary Tree154
1098Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution153
1099Binary Tree Data Structure153
1100Increasing Triplet Subsequence LeetCode Solution153
1101Divisible Pairs Counting153
1102Number of siblings of a given Node in n-ary Tree152
1103Find whether a subarray is in form of a mountain or not152
1104Search in Sorted Rotated Array152
1105Print all triplets in sorted array that form AP152
1106Find the minimum distance between two numbers152
1107Path Sum152
1108Reformat The String Leetcode Solution152
1109Root to Leaf path with target sum Leetcode Solutions151
1110Number of Students Doing Homework at a Given Time Leetcode Solution151
1111Cells with Odd Values in a Matrix LeetCode Solution151
1112Find Three Element From Different Three Arrays Such That a + b + c = sum151
1113Iterative method to find ancestors of a given binary tree151
1114Kth Smallest Product of Two Sorted Arrays LeetCode Solution151
1115Search Insert Position151
1116Count Largest Group Leetcode Solution151
1117Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution150
1118Products of ranges in an array150
1119Prime Palindrome LeetCode Solution150
1120Distinct Subsequences150
1121Find Smallest Range Containing Elements from k Lists150
1122Day of the Year Leetcode Solution150
1123Longest Bitonic Subsequence150
1124Moser-de Bruijn Sequence150
1125Level of Each node in a Tree from source node150
1126Serialize and Deserialize Binary Tree LeetCode Solution150
1127Convert BST into a Min-Heap without using array149
1128Minimum Absolute Difference in BST Leetcode Solution149
1129Thousand Separator Leetcode Solution149
1130Bottom View of a Binary Tree149
1131Maximum Product Subarray149
1132Longest Increasing Consecutive Subsequence149
1133Longest Repeated Subsequence149
1134Construct K Palindrome Strings LeetCode Solution149
1135Topological Sorting148
1136Clone a Binary Tree with Random Pointers148
1137Rotate Array148
1138Constant time range add operation on an array148
1139Sum of Even Numbers After Queries148
1140Mean of Array After Removing Some Elements Leetcode Solution148
1141Maximum Depth Of Binary Tree148
1142Subset Sum Problem in O(sum) space147
1143Longest Subarray of 1’s After Deleting One Element LeetCode Solution147
1144Queries for Number of Distinct Elements in a Subarray147
1145Web Crawler LeetCode Solution147
1146Priority Queue147
1147Cutting a Rod147
1148Find maximum length Snake sequence147
1149Closest Binary Search Tree Value Leetcode Solution147
1150Minimum Score Triangulation of Polygon Leetcode Solution147
1151Search an Element in Sorted Rotated Array146
1152Delete Nodes and Return Forest Leetcode Solution146
1153Compare Strings by Frequency of the Smallest Character Leetcode Solution146
1154Search Suggestions System LeetCode Solution146
1155Print modified array after executing the commands of addition and subtraction146
1156Diameter of N-Ary Tree LeetCode Solution146
1157Minimum Cost to Move Chips to The Same Position LeetCode Solution146
1158Write Code to Determine if Two Trees are Identical146
1159Swap Nodes In Pairs146
1160Find a sorted subsequence of size 3 in linear time145
1161Count even length binary sequences with same sum of first and second half bits145
1162Decision Tree145
1163Possible Bipartition LeetCode Solution145
1164Minimum Moves to Equal Array Elements LeetCode Solution145
1165Minimum sum of squares of character counts in a given string after removing k characters145
1166Maximum Product of Splitted Binary Tree LeetCode Solution145
1167Third Maximum Number Leetcode Solution145
1168Find the smallest binary digit multiple of given number144
1169Minimum Swaps To Make Sequences Increasing LeetCode Solution144
1170Red-Black Tree Introduction144
1171Closest Leaf in a Binary Tree LeetCode Solution144
1172Find Largest Value in Each Tree Row LeetCode Solution144
1173Transform a BST to Greater sum Tree144
1174Kth Smallest Number in Multiplication Table Leetcode Solution144
1175Binary Tree to Binary Search Tree Conversion144
1176Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution144
1177Minimum Sideway Jumps LeetCode Solution144
1178Count Pairs Whose Products Exist in Array144
1179Reformat Date LeetCode Solution144
1180Golomb sequence144
1181Maximum Value at a Given Index in a Bounded Array LeetCode Solution143
1182Reverse a Path in BST using Queue143
1183Matchsticks to Square Leetcode Solution143
1184Maximize sum of consecutive differences in a circular array143
1185Contiguous Array LeetCode Solution143
1186Replace two consecutive equal values with one greater143
1187Sum of Left Leaves LeetCode Solution143
1188Merge two BSTs with limited extra space143
1189Perfect Squares LeetCode Solution143
1190K’th Largest element in BST using constant extra space143
1191Divide Two Integers Leetcode Solution142
1192Convert Sorted Array to Binary Search Tree LeetCode Solutions142
1193Check Array Formation Through Concatenation Leetcode Solution142
1194Queue Reconstruction by Height142
1195Maximum number of segments of lengths a, b and c142
1196Decrease Elements To Make Array Zigzag LeetCode Solution142
1197First Bad Version142
1198Given a binary tree, how do you remove all the half nodes?142
1199Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution142
1200Factorial Trailing Zeroes LeetCode Solution142
1201Path Crossing Leetcode Solution142
1202Swapping Nodes in a Linked List Leetcode Solution141
1203Number of Orders in the Backlog Leetcode Solution141
1204Concatenation of Array LeetCode Solution141
1205Valid Triangle Number141
1206Valid Perfect Square LeetCode Solution141
1207Maximum Binary Tree141
1208New 21 Game140
1209Kth Smallest Element in a BST140
1210Sliding Window Median Leetcode Solution140
1211Lowest Common Ancestor of a Binary Tree Leetcode Solution140
1212Champagne Tower LeetCode Solution140
1213Maximum sum of pairs with specific difference140
1214Maximum sum bitonic subarray140
1215Print n terms of Newman-Conway Sequence139
1216Guess The Word139
1217Integer Break LeetCode Solution139
1218How to print maximum number of A’s using given four keys139
1219Flatten 2D Vector LeetCode Solution139
1220Find minimum number of merge operations to make an array palindrome138
1221Graph and its representation138
1222Array Queries for multiply replacements and product138
1223Queries on Probability of Even or Odd Number in given Ranges138
1224Merge k Sorted Lists Leetcode Solution138
1225Lowest Common Ancestor in Binary Search Tree138
1226Longest Common Prefix Using Word by Word Matching138
1227Design Skiplist LeetCode Solution137
1228Maximum Sum Increasing Subsequence137
1229Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution137
1230Maximum sum of a path in a Right Number Triangle137
1231Moving Stones Until Consecutive Leetcode Solution137
1232Missing Number137
1233Find Minimum in Rotated Sorted Array II LeetCode Solution137
1234LRU Cache Leetcode Solution137
1235Check if all levels of two Binary Tree are anagrams or not137
1236Maximize Elements Using Another Array136
1237Maximum Product Subarray136
1238Range Queries for Longest Correct Bracket Subsequence136
1239Largest Plus Sign Leetcode Solution136
1240Range Sum Query using Sparse Table136
1241Maximum Array from Two given Arrays Keeping Order Same136
1242Mean of range in array136
1243Print modified array after multiple array range increment operations135
1244The kth Factor of n Leetcode Solution135
1245BST to a Tree with Sum of all Smaller Keys135
1246Contiguous Array135
1247Count Subsets Having Distinct Even Numbers135
1248Min Cost Climbing Stairs LeetCode Solution134
1249Graph Cloning134
1250Power of Two134
1251Write a function to get the intersection point of two Linked Lists134
1252Find k-th smallest element in BST (Order Statistics in BST)134
1253Arithmetic Slices II – Subsequence LeetCode Solution134
1254Check in binary array the number represented by a subarray is odd or even133
1255Minimum Remove to Make Valid Parentheses LeetCode Solution133
1256Check if each internal node of a BST has exactly one child133
1257Bold Words in String LeetCode Solution133
1258Different Ways to Add Parentheses Leetcode Solution133
1259Parallel Courses II LeetCode Solution133
1260Minimum Time to Collect All Apples in a Tree LeetCode Solution132
1261Check for Identical BSTs without building the trees132
1262Check Completeness of a Binary Tree LeetCode Solution132
1263Check if two nodes are on the same path in a Tree132
1264Image Overlap LeetCode Solution132
1265Smallest Range II Leetcode Solution131
1266Symmetric Tree LeetCode Solution Leetcode Solution131
1267Print Ancestors of a Given Binary Tree Node Without Recursion131
1268Verify Preorder Serialization of a Binary Tree131
1269Koko Eating Bananas LeetCode Solution130
1270Arranging Coins Leetcode Solution129
1271Excel Sheet Column Title LeetCode Solution129
1272Merge Sorted Array129
1273Orderly Queue LeetCode Solution129
1274Next greater element128
1275Vertical Order Traversal of Binary Tree LeetCode Solution128
1276Number of elements less than or equal to a given number in a given subarray127
1277Longest Substring Without Repeating Characters Leetcode Solution127
1278Array Nesting Leetcode Solution127
1279Count and Toggle Queries on a Binary Array126
1280Check If a String Can Break Another String Leetcode Solution126
1281Palindrome Partitioning126
1282Palindrome Number LeetCode Solution125
1283Add Two Numbers II Leetcode Solution125
1284Insert Delete GetRandom O(1) Leetcode Solution125
1285Largest Submatrix With Rearrangements LeetCode Solution124
1286Check if X can give change to every person in the Queue124
1287Newman–Shanks–Williams prime124
1288Peeking Iterator LeetCode Solution124
1289Find the Winner of the Circular Game LeetCode Solution123
1290Queries for Decimal Values of Subarrays of a Binary Array123
1291Find maximum average subarray of k length123
1292Maximum product of an increasing subsequence123
1293Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution122
1294Range Minimum Query (Square Root Decomposition and Sparse Table)122
1295Encoded String With Shortest Length LeetCode Solution121
1296Check given array of size n can represent BST of n levels or not120
1297Continuous Subarray Sum LeetCode Solution120
1298Jump Game IV LeetCode Solution119
1299Reach a Number LeetCode Solution119
1300Random Pick Index LeetCode Solution118
1301Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution118
1302Binary Tree to Binary Search Tree Conversion using STL set118
1303Number of indexes with equal elements in given range117
1304Convert a BST to a Binary Tree such that sum of all greater keys is added to every key117
1305Minimum Number of People to Teach LeetCode Solution116
1306Convert to Base -2 LeetCode Solution116
1307Minimum Total Space Wasted With K Resizing Operations LeetCode Solution115
1308Design A Leaderboard Leetcode Solution115
1309Design Underground System Leetcode Solution114
1310Shifting Letters LeetCode Solution112
1311Queries on XOR of greatest odd divisor of the range112
1312Print Maximum Length Chain of Pairs110
1313Minimum Swaps to Group All 1’s Together Leetcode Solution110
1314Top K Frequent Elements LeetCode Solution108
1315Detect Capital Leetcode Solution108
1316Minimum Path Sum Leetcode Solution107
1317Count Sub Islands LeetCode Solution106
1318Monotonic Array Leetcode Solution105
1319Odd Even Linked List Leetcode Solution104
1320Substring with Concatenation of All Words Leetcode Solution104
1321Longest Common Subsequence LeetCode Solution102
1322Binary Tree Inorder Traversal LeetCode Solution101
1323Decode String Leetcode Solution101
1324Maximum Population Year LeetCode Solution99
1325Find the Town Judge LeetCode Solution99
1326Best Meeting Point LeetCode Solution94
1327Shortest Unsorted Continuous Subarray LeetCode Solution94
1328Rectangle Overlap LeetCode Solution93
1329Maximum Population Year LeetCode Solution92
1330Find the Town Judge LeetCode Solution91
1331Flatten Binary Tree to Linked List LeetCode Solution89
1332Design Add and Search Words Data Structure LeetCode Solution89
1333Sum Root to Leaf Numbers LeetCode Solution88
1334Is Graph Bipartite? LeetCode Solution86
1335Insert into a Sorted Circular Linked List LeetCode Solution86
1336Range Sum Query 2D – Immutable LeetCode Solution86
1337Stone Game IV LeetCode Solution86
1338Valid Triangle Number LeetCode Solution86
1339Reveal Cards In Increasing Order Leetcode Solution85
1340Score of Parenthesis LeetCode Solution84
1341Divide Chocolate LeetCode Solution80
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution75
1343Range Sum of BST LeetCode Solution68
1344Reverse Integer Leetcode Solution66
1345Find K Closest Elements LeetCode Solution64
1346Rotate String LeetCode Solution64
1347Sort Colors LeetCode Solution63
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution61
1349Excel Sheet Column Number LeetCode Solution56
1350Maximum Size Subarray Sum Equals k Leetcode Solution49
1351Camelcase Matching Leetcode Solution45
1352H-Index Leetcode Solution44
1353Valid Anagram Leetcode Solution44
1354Most Stones Removed with Same Row or Column LeetCode Solution43
1355Sliding Window Maximum LeetCode Solution42
1356Container With Most Water LeetCode Solution42
1357Group Anagrams LeetCode Solution41
1358Next Permutation LeetCode Solution41
1359High Five LeetCode Solution41
1360Find Peak Element LeetCode Solution40
1361Binary Search LeetCode Solution40
1362Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution37
1363Paint House LeetCode Solution37
1364Valid Triangle Number LeetCode Solution35
1365Unique Binary Search Trees LeetCode Solution34
1366Flatten Binary Tree to Linked List LeetCode Solution34
1367Minimum Number of Arrows to Burst Balloons LeetCode Solution34
1368Next Greater Element I Leetcode Solution34
1369Group Shifted Strings Leetcode Solution34
1370Sentence Screen Fitting LeetCode Solution33
1371Count Good Nodes in Binary Tree LeetCode Solution32
1372Isomorphic Strings LeetCode Solution32
1373Closest Binary Search Tree Value II LeetCode Solution31
1374Swim in Rising Water LeetCode Solution31
1375Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution30
1376The Number of Weak Characters in the Game LeetCode Solution29
1377Peak Index in a Mountain Array LeetCode Solution29
1378Split Linked List in Parts Leetcode Solution27
1379Validate Stack Sequences LeetCode Solution26
1380Greatest Sum Divisible by Three LeetCode Solution24
1381Best Time to Buy and Sell Stock IV LeetCode Solution24
1382Implement strStr() LeetCode Solution23
1383All Possible Full Binary Trees LeetCode Solution23
1384Single Element in a Sorted Array LeetCode Solution23
1385Lowest Common Ancestor of a Binary Search Tree Leetcode Solution22
1386Implement Rand10() Using Rand7() Leetcode Solution22
1387Trapping Rain Water II LeetCode Solution21
1388Break a Palindrome LeetCode Solution21
1389Max Sum of Two Non-Overlapping Subarrays LeetCode Solution21
1390Stone Game IV LeetCode Solution20
1391Minimum Increment to Make Array Unique Leetcode Solution20
1392Contains Duplicate LeetCode Solution20
1393Remove All Ones With Row and Column Flips Leetcode Solution19
1394Find First and Last Position of Element in Sorted Array LeetCode Solution19
1395Detect Squares LeetCode Solution18
1396Reverse Nodes in k-Group LeetCode Solution17
1397Fibonacci Number LeetCode Solution16
1398Minimum Number of Operations to Move All Balls to Each Box LeetCode Solution16
1399Design Bounded Blocking Queue LeetCode Solution15
1400Total Hamming Distance LeetCode Solution14
1401Invert Binary Tree LeetCode Solution3
Translate »