Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution

Difficulty Level Medium
Frequently asked in Amazon Facebook Google Microsoft
String TreeViews 38

Problem Statement:

Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution – You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer destValue representing the value of the destination node t.

Find the shortest path starting from the node s and ending at the node t. Generate step-by-step directions of such path as a string consisting of only the uppercase letters 'L''R', and 'U'. Each letter indicates a specific direction:

  • 'L' means to go from a node to its left child node.
  • 'R' means to go from a node to its right child node.
  • 'U' means to go from a node to its parent node.

Return the step-by-step directions of the shortest path from the node s to node t.



Step-By-Step Directions From a Binary Tree Node to Another LeetCode SolutionPin

 root = [5,1,2,3,null,6,4], startValue = 3, destValue = 6




 The shortest path is: 3 → 1 → 5 → 2 → 6.



The idea is to first find the path of source and destination from the root. This can be done by a simple DFS traversal. Once we have the paths to the source and destination then we will be removing that part of the path which is common to both the source and destination. That is we only need the path of the source and destination when approached from their lowest common ancestor.

The length of the path to the source node will denote the number of up movements i.e., “U” we need to do in order to reach the lowest common ancestor. Once we get the count of this we can simply append the destination node path to this. This will be our final answer. Check out the C++ code for a better understanding,

Another method for solving this problem is to first generate a graph out of the tree and then simply do a BFS from the source until we reach the destination node. To create the graph we will be doing another BFS and will be storing the movement we did in order to reach a particular node, i.e., left or right and this thing will change to up when seen from the child node perspective. Check out the Python code for a better understanding.


Step-By-Step Directions From a Binary Tree Node to Another C++ Solution:

class Solution {
    bool dfs(TreeNode* root, int target, string &path){
        if(root->val == target){
            return true;
                return true;
                return true;
        return false;
    void removePrefix(string &s1,string &s2){
        int n1 = s1.length();
        int n2 = s2.length();
        int i=0;
        while(i<min(n1,n2) and s1[i]==s2[i])
        s1 = s1.substr(i);
        s2 = s2.substr(i);
    string getDirections(TreeNode* root, int startValue, int destValue) {
        string pathOne = "";
        string pathTwo = "";
        int n = pathOne.length();
        string s = "";
        for(int i=0;i<n;i++){
        s += pathTwo;
        return s;

Step-By-Step Directions From a Binary Tree Node to Another Python Solution:

class Solution:
    def getDirections(self, root: Optional[TreeNode], s: int, d: int) -> str:
        graph = collections.defaultdict(list)
        q = collections.deque([root])
        # create graph
        while q:
            node = q.popleft()
            if node.left:
            if node.right:
        q = collections.deque([(s,"")])
        vis = set()
        # BFS from source to destination 
        while q:
            for i in range(len(q)):
                top = q.popleft()
                for it in graph[top[0]]:
                    val = it[0]
                    dirs = it[1]
                    if val not in vis:
                         path = top[1]
                         path += dirs;
                         if val==d:
                            return path
        return ""

Complexity Analysis of Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution:

  • Time Complexity: The time complexity of the above C++ code is O(n).
  • Space Complexity: The space complexity of the above C++ code is O(n).

Top Interview Questions

S.No Interview Question Number of times has been asked
1Delete a node in doubly linked list2815
2Java program to find the number of Nodes in a Binary Tree2498
3Reverse a string without affecting special characters2453
4Delete a node of a linked list at given position1972
5Palindrome using Recursion1775
6Insert nodes in a linked list in a sorted way (Ascending Order)1656
7Find elements pair from array whose sum equal to number1644
8Sort Elements by Frequency of Occurrences1626
9Write a program to print all permutations of a given string1599
10Find Minimum Distance Between Two Numbers in an Array1470
11Create a Doubly Linked List1443
12Quick Sort1415
13Reverse an Array1408
14Smallest window in a string containing all characters of another string1393
15Find a Triplet That Sum to a Given Value1355
16Recursively remove all adjacent duplicates1351
17First Repeating Element1334
18Arrange Even and Odd number such that Odd comes after Even1318
19Sum of numbers in String1310
20Smallest Positive Number Missing in an Unsorted Array1277
21Check if the Elements of an Array are Consecutive1250
22Detect a loop in the Linked List1234
23Largest Sum Contiguous Subarray1228
24Quick Sort on SIngly Linked List1212
25Subarray with Given Sum1209
26Print all Possible Combinations of R Elements in a given Array of size N1201
27Recursive function to do substring search1195
28Find the Maximum Repeating Number in Array1149
29Binary Tree Level order traversal in Java1121
30Find the First and Second Smallest Elements1118
31Check if two linked lists are identical1100
32Maximum Subarray Sum using Divide and Conquer1098
33Remove characters from first string which are in second1065
34Find Leaders in an Array1057
35Swap nodes in the linked list1031
36Find the Number Occurring Odd Number of Times in an Array999
37Arrange given Numbers to Form the Biggest Number II991
38Find the second most frequent character983
39Given a string find its first non-repeating character962
40Find Triplet in Array With a Given Sum962
41Total number of occurrences of a given item in the linked list950
42Given a sorted array and a number x, find the pair in array whose sum is closest to x950
43A Program to check if strings are rotations of each other or not941
44Print all possible words from phone digits927
45Find the Missing Number922
46Rearrange Positive and Negative Numbers Alternatively in Array916
47Longest Palindromic Substring901
48Segregate even and odd nodes in a linked list880
49Print Longest common subsequence877
50Union and Intersection of Two Linked Lists870
51Transform one string to another using minimum number of given operations861
52Check rearranged string can form a palindrome841
53Rearrange given Array in Maximum Minimum Form841
54Count Possible Triangles818
55Iterative Implementation of Quick Sort813
56Multiplication of Two Matrices796
57Check if the linked list is palindrome792
58Count of Triplets With Sum Less than Given Value788
59Rotate a Linked List788
60Stock Buy Sell to Maximize Profit785
61Concatenation of two strings756
62Tug of War755
63Count Number of Substrings with K Distinct Character’s750
64Print all duplicates in the input string748
65Find Nearest Greater and Smaller Element743
66The Celebrity Problem735
67Find Pythagorean Triplets from Array735
68Reverse String Without Temporary Variable729
69Remove ‘b’ and ‘ac’ from a given string726
70Find all Common Elements in Given Three Sorted Arrays726
71Remove all duplicates in an unsorted linked list708
72Find the Row with Maximum Number of 1’s702
73Find the Peak Element from an Array696
74Find the subarray whose sum is equal to a given number X693
75Remove Minimum Characters so that Two Strings Become Anagrams685
76Insertion Sort685
77Find Smallest Missing Number in a Sorted Array684
78Addition of Two Matrices681
79A Product Array Puzzle681
80Implement Two Stacks in an Array674
81Generate all Binary Strings Without Consecutive 1’s670
82Maximum Sum of Non Consecutive Elements667
83Maximum Product Subarray II658
84Lexicographic rank of string651
85Multiplication of Previous and Next641
86Check if Two given Matrices are Identical641
87Merge K Sorted Arrays and Print Sorted Output631
88Subtraction of Two Matrices630
89Move All the Zeros to the End of the Given Array626
90Divide a string in N equal parts620
91Online Algorithm for Checking Palindrome in a Stream620
92Form Minimum Number from Given Sequence of D’s and I’s620
93Check whether two strings are anagram of each other611
94Maximum Circular Subarray Sum607
95Sort a linked list that is sorted alternating ascending and descending607
96Remove recurring digits in a given number607
97Sort a stack using a temporary stack603
98Find the Minimum Element in a Sorted and Rotated Array603
99Move last element of the Linked List at first place600
100Subarray and Subsequence597
101First Circular Tour to Visit all the Petrol Bunks596
102Largest Subarray with Equal Number of 0’s and 1’s592
103Compare two strings(linked lists)591
104Flattening a linked list589
105Maximum Element in an Array which is Increasing and then Decreasing588
106Palindrome Permutations of a String581
107Elements Appear more than N/K times in Array580
108Majority Element573
109Minimum insertions to form a shortest palindrome571
110Run length encoding571
111Print all permutations with repetition570
112Palindromes in a given range569
113Pangram Checking565
114Merge a linked list into another at alternate positions563
115Minimum Characters to be Added at Front to Make String Palindrome561
116Rearrange a given linked list in-place561
117Remove all duplicates in a sorted linked list561
118Minimum number of Merge Operations to make an Array Palindrome557
119Rotate string to get lexicographically minimum string556
120Most repeating character in a string555
121Repeated Subsequence of Length Two or More553
122Print all anagrams together in a sequence of words548
123Reorder an Array According to the Given Indexes548
124Pancake Sorting Problem540
125Merge Overlapping Intervals II536
126Clone a Linked List with next and random pointer535
127Two Sum Leetcode Solution533
128Size of The Subarray With Maximum Sum524
129Transpose of a Matrix522
130Removing Spaces from a String using stringstream518
131Remove Extra Spaces from a String518
132Check if a given string is a rotation of a palindrome515
133Partition Problem514
134Smallest Palindrome after Replacement514
135Remove duplicates from a string513
136Longest Palindrome can be Formed by Removing or Rearranging Characters511
137Maximum Sum Increasing Subsequence511
138Check whether Strings are K Distance Apart or Not501
139Generate all Binary Strings from Given Pattern499
140Find Zeros to be Flipped so that Number of Consecutive 1’s is Maximized498
141Length of Longest valid Substring497
142Insert Node in the Sorted Linked List497
1433Sum Leetcode Solution494
144Delete Last Occurrence494
145Check if Two given Strings are Isomorphic to each other490
146Maximum difference between two elements such as larger element comes after smaller486
147Program to Toggle all Characters in a String481
148Count Minimum Steps to Get the given Array478
149Given string is interleaving of two other strings or not478
150Merge sort better than quick sort for linked lists474
151Number of Smaller Elements on Right Side472
152Find Pair with Given Difference470
153Check length of a String is Equal to the Number Appended at its Last468
154Check if all Rows of a Matrix are Circular Rotations of Each Other468
155Find nth node of the Linked list from the end466
156Longest Common Prefix using Divide and Conquer466
157Sort 0s 1s and 2s in an Array457
158Find a Fixed Point in a Given Array456
159Compare Two Version Numbers454
160Print all interleavings of given two strings454
161Find the Subarray of given length with Least Average452
162Merge two sorted linked lists such that merged list is in reverse order452
163Reorder Array Using Given Indexes450
164Split linked list using alternate nodes449
165Reverse words in a given string448
166Print Reverse of a string (Recursion)446
167Median of Two Sorted Arrays LeetCode Solution444
168Print string of odd length in ‘X’ format434
169Find K Length Subarray of Maximum Average430
170Find Element Using Binary Search in Sorted Array430
171Swap Kth Node from beginning with Kth Node from End430
172Print all Palindromic Partitions of a String426
173Find Duplicates in an Array in Most Efficient Way424
174print all palindromic partitions420
175Flatten a multilevel linked list414
176Maximum Length of Chain Pairs414
177Shortest Superstring Problem413
178Check if String Follows Order of Characters by a Pattern or not410
179Sorting a K Sorted Array408
180Sort a String According to Another String401
181Longest Span with same Sum in two Binary Arrays II397
182Reverse a Linked List in groups394
183Find a Sorted Subsequence of size 3391
184Program to add two binary digits389
185Find the two Numbers with Odd Occurrences in an Unsorted Array386
186Recursively print all the sentences that can be formed from list of word lists385
187Longest Common Prefix Using Binary Search II382
188Reverse a Singly Linked List (Iterative/Non-Recursive)380
189Kth Non-repeating Character376
190Rearrange a linked list in Zig-Zag376
191Caesar Cipher375
192Check if String can Become Empty by Recursively Deleting given Substring374
193Pancake Sorting373
194Rotate Image by 90 degrees370
195Longest Common Prefix Word by Word Matching367
196Perfect Reversible String364
197Permutations of a Given String Using STL363
198Merging Two Sorted Arrays361
199Increasing Subsequence of Length three with Maximum Product361
200Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes360
201Find the point where a monotonically increasing function becomes positive first time358
202Sort a linked list with 0s, 1s and 2s357
2031`s and 2`s complement of binary number355
204Find First non-repeating character in a string355
205Four Elements that Sum to Given353
206Delete N nodes after M351
207List items containing all characters of a given word350
208Longest Common Prefix using Character by Character Matching347
209Count Number of Occurrences in a Sorted Array344
210Split a string338
211Minimum Characters to be Removed to Make a Binary String Alternate338
212Palindrome string (number)338
213Check if a Linked list of Strings form a Palindrome332
214Recursive Implementation of atoi()330
215Print All Distinct Elements of the Array330
216Sorting the array of strings329
217Convert a String that is Repetition of a Substring of Length K327
218Find the first Repeating Number in a Given Array325
219Maximum occurring character in a string324
220Even Substring Count324
221Reverse a singly linked list recursively323
222Valid Parentheses LeetCode Solution322
223Can we reverse a linked list in less than O(n) time ?322
224Binary Tree to Doubly linked list321
225Print Shortest Path to Print a String on Screen320
226Nth Character in Concatenated Decimal String316
227Sort Elements by Frequency II316
228Reverse a String using Stack316
229Convert string1 to string2 in one edit316
230Lower Case To Upper Case314
231wildcard character matching313
232Maximum Subarray Leetcode Solution311
233Merge Two Sorted Arrays310
234Find the Lost Element From a Duplicated Array310
235Count the number of words308
236Split Four Distinct Strings307
237Find middle of the Linked List304
238Count the Pairs at Same Distance as in English Alphabets298
239Longest Common Subsequence with Permutations298
240Next Greater Element in an Array294
241Matrix Chain Multiplication using Dynamic Programming292
242Palindrome Permutation287
243Searching a node in a Binary Search Tree283
244Find Nth Node283
245Find All Pairs With a Given Difference281
246Triplet from three linked lists with given sum280
247Roman to Integer Leetcode Solution279
248Delete a Tree279
249String(represents an integer) to value275
250Print all Possible Ways to Break a String in Bracket Form275
251Reverse a String275
252Reverse Bits271
253Binary Tree271
254Delete a node under given conditions270
255Change Gender of a given String270
256Word Search Leetcode Solution269
257Sort an array of strings268
258Number of sub-strings which recursively add up to 9265
259How to Efficiently Implement k Stacks in a Single Array?265
260Longest Common Extension264
261Remove middle points in a linked list of line segments264
262Count Pairs With Given Sum263
263Meeting Rooms II LeetCode Solution262
264Toeplitz Matrix262
265First non Repeating Element261
266Remove spaces from a string261
267Longest Palindromic Substring LeetCode Solution260
268Shuffle a given Array258
269Repeated Substring Pattern257
270Move all negative elements to one side of array257
271Min Stack255
272N queen problem254
273Dijkstra Algorithm249
274Number of Islands LeetCode Solution249
275Find, second, frequent, character249
276House Robber Leetcode Solution247
277Cuckoo sequence program247
278Most Frequent Element in an Array246
279Clone a linked list with next and random pointer (Hashing)245
280Minimize the maximum difference between the heights244
281Sort linked which is sorted on absolute values243
282Max stack243
283Expression Evaluation242
284Search Insert Position Leetcode Solution242
285Fibonacci numbers240
286Valid Palindrome Leetcode Solution238
287KMP Algorithm237
288Plus One Leetcode Solution237
289How to Delete a Linked List237
290Sudoku Solver236
291Min Stack Leetcode Solution236
292Word Search235
293Reverse words in a string234
294Subset Leetcode233
295Evaluation of Postfix Expression233
296Number Of 1 bits232
297Combination Sum Leetcode Solution232
298Backspace String Compare227
299Merge Sorted Arrays Leetcode Solution227
300Pair of Positive Negative Values in an Array226
301Rabin Karp Algorithm226
302Sqrt(x) Leetcode Solution225
303Set Matrix Zeroes224
304Contains Duplicate II Leetcode Solution223
305Reversing a Queue223
306Tower Of Hanoi222
307Subarray with 0 sum221
308Combination Sum220
309Common elements in all rows of a given matrix219
310Product of array except self219
311Intersection of Two Arrays II Leetcode Solution218
312Integer to Roman Leetcode Solution217
313Count subarrays with equal number of 1’s and 0’s216
314String Compression215
315Pascal Triangle Leetcode215
316Delete middle element of a stack215
317Reverse individual words214
318Find Top K (or Most Frequent) Numbers in a Stream213
319Second Most Repeated Word in a Sequence213
320Construct Binary Tree from Given Inorder and Preorder Traversals213
321Minimum swaps required to bring all elements less than or equal to k together212
322Sliding Window Technique212
323Pow(x, n) Leetcode Solution211
324Segregate even and odd numbers211
325Bellman Ford Algorithm211
326Add Binary Leetcode Solution211
327Arithmetic Expression Evaluation211
328Palindrome Linked List Leetcode Solution210
329Next Permutation210
330Count of index pairs with equal elements in an array210
331Page Replacement Algorithms in Operating Systems210
332Implementation of Deque using Doubly Linked List210
333Design a stack that supports getMin() in O(1) time and O(1) extra space209
334Single Number Leetcode Solution209
335Kruskal Algorithm209
336Find sum of non-repeating elements (distinct) elements in an array208
337Contains Duplicate208
338Postfix to Infix Conversion208
339Minimum Value to Get Positive Step by Step Sum Leetcode Solution207
340K-th Smallest Element in a Sorted Matrix207
341Count Odd Numbers in an Interval Range Leetcode Solution207
342Maximum Subarray206
343Maximum Number of Balloons Leetcode Solution206
344Sort elements by frequency206
345Longest Common Prefix Leetcode Solution204
346Group Words With Same Set of Characters204
347Find Lucky Integer in an Array Leetcode Solution204
348Permutations Leetcode Solution204
349Convex Hull Algorithm204
350Third Maximum Number Leetcode Solution204
351Find Numbers with Even Number of Digits Leetcode Solution203
352Majority Element Leetcode Solution203
353Find the Town Judge Leetcode Solution203
354Top K Frequent Words203
355Longest Substring Without Repeating Characters LeetCode Solution202
356Spiral Matrix LeetCode Solution202
357Swap Nodes in Pairs Leetcode Solutions202
358Sorting array using Stacks201
359Minimum operation to make all elements equal in array201
360Sum of minimum and maximum elements of all subarrays of size k201
361Count subarrays having total distinct elements same as original array200
362Evaluate Division200
363Scramble String200
364Smallest Subarray with k Distinct Numbers200
365Special Number198
366Merge Two Sorted Lists Leetcode Solutions198
367Check if two arrays are equal or not197
368First element occurring k times in an array197
369Search in Rotated Sorted Array Leetcode Solution197
370Reverse a Number Using Stack197
371Count Primes Leetcode Solutions196
372Group Anagrams196
373Prefix to Infix Conversion196
374Given two unsorted arrays find all pairs whose sum is x196
375Minimum Path Sum196
376Number of Good Pairs Leetcode Solution195
377Pascal’s Triangle II Leetcode Solution195
378Best Time to Buy and Sell Stock  II Leetcode Solution195
379Huffman Coding194
380Find duplicates in a given array when elements are not limited to a range194
381Maximum Distance Between two Occurrences of Same Element in Array194
382Reversing the First K elements of a Queue194
383Minimum Steps to reach target by a Knight193
384Power of Two Leetcode Solution193
385Single Number193
386Minimum Absolute Difference Leetcode Solution193
387Fizz Buzz Leetcode193
388Running Sum of 1d Array Leetcode Solution192
389House Robber II Leetcode Solution192
390Sort Array by Increasing Frequency Leetcode Solution192
391Coin Change 2 Leetcode Solution192
392Range Sum Query 2D – Immutable Leetcode Solution192
393Missing Number Leetcode Solution192
394Maximal Square191
395How to Implement Stack Using Priority Queue or Heap?191
396Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution191
397Maximum possible difference of two subsets of an array191
398Top K Frequent Elements190
399Find All Numbers Disappeared in an Array Leetcode Solution190
400Unique Paths Leetcode Solution189
401Matrix Diagonal Sum Leetcode Solution189
402How Many Numbers Are Smaller Than the Current Number Leetcode Solution189
403Subarray Sum Equals K LeetCode Solution189
404Max Consecutive Ones Leetcode Solution189
405Sorting using trivial hash function189
406Leetcode Permutations188
407Check if Array Contains Contiguous Integers With Duplicates Allowed188
408Palindrome Substring Queries188
409Zigzag Conversion188
410Expression Contains Redundant Bracket or Not188
411Subset sum problem188
412Unique Paths188
413Decode String188
414Subarray Sum Equals k187
415Sort Integers by The Number of 1 Bit Leetcode Solution187
416Find The Duplicate Number187
417Difference between highest and least frequencies in an array187
418Find Winner on a Tic Tac Toe Game Leetcode Solution187
419Happy Number Leetcode Solution187
420Smallest Element Repeated Exactly K Times187
421Fibonacci Number LeetCode Solution187
422Subtract the Product and Sum of Digits of an Integer Leetcode Solution187
423Nth Catalan Number187
424Find the Closest Palindrome number186
425Print All Distinct Elements of a Given Integer Array186
426Monotonic Array LeetCode Solution186
427Cumulative Frequency of Count of Each Element in an Unsorted Array186
428Reverse Integer186
429Convert String To Int186
430Check If N and Its Double Exist Leetcode Solution186
431Find Median from data Stream186
432Letter Case Permutation186
433Reverse Vowels of a String Leetcode Solution186
434Find Number of Employees Under every Employee185
435Trapping Rain Water Leetcode Solution185
436Length of the largest subarray with contiguous elements185
437Shuffle the Array Leetcode Solution185
438Remove Duplicates from Sorted Array Leetcode Solution185
439Find top three repeated in array185
440Best Time to Buy and Sell Stock III Leetcode Solution184
441Reverse Words in a String III LeetCode Solution184
442Implement Stack and Queue using Deque184
443Bipartite Graph184
444Find all pairs (a, b) in an array such that a % b = k184
445Capacity To Ship Packages Within D Days Leetcode Solution184
446Sort a stack using recursion184
447LRU Cache Implementation183
448Maximum Depth of Binary Tree Leetcode Solution183
449Find the first repeating element in an array of integers183
450Prim’s Algorithm182
451Priority Queue Using Singly Linked List182
452Minimum Moves to Equal Array Elements Leetcode Solution182
453Generate a String With Characters That Have Odd Counts Leetcode Solution182
454Find the Duplicate Element182
455Find Minimum In Rotated Sorted Array182
456Merge Two Sorted Linked Lists181
457Count pairs from two linked lists whose sum is equal to a given value181
458Count Substrings with equal number of 0s, 1s and 2s181
459Delete a Node from linked list without head pointer181
460Subarrays with distinct elements181
461Integer to English words181
462Reverse a String181
463Longest Common Subsequence181
464Concatenation of Array LeetCode Solution181
465Sum of Subarray Ranges Leetcode Solution181
466Reverse a Stack Using Recursion181
467Sorting a Queue without Extra Space181
468Kth largest element in an Array Leetcode Solutions181
469Fizz Buzz180
470The K Weakest Rows in a Matrix Leetcode Solution180
471Find elements which are present in first array and not in second180
472Find First and Last Position of Element in Sorted Array Leetcode Solution179
473Find Common Characters Leetcode Solution179
474Edit Distance179
475Remove Minimum Number of Elements Such That no Common Element Exist in both Array179
476Find the Difference Leetcode Solution179
477Next Greater Element I Leetcode Solution179
478Reverse a linked list178
479Kth Largest Element in a Stream Leetcode Solution178
480Word Ladder LeetCode Solution178
481Text Justification LeetCode Solution178
482Count and Say178
483Kids With the Greatest Number of Candies Leetcode Solution178
484Target Sum178
485MiniMax Algorithm178
486Excel Sheet Column Number Leetcode Solution178
487Degree of an array178
488Floyd Warshall Algorithm177
489Number of Steps to Reduce a Number to Zero Leetcode Solution177
490Multiply Strings Leetcode Solution177
491Print all subarrays with 0 sum177
492Longest Common Prefix using Trie177
493Top View of Binary Tree177
494Priority Queue in C++176
495Balanced Binary Tree Leetcode Solution176
496Merge Overlapping Intervals176
497Iterative Tower of Hanoi176
498Longest subarray not having more than K distinct elements175
499Pair with given product175
500Flood Fill LeetCode175
501Shortest Palindrome175
502Koko Eating Bananas Leetcode Solution175
503Design Parking System Leetcode Solution175
504Max Area of Island175
505Prefix to Postfix Conversion174
506Count and Say Leetcode Solution174
507Postfix to Prefix Conversion174
508Valid Parenthesis String174
509Peak Index in a Mountain Array174
510Check if a given array contains duplicate elements within k distance from each other174
511Move Zeroes LeetCode Solution174
512The Stock Span Problem174
513Jump Game Leetcode Solution173
514Shuffle String Leetcode Solution173
515Substring With Concatenation Of All Words173
516Mobile Numeric Keypad Problem173
517Find distinct elements common to all rows of a matrix173
518Find four elements that sum to a given value (Hashmap)173
519Find subarray with given sum (Handles Negative Numbers)173
521Length of Last Word Leetcode Solution173
522Find N Unique Integers Sum up to Zero Leetcode Solution173
523Intersection of Two Arrays173
524Implement a stack using single queue173
525Implement Stack using Queues173
526Zigzag Conversion LeetCode Solution173
527Container with Most Water172
528Find missing elements of a range172
529Find Index of Closing Bracket for a Given Opening Bracket in an Expression172
530Convert array into Zig-Zag fashion172
531Slowest Key Leetcode Solution172
532Contiguous Array Leetcode172
533Excel Sheet Column Title Leetcode Solution172
534Count number of triplets with product equal to given number172
535Iterative Inorder Traversal of a Binary Tree172
536Longest Common Prefix using Sorting171
537Best Time to Buy and Sell Stock171
538Delete Node in a Linked List Leetcode Solution171
539Smallest Subarray With all Occurrences of a Most Frequent Element171
540Maximum sum rectangle in a 2D matrix171
541Relative Sort Array Leetcode Solution171
542Last Stone Weight171
543Largest Perimeter Triangle Leetcode Solution170
544K-th Distinct Element in an Array170
545Minimum Operations to convert X to Y170
546Find any one of the multiple repeating elements in read only array170
547Convert a normal BST to Balanced BST170
548Minimum Bracket Reversals170
549Build Array From Permutation Leetcode Solution169
550Valid Sudoku169
551Next Greater Frequency Element169
552Shuffle an Array169
553Check for Balanced Parentheses in an Expression168
554First negative integer in every window of size k168
555Assign Cookies Leetcode Solution168
556Sum of Left Leaves Leetcode Solutions168
557Jewels and Stones Leetcode Solution168
558Change the Array into Permutation of Numbers From 1 to N168
559Implementation of Deque using circular array168
560Arrange given numbers to form the biggest number168
561Distribute Candies to People Leetcode Solution168
562The Knapsack Problem167
563Valid Anagrams167
564Isomorphic Strings Leetcode Solution167
565Shortest Path in a Grid with Obstacles Elimination LeetCode Solution167
566Rearrange a binary string as alternate x and y occurrences167
567Group Multiple Occurrence of Array Elements Ordered by first Occurrence167
568Maximum path sum in a triangle167
569Integer to Roman167
570Find Words That Can Be Formed by Characters Leetcode Solution167
571Is Subsequence Leetcode Solution167
572Gold Mine Problem167
573Insert Interval Leetcode Solution167
574N-th Tribonacci Number Leetcode Solution166
5753Sum Closest LeetCode Solution166
576Unique Binary Search Trees166
577Linked List Cycle II LeetCode Solution166
57801 Matrix LeetCode Solution166
579Convert Sorted Array to Binary Search Tree Leetcode Solution166
580Sieve of Eratosthenes166
581Count all subsequences having product less than K166
582Minimum Delete Operations to make all Elements of Array Same166
583Decode Ways166
584Hamming Distance166
585How to check if two given sets are disjoint?165
586Island Perimeter Leetcode Solution165
587Count the number of nodes at given level in a tree using BFS165
588Find the smallest positive integer value that cannot be represented as sum of any subset of a given array165
589Rotate List Leetcode Solution165
590Remove Linked List Elements Leetcode Solution165
591Same Tree LeetCode Solution165
592Maximum Distance in Array164
593LRU Cache LeetCode Solution164
594Maximum difference between first and last indexes of an element in array164
595Combinations Leetcode Solution164
596Minimum number of distinct elements after removing m items164
597Trapping Rain Water LeetCode Solution164
598K Empty Slots LeetCode164
599Minimum Knight Moves LeetCode Solution164
600Distance Between Bus Stops Leetcode Solution163
601Minimum number of subsets with distinct elements163
602Word Pattern163
603Find minimum difference between any two elements163
604Summary Ranges Leetcode Solution163
605Rotate Image LeetCode Solution163
606Printing brackets in Matrix Chain Multiplication Problem162
607Minimum insertions to form a palindrome with permutations allowed162
608Frog Jump Leetcode Solution162
609Applications of Breadth First Search and Depth First Search162
610Sort Array By Parity LeetCode Solution162
611Maximum Number of Chocolates to be Distributed Equally Among k Students162
612Find Sum of all unique sub-array sum for a given array162
613Find if an Expression has Duplicate Parenthesis or Not162
614Coin Change Problem162
615Best Time to Buy and Sell Stock LeetCode Solution161
616Permutation in String Leetcode Solution161
617Minimum Cost to Hire K Workers161
618Find the Duplicate Number LeetCode Solution161
619Word Wrap Problem161
620Replace Elements with Greatest Element on Right Side Leetcode Solution161
621Distance of nearest cell having 1 in a binary matrix160
622Kth Missing Positive Number Leetcode Solution160
623Minimum Depth of Binary Tree Leetcode Solution160
624Stone Game LeetCode160
625Find Maximum Level sum in Binary Tree160
626Remove All Occurrences of a Substring LeetCode Solution160
627House Robber160
628Sort Characters By Frequency LeetCode Solution160
629License Key Formatting Leetcode Solution160
630XOR Operation in an Array Leetcode Solution160
631Defanging an IP Address Leetcode Solution160
632Painting Fence Algorithm159
633Longest Increasing Subsequence159
634Segregate 0s and 1s in an Array159
635Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest159
636Smallest Good Base159
637Maximum Consecutive Numbers Present in an Array159
638Check If It Is a Straight Line Leetcode Solution158
639Power of Four Leetcode Solution158
640Queries for counts of array elements with values in given range158
641Longest Substring with At Most K Distinct Characters LeetCode Solution158
642Binary Tree Zigzag Level Order Traversal LeetCode Solution158
643Non-overlapping sum of two sets158
644Reverse a stack without using extra space in O(n)158
645K Empty Slots157
646Valid Palindrome II Leetcode Solution157
647Find Largest d in Array such that a + b + c = d157
648Count Good Nodes in Binary Tree Leetcode Solution157
649Isomorphic Strings157
650Tracking current Maximum Element in a Stack157
651Merge Two Balanced Binary Search Trees157
652GCD Of Two Numbers157
653Best Time to Buy and Sell Stock with Cooldown Leetcode Solution157
654Reorganize String157
655Optimal Account Balancing LeetCode Solution157
656Iterative Method to find Height of Binary Tree157
657How to Create Mergable Stack?156
658Moving Average from Data Stream Leetcode Solution156
659Strobogrammatic Number LeetCode Solution156
660Wiggle Sort156
661Check If Two String Arrays are Equivalent Leetcode Solution156
662Partition Labels LeetCode Solution156
663Number of Provinces Leetcode Solution156
664String to Integer (atoi) LeetCode Solution156
665Sum of All Odd Length Subarrays Leetcode Solution156
666Flipping an Image LeetCode Solution156
667Longest Substring with At Least K Repeating Characters LeetCode Solution156
668Employee Free Time LeetCode Solution156
669Convert an array to reduced form155
670Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions155
671Check if a queue can be sorted into another queue using a stack155
672Reservoir Sampling155
673Find the Distance Value Between Two Arrays Leetcode Solution155
674Permutation Sequence LeetCode Solution155
675Increasing Decreasing String Leetcode Solution155
676BFS vs DFS for Binary Tree155
677Form minimum number from given sequence155
678Largest Sum Contiguous Subarray155
679Sum of f(a[i], a[j]) over all pairs in an array of n integers155
680Letter Combinations of a Phone Number155
681Inorder Successor of a node in Binary Tree155
682Maximum Number of Coins You Can Get Leetcode Solution155
683Populating Next Right Pointers in Each Node154
684Delete consecutive same words in a sequence154
685Reducing Dishes LeetCode Solution154
686Lucky Numbers in a Matrix Leetcode Solution154
687Path With Maximum Minimum Value LeetCode Solution154
688Ugly Number Leetcode Solution154
689Maximum Number of Occurrences of a Substring Leetcode Solution154
690To Lower Case Leetcode Solution154
691Subset Sum Leetcode154
692Longest Increasing Path in a Matrix LeetCode Solution153
693Maximum Product of Three Numbers LeetCode Solution153
694Find the node with minimum value in a Binary Search Tree153
695Majority Element II Leetcode Solution153
696Number of Dice Rolls With Target Sum LeetCode Solution153
697Find Leaves of Binary Tree LeetCode Solution153
698Print the Fibonacci numbers in reverse order153
699Valid Palindrome153
700Reversing a Queue using Recursion153
701Sort Array by Increasing Frequency Leetcode Solution153
702Find whether an array is subset of another array153
703Find the Smallest Divisor given a Threshold Leetcode Solution153
704Hamming Distance Leetcode Solution153
705Add and Search Word – Data structure design LeetCode152
706Numbers with prime frequencies greater than or equal to k152
707Delete Nth node from the end of the given linked list152
708Construct BST from given Preorder Traversal152
709Reverse Only Letters LeetCode Solution152
710Unique Paths II Leetcode Solution152
711Valid Perfect Square Leetcode Solution152
712Partition Array Into Three Parts With Equal Sum Leetcode Solution152
713Remove Invalid Parentheses Leetcode Solution152
714Dynamic Programming Basics152
715Factorial Trailing Zeroes Leetcode Solution152
716Recover Binary Search Tree152
717Find pairs with given sum such that elements of pair are in different rows152
718Stack Permutations (Check if an array is stack permutation of other)151
719Largest subarray with equal number of 0s and 1s151
720Edit Distance LeetCode Solution151
721Binary Tree zigzag level order Traversal151
722Convert a Number to Hexadecimal Leetcode Solution151
723Decompress Run-Length Encoded List Leetcode Solution151
724Longest Span with same Sum in two Binary arrays151
725Merge Two Binary Trees LeetCode Solution150
726Binomial Coefficient150
727Maximum Product of Two Elements in an Array Leetcode Solution150
728Deletion in a Binary Tree150
729Minimum Cost For Tickets Leetcode Solution150
730Restore IP Addresses Leetcode Solution150
731Symmetric Tree Leetcode Solution149
732Bubble sort using two Stacks149
733Maximum 69 Number Leetcode Solution149
734Minimum Distance Between BST Nodes Leetcode Solution149
735Keyboard Row Leetcode Solution149
736Minimum Height Trees149
737Find Pair with Greatest Product in Array149
738Rank Transform of an Array Leetcode Solution149
739Finding K closest element149
740Find unique character in a string149
741Find Maximum Depth of Nested Parenthesis in a String149
742Best Meeting Point LeetCode Solution149
743Find the largest multiple of 3149
744Merge K Sorted Linked Lists149
745Generate all possible sorted arrays from alternate elements of two given sorted arrays148
746Sorted Linked List to Balanced BST148
747Count quadruples from four sorted arrays whose sum is equal to a given value x148
748Binary Tree Maximum Path Sum LeetCode Solution148
749Bulb Switcher LeetCode Solution148
750Morris Traversal148
751k-th missing element in increasing sequence which is not present in a given sequence148
752Elements to be added so that all elements of a range are present in array148
753Word Pattern LeetCode Solution148
754Perform String Shifts Leetcode148
755Race Car LeetCode Solution148
756Invert Binary Tree LeetCode Solution148
757Jump Game148
758Growable array based stack148
759Robot Room Cleaner Leetcode Solution148
760Remove brackets from an algebraic string containing + and – operators148
761Minimum time required to rot all oranges147
762Student Attendance Record I Leetcode Solution147
763Queue based approach for first non-repeating character in a stream147
764Evaluate Reverse Polish Notation LeetCode Solution147
765Maximum Depth of N-ary Tree Leetcode Solution147
766Find All Duplicates in an Array LeetCode Solution147
767Diagonal Traversal of Binary Tree147
768First Unique Character in a String LeetCode Solution147
769Kth ancestor of a node in binary tree147
770Largest rectangular sub-matrix whose sum is 0147
771Number of NGEs to the Right147
772Relative Ranks Leetcode Solution147
773Non-decreasing Array LeetCode Solution147
774Program for Bridge and Torch problem147
775Remove Nth Node From End of List Leetcode Solution146
776String comparison containing wildcards146
777Search in a Binary Search Tree Leetcode Solution146
778Maximum Length of a Concatenated String with Unique Characters Leetcode Solution146
779Merge Sorted Array LeetCode Solution146
780Valid Number146
781Check for Palindrome after every character replacement Query146
782Largest Rectangle in Histogram LeetCode Solution146
783Snakes and Ladders LeetCode Solution146
784N-Queens LeetCode Solution146
785Tiling Problem146
786Minimum number of jumps to reach end146
787Remove Duplicates from Sorted List LeetCode Solution146
788Number of Islands II LeetCode Solution146
789Nested List Weight Sum II LeetCode Solution146
790String Compression LeetCode Solution146
791Transpose Graph145
792Maximum Difference Between Increasing Elements LeetCode Solution145
793Count items common to both the lists but with different prices145
794Linked List Cycle145
795Find Median from Data Stream LeetCode Solution145
796Base 7 Leetcode Solution145
797Alien Dictionary LeetCode Solution145
798Find if Path Exists in Graph Leetcode Solution145
799Partition to K Equal Sum Subsets Leetcode Solution145
800Sort an array according to the order defined by another array145
801Minimum swaps to make sequences increasing145
802Special Array With X Elements Greater Than or Equal X Leetcode Solution145
803Minimize Maximum Pair Sum in Array LeetCode Solution145
804Interval Tree145
805Search a 2D Matrix II Leetcode Solution145
806Get Maximum in Generated Array Leetcode Solution144
807Number Complement Leetcode Solution144
808Total Numbers With no Repeated Digits in a Range144
809Split a String in Balanced Strings Leetcode Solution144
810Check if Two Expressions With Brackets are Same144
811Iterative Preorder Traversal144
812Check If Array Pairs Are Divisible by k LeetCode Solution144
813Print a Binary Tree in Vertical Order144
814Circular Queue144
815Final Prices With a Special Discount in a Shop Leetcode Solution144
816Crawler Log Folder Leetcode Solution144
817Reorder Data in Log Files LeetCode Solution144
818A Space Optimized DP solution for 0-1 Knapsack Problem144
819Remove Duplicates from Sorted List II143
820Last Stone Weight II LeetCode Solution143
821Sort Array By Parity II Leetcode Solution143
822Find all triplets with zero sum143
823One Edit Distance LeetCode Solution143
824Course Schedule II – LeetCode143
825Longest Subarray Having Count of 1s One More than Count of 0s143
826Priority Queue using doubly linked list143
827Permutation Coefficient143
828Clone Graph LeetCode Solution143
829Nearest Exit from Entrance in Maze LeetCode Solution143
830Minimum Time Visiting All Points Leetcode Solution143
831Convert BST to Min Heap143
832Subset with sum divisible by m142
833Design a Stack With Increment Operation Leetcode Solution142
834Sort Colors142
835Guess Number Higher or Lower LeetCode Solution142
836Minimum Swaps to Make Strings Equal Leetcode Solution142
837Path with maximum average value142
838Top K Frequent Words LeetCode Solution142
839Find the subarray with least average142
840Partition List Leetcode Solution142
841Find the Only Repetitive Element Between 1 to N-1142
842Maximum size subarray sum equals k142
843Maximum Nesting Depth of the Parentheses Leetcode Solution142
844Check if an Array is Stack Sortable141
845Sum of nearest smaller and greater number141
846Form Minimum Number From Given Sequence141
847Minimum Number of Taps to Open to Water a Garden LeetCode Solution141
848Minimum Jumps to Reach Home LeetCode Solution141
849Count ways to reach the nth stair using step 1, 2 or 3141
850Friends Pairing Problem141
851Given an Array of Pairs Find all Symmetric Pairs in it141
852Check if a given array can represent Preorder Traversal of Binary Search Tree141
853Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution141
854Regular Expression Matching141
855Brick Wall LeetCode Solution141
856Spiral Matrix II Leetcode Solution141
857Find All Possible Recipes from Given Supplies LeetCode Solution141
858Sorted Array to Balanced BST141
859Count Distinct Elements in Every Window of Size K141
860Matrix Chain Multiplication141
861Level order Traversal in Spiral Form140
862Tree Traversal (Preorder, Inorder & Postorder)140
863Check whether a given Binary Tree is Complete or not140
864Can Place Flowers LeetCode Solution140
865Valid Parentheses Leetcode Solution140
866Brightest Position on Street LeetCode Solution140
867Subarray Product Less Than K LeetCode Solution140
868Insert Delete GetRandom140
869Binary Search Tree Search and Insertion140
870LCS (Longest Common Subsequence) of three strings140
871Subsequence of Size K With the Largest Even Sum LeetCode Solution140
872Maximum Profit in Job Scheduling Leetcode Solution140
873Minimum Sum Path in a Triangle139
874Distinct adjacent elements in an array139
875Union and Intersection of two Linked Lists139
876Insert into a Binary Search Tree Leetcode Solution139
877Range sum queries without updates139
878Count Subarrays with Same Even and Odd Elements139
879Guess Number Higher or Lower II139
880Find Maximum Sum Possible Equal Sum of Three Stacks139
881Rearrange an Array Such that arr[i] is equal to i139
882Find all permuted rows of a given row in a matrix139
883Sequences of given length where every element is more than or equal to twice of previous139
884Find distance between two nodes of a Binary Tree138
885Rearrange Spaces Between Words Leetcode Solution138
886Shortest Word Distance Leetcode Solution138
887Check if stack elements are pairwise consecutive138
888Count Negative Numbers in a Sorted Matrix LeetCode Solution138
889A program to check if a binary tree is BST or not138
890Destination City Leetcode Solution138
891Alien Dictionary138
892Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution138
893Daily Temperatures Leetcode Solution138
894Delete And Earn138
895Find Common Characters Leetcode Solution138
896Diagonal Traversal LeetCode Solution138
897Three way partitioning of an array around a given range138
898Minimum sum of multiplications of n numbers138
899Convert Sorted List to Binary Search Tree138
900An Interesting Method to generate Binary Numbers from 1 to n138
901Missing Element in Sorted Array LeetCode Solution138
902Identify and Mark Unmatched Parenthesis in an Expression138
903BFS for Disconnected Graph138
904Maximum Score After Splitting a String Leetcode Solution138
905Water Bottles Leetcode Solution137
906Check if the given array can represent Level Order Traversal of Binary Search Tree137
907Lemonade Change Leetcode Solution137
908Repeated Substring Pattern LeetCode Solution137
910GCDs of given index ranges in an array137
911Balanced Expression with Replacement137
912Special Positions in a Binary Matrix Leetcode Solution137
913Set Matrix Zeroes Leetcode Solution137
914Construct Complete Binary Tree from its Linked List Representation137
915Range LCM Queries137
916Number of Days Between Two Dates LeetCode Solution137
917Design Browser History LeetCode Solution136
918Robot Bounded In Circle LeetCode Solution136
919Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i136
920Least Number of Unique Integers after K Removals Leetcode Solution136
921Infix to Postfix136
922Merge Two Sorted Lists Leetcode136
923Diagonal Traverse LeetCode Solution136
924Vertical sum in a given binary tree136
925Queue using Stacks136
926Number of Equivalent Domino Pairs Leetcode Solution136
927Longest Palindromic Subsequence136
928Spiral Matrix III LeetCode Solution136
929Print Fibonacci sequence using 2 variables135
930Palindrome Partitioning Leetcode Solution135
931Construct the Rectangle Leetcode Solution135
932Averages of Levels in Binary Tree135
933Trim a Binary Search Tree135
934K’th Largest Element in BST when modification to BST is not allowed135
935Lexicographical Numbers Leetcode Solution135
936Number of Distinct Islands Leetcode Solution135
937Three Consecutive Odds Leetcode Solution135
938Maximum Subarray Sum Excluding Certain Elements135
939Dividing Array into Pairs With Sum Divisible by K135
940Largest area rectangular sub-matrix with equal number of 1’s and 0’s134
941Pattern Occurrences using Stack134
942Binary array after M range toggle operations134
943Analyze User Website Visit Pattern LeetCode Solution134
944Stone Game II Leetcode134
945Remove Duplicates from Sorted List II LeetCode Solution134
946Construct BST from its given Level Order Traversal134
947Median of Two Sorted Arrays134
948Time Based Key-Value Store LeetCode Solution134
949Word Break134
9503 Sum134
951Strongly Connected Component134
952Check if any two intervals overlap among a given set of intervals134
953Queries for GCD of all numbers of an array except elements in a given range134
954All Unique Triplets that Sum up to a Given Value134
955Merging Intervals134
956Split Array Into Consecutive Subsequences133
957Newman-Conway Sequence133
958Can Make Arithmetic Progression From Sequence Leetcode Solution133
959Binary Tree Longest Consecutive Sequence LeetCode Solution133
960Count Submatrices With All Ones LeetCode Solution133
961Maximum Frequency Stack Leetcode Solution133
962Maximize Sum of Array after K Negations Leetcode Solution133
963Iterative Postorder Traversal Using Two Stacks133
964Palindrome Partitioning133
965Create Maximum Number133
966Largest Substring Between Two Equal Characters Leetcode Solution133
967Symmetric Tree133
968Sliding Window Maximum133
969Find Maximum of Minimum for Every Window Size in a Given Array132
970Shuffle 2n integers as without using extra space132
971Maximum Product Subarray132
972Sign of the Product of an Array LeetCode Solution132
973Segment Tree132
974Intersection of Two Linked Lists LeetCode Solution132
975Difference Array | Range update query in O(1)132
976Climbing stairs132
977My Calendar I LeetCode Solution132
978Length of Longest Fibonacci Subsequence132
979Depth First Search (DFS) for a Graph132
980Find Duplicate Subtrees131
981First missing positive131
982Minimum Height Trees LeetCode Solution131
983Maximum subsequence sum such that no three are consecutive131
984Count pair with Given Sum131
985Height of a generic tree from parent array131
986Binary Search Tree Delete Operation131
987Breadth First Search (BFS) for a Graph131
988Level Order Traversal of Binary Tree131
989Find the Difference Leetcode Solution131
990Count Primes in Ranges131
991Make The String Great Leetcode Solution130
992Double the first element and move zero to end130
993Find the First Circular Tour that visits all the Petrol Pumps130
994Boundary Traversal of binary tree130
995Minesweeper LeetCode Solution130
996Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution130
997Reverse Nodes in K-Group130
998Insertion in a Binary Tree130
999Find postorder traversal of BST from preorder traversal130
1000Serialize and Deserialize Binary Tree130
1001Largest divisible pairs subset130
1002Product of Array Except Self LeetCode Solution129
1003Kill Process LeetCode Solution129
1004Largest Number Leetcode Solution129
1005Asteroid Collision LeetCode Solution129
1006Longest Nice Substring LeetCode Solution129
1007Partition Equal Subset Sum129
1008Kth Smallest Element in a BST Leetcode Solution129
1009Count subarrays where second highest lie before highest129
1010Maximum Length of Repeated Subarray129
1011Compute nCr % p129
1012Unique Paths II129
1013The Painter’s Partition Problem129
1014Number Of Longest Increasing Subsequence129
1015Level order traversal using two Queues129
1016Rearrange array such that even positioned are greater than odd129
1017Valid Boomerang Leetcode Solution129
1018Find number of pairs in an array such that their XOR is 0129
1019Collect maximum points in a grid using two traversals128
1020Friends Of Appropriate Ages LeetCode Solution128
1021Graph Valid Tree LeetCode Solution128
1022Construction of Longest Increasing Subsequence (N log N)128
1023Decrypt String from Alphabet to Integer Mapping Leetcode Solution128
1024Binary Search Tree128
1025K Closest Points to Origin Leetcode Solution128
1026The Maze III LeetCode Solution128
1027Shortest Completing Word Leetcode Solution128
1028Number of palindromic paths in a matrix128
1029String Matching in an Array Leetcode Solution128
1030Scramble String LeetCode Solution128
1031Maximum Number of Ways to Partition an Array LeetCode Solution128
1032Next Greater Element III LeetCode Solution127
1033Ugly Numbers127
1034Maximum length subsequence with difference between adjacent elements as either 0 or 1127
1035Find whether a subarray is in form of a mountain or not127
1036Invalid Transactions LeetCode Solution127
1037Find Peak Element127
1038Build an Array With Stack Operations Leetcode Solution127
1039Design Hit Counter LeetCode Solution127
1040Construct Binary Tree from given Parent Array representation127
1041Boolean Parenthesization Problem127
1042Advantages of BST over Hash Table127
1043Balanced Binary Tree127
1044Longest subsequence such that difference between adjacents is one127
1045Lowest Common Ancestor126
1046Maximum Product of Indexes of Next Greater on Left and Right126
1047Ugly Number II LeetCode Solution126
1048Minimum Index Sum of Two Lists126
1049Maximum Sum of 3 Non-Overlapping Subarrays126
1050Available Captures for Rook Leetcode Solution126
1051Minimum Size Subarray Sum126
1052Maximum weight transformation of a given string126
1053Rearrange an array such that ‘arr[j]’ becomes ‘i’ if ‘arr[i]’ is ‘j’126
1054Add two numbers126
1055Kth Smallest Element in a Sorted Matrix LeetCode Solution126
1056Implement Trie (Prefix Tree) Leetcode Solution126
1057Regular Expression Matching Regular Expression Matching LeetCode Solution126
1058Morris Inorder Traversal126
1059Iterative Depth First Traversal of Graph125
1060Move all negative elements to end in order with extra space allowed125
1061Custom Sort String Leetcode Solution125
1062Maximize Distance to Closest Person LeetCode Solution125
1063Count minimum steps to get the given desired array125
1064Bitwise AND of Numbers Range LeetCode Solution125
1065Find a Peak Element II LeetCode Solution125
1066Validate Binary Search Tree125
1067Path Sum II LeetCode Solution125
1068Defanging an IP Address LeetCode Solution125
1069Find the minimum distance between two numbers125
1070Recover Binary Search Tree Leetcode Solution124
1071Employee Importance LeetCode Solution124
1072Divisible Pairs Counting124
1073Largest BST Subtree LeetCode Solution124
1074Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution124
1075Remove Duplicates from Sorted Array II Leetcode Solution124
1076Binary Tree Right Side View LeetCode Solution124
1077Populating Next Right Pointers in Each Node Leetcode Solution124
1078Rearrange array such that even index elements are smaller and odd index elements are greater124
1079Super Ugly Number124
1080Binary Tree Data Structure124
1081Number of Closed Islands Leetcode Solution124
1082Types of Binary Tree123
1083Find Smallest Range Containing Elements from k Lists123
1084Clone a Binary Tree with Random Pointers123
1085Generate Parentheses Leetcode Solution123
1086Print all triplets in sorted array that form AP123
1087Day of the Year Leetcode Solution123
1088Maximum difference between frequency of two elements such that element having greater frequency is also greater123
1089Consecutive Characters LeetCode Solution123
1090Subarrays with K Different Integers Leetcode Solution123
1091Serialize and Deserialize Binary Tree LeetCode Solution123
1092Print Next Greater Number of Q queries123
1093Count pairs from two sorted arrays whose sum is equal to a given value x123
1094Root to Leaf path with target sum Leetcode Solutions122
1095Next Permutation Leetcode Solution122
1096Path Sum122
1097Number of siblings of a given Node in n-ary Tree122
1098Remove Palindromic Subsequences Leetcode Solution122
1099Longest Bitonic Subsequence122
1100Smallest Common Region Leetcode Solution122
1101Search in Sorted Rotated Array122
1102Number of Students Doing Homework at a Given Time Leetcode Solution122
1103Level of Each node in a Tree from source node121
1104Convert BST into a Min-Heap without using array121
1105Constant time range add operation on an array121
1106Print Right View of a Binary Tree121
1107Bottom View of a Binary Tree121
1108Write Code to Determine if Two Trees are Identical121
1109Remove duplicates from sorted array121
1110Third Maximum Number Leetcode Solution121
1111Combination Sum IV LeetCode Solution121
1112Kth Smallest Product of Two Sorted Arrays LeetCode Solution121
1113Valid Tic-Tac-Toe State LeetCode Solution121
1114Distinct Subsequences121
1115Cutting a Rod120
1116Search Insert Position120
1117Products of ranges in an array120
1118Palindrome Permutation LeetCode Solution120
1119Iterative method to find ancestors of a given binary tree120
1120Minimum sum of squares of character counts in a given string after removing k characters120
1121Count Largest Group Leetcode Solution120
1122Find Three Element From Different Three Arrays Such That a + b + c = sum120
1123Find maximum difference between nearest left and right smaller elements120
1124Mean of Array After Removing Some Elements Leetcode Solution119
1125Prime Palindrome LeetCode Solution119
1126Increasing Triplet Subsequence LeetCode Solution119
1127Maximum Binary Tree119
1128Reformat The String Leetcode Solution119
1129Maximum Product Subarray119
1130Thousand Separator Leetcode Solution119
1131Topological Sorting119
1132Longest Increasing Consecutive Subsequence119
1133Minimum Score Triangulation of Polygon Leetcode Solution119
1134Print modified array after executing the commands of addition and subtraction119
1135Golomb sequence118
1136Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution118
1137Search an Element in Sorted Rotated Array118
1138Cells with Odd Values in a Matrix LeetCode Solution118
1139Moser-de Bruijn Sequence118
1140Construct K Palindrome Strings LeetCode Solution118
1141Maximum Product of Splitted Binary Tree LeetCode Solution117
1142Count even length binary sequences with same sum of first and second half bits117
1143K maximum sums of overlapping contiguous sub-arrays117
1144Sum of Even Numbers After Queries117
1145Find maximum length Snake sequence117
1146Minimum Absolute Difference in BST Leetcode Solution117
1147Kth Smallest Number in Multiplication Table Leetcode Solution117
1148Longest Subarray of 1’s After Deleting One Element LeetCode Solution117
1149Swap Nodes In Pairs117
1150Red-Black Tree Introduction117
1151Transform a BST to Greater sum Tree117
1152Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution117
1153Binary Tree to Binary Search Tree Conversion117
1154Queries for Number of Distinct Elements in a Subarray117
1155Priority Queue116
1156Subset Sum Problem in O(sum) space116
1157K’th Largest element in BST using constant extra space116
1158Longest Repeated Subsequence116
1159Delete Nodes and Return Forest Leetcode Solution116
1160Check Array Formation Through Concatenation Leetcode Solution116
1161Maximize sum of consecutive differences in a circular array116
1162Rotate Array116
1163Possible Bipartition LeetCode Solution116
1164Factorial Trailing Zeroes LeetCode Solution116
1165Merge two BSTs with limited extra space116
1166Palindromic Substrings Leetcode Solution116
1167Minimum Cost to Move Chips to The Same Position LeetCode Solution115
1168Web Crawler LeetCode Solution115
1169Compare Strings by Frequency of the Smallest Character Leetcode Solution115
1170Decision Tree115
1171Find the smallest binary digit multiple of given number115
1172Bus Routes Leetcode Solution115
1173First Bad Version115
1174Count Pairs Whose Products Exist in Array114
1175Minimum Moves to Equal Array Elements LeetCode Solution114
1176Closest Binary Search Tree Value Leetcode Solution114
1177Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution114
1178Search Suggestions System LeetCode Solution114
1179Minimum Sideway Jumps LeetCode Solution114
1180Find a sorted subsequence of size 3 in linear time114
1181Maximum number of segments of lengths a, b and c113
1182Reverse a Path in BST using Queue113
1183Given a binary tree, how do you remove all the half nodes?113
1184Number of Orders in the Backlog Leetcode Solution113
1185Diameter of N-Ary Tree LeetCode Solution113
1186Queue Reconstruction by Height112
1187Matchsticks to Square Leetcode Solution112
1188Lowest Common Ancestor in Binary Search Tree112
1189Find Largest Value in Each Tree Row LeetCode Solution112
1190Contiguous Array LeetCode Solution112
1191Swapping Nodes in a Linked List Leetcode Solution112
1192Decrease Elements To Make Array Zigzag LeetCode Solution112
1193Reformat Date LeetCode Solution111
1194Champagne Tower LeetCode Solution111
1195Moving Stones Until Consecutive Leetcode Solution111
1196Valid Triangle Number111
1197Array Queries for multiply replacements and product111
1198Convert Sorted Array to Binary Search Tree LeetCode Solutions111
1199Closest Leaf in a Binary Tree LeetCode Solution111
1200Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution111
1201Graph and its representation110
1202Maximum Value at a Given Index in a Bounded Array LeetCode Solution110
1203Range Sum Query using Sparse Table110
1204Valid Perfect Square LeetCode Solution110
1205Sum of Left Leaves LeetCode Solution110
1206Replace two consecutive equal values with one greater110
1207New 21 Game110
1208Maximum sum bitonic subarray110
1209How to print maximum number of A’s using given four keys110
1210Integer Break LeetCode Solution110
1211Maximum sum of pairs with specific difference110
1212Kth Smallest Element in a BST110
1213Arithmetic Slices II – Subsequence LeetCode Solution109
1214Maximum Depth Of Binary Tree109
1215The kth Factor of n Leetcode Solution109
1216Concatenation of Array LeetCode Solution109
1217Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution109
1218Print modified array after multiple array range increment operations109
1219Write a function to get the intersection point of two Linked Lists109
1220Range Queries for Longest Correct Bracket Subsequence109
1221BST to a Tree with Sum of all Smaller Keys109
1222Guess The Word109
1223Path Crossing Leetcode Solution109
1224Divide Two Integers Leetcode Solution108
1225Check if each internal node of a BST has exactly one child108
1226Maximum sum of a path in a Right Number Triangle108
1227Merge Sort108
1228Minimum Swaps To Make Sequences Increasing LeetCode Solution108
1229Lowest Common Ancestor of a Binary Tree Leetcode Solution108
1230Queries on Probability of Even or Odd Number in given Ranges108
1231Design Skiplist LeetCode Solution108
1232Longest Common Prefix Using Word by Word Matching107
1233Count Subsets Having Distinct Even Numbers107
1234Perfect Squares LeetCode Solution107
1235Flatten 2D Vector LeetCode Solution107
1236Check Completeness of a Binary Tree LeetCode Solution107
1237Check if all levels of two Binary Tree are anagrams or not107
1238Check for Identical BSTs without building the trees107
1239Sliding Window Median Leetcode Solution107
1240Graph Cloning107
1241Power of Two107
1242Find minimum number of merge operations to make an array palindrome106
1243Maximize Elements Using Another Array106
1244LRU Cache Leetcode Solution106
1245Count and Toggle Queries on a Binary Array106
1246Bold Words in String LeetCode Solution106
1247Find Minimum in Rotated Sorted Array II LeetCode Solution106
1248Maximum Array from Two given Arrays Keeping Order Same106
1249Print n terms of Newman-Conway Sequence106
1250Largest Plus Sign Leetcode Solution106
1251Symmetric Tree LeetCode Solution Leetcode Solution106
1252Missing Number105
1253Mean of range in array105
1254Contiguous Array105
1255Find k-th smallest element in BST (Order Statistics in BST)105
1256Next greater element104
1257Verify Preorder Serialization of a Binary Tree104
1258Check If a String Can Break Another String Leetcode Solution103
1259Print Ancestors of a Given Binary Tree Node Without Recursion103
1260Image Overlap LeetCode Solution103
1261Excel Sheet Column Title LeetCode Solution103
1262Maximum Product Subarray103
1263Merge k Sorted Lists Leetcode Solution103
1264Minimum Remove to Make Valid Parentheses LeetCode Solution103
1265Parallel Courses II LeetCode Solution103
1266Check if two nodes are on the same path in a Tree102
1267Smallest Range II Leetcode Solution102
1268Minimum Time to Collect All Apples in a Tree LeetCode Solution102
1269Orderly Queue LeetCode Solution101
1270Palindrome Partitioning101
1271Check in binary array the number represented by a subarray is odd or even101
1272Koko Eating Bananas LeetCode Solution100
1273Check if X can give change to every person in the Queue99
1274Merge Sorted Array99
1275Peeking Iterator LeetCode Solution98
1276Min Cost Climbing Stairs LeetCode Solution98
1277Different Ways to Add Parentheses Leetcode Solution98
1278Number of elements less than or equal to a given number in a given subarray98
1279Newman–Shanks–Williams prime98
1280Maximum Sum Increasing Subsequence97
1281Largest Submatrix With Rearrangements LeetCode Solution97
1282Range Minimum Query (Square Root Decomposition and Sparse Table)96
1283Find maximum average subarray of k length96
1284Queries for Decimal Values of Subarrays of a Binary Array96
1285Longest Substring Without Repeating Characters Leetcode Solution95
1286Number of indexes with equal elements in given range95
1287Check given array of size n can represent BST of n levels or not94
1288Binary Tree to Binary Search Tree Conversion using STL set93
1289Array Nesting Leetcode Solution93
1290Arranging Coins Leetcode Solution93
1291Maximum product of an increasing subsequence93
1292Minimum Number of People to Teach LeetCode Solution92
1293Minimum Total Space Wasted With K Resizing Operations LeetCode Solution91
1294Random Pick Index LeetCode Solution91
1295Encoded String With Shortest Length LeetCode Solution91
1296Find the Winner of the Circular Game LeetCode Solution91
1297Convert a BST to a Binary Tree such that sum of all greater keys is added to every key90
1298Queries on XOR of greatest odd divisor of the range90
1299Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution90
1300Reach a Number LeetCode Solution90
1301Jump Game IV LeetCode Solution89
1302Convert to Base -2 LeetCode Solution89
1303Insert Delete GetRandom O(1) Leetcode Solution88
1304Palindrome Number LeetCode Solution86
1305Add Two Numbers II Leetcode Solution86
1306Vertical Order Traversal of Binary Tree LeetCode Solution86
1307Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution84
1308Design Underground System Leetcode Solution83
1309Print Maximum Length Chain of Pairs83
1310Continuous Subarray Sum LeetCode Solution82
1311Detect Capital Leetcode Solution81
1312Design A Leaderboard Leetcode Solution78
1313Substring with Concatenation of All Words Leetcode Solution76
1314Minimum Swaps to Group All 1’s Together Leetcode Solution75
1315Top K Frequent Elements LeetCode Solution72
1316Minimum Path Sum Leetcode Solution72
1317Odd Even Linked List Leetcode Solution72
1318Shifting Letters LeetCode Solution71
1319Maximum Population Year LeetCode Solution70
1320Decode String Leetcode Solution70
1321Binary Tree Inorder Traversal LeetCode Solution70
1322Find the Town Judge LeetCode Solution69
1323Count Sub Islands LeetCode Solution69
1324Shortest Unsorted Continuous Subarray LeetCode Solution69
1325Best Meeting Point LeetCode Solution68
1326Longest Common Subsequence LeetCode Solution68
1327Sum Root to Leaf Numbers LeetCode Solution67
1328Find the Town Judge LeetCode Solution66
1329Design Add and Search Words Data Structure LeetCode Solution65
1330Rectangle Overlap LeetCode Solution63
1331Maximum Population Year LeetCode Solution62
1332Insert into a Sorted Circular Linked List LeetCode Solution61
1333Score of Parenthesis LeetCode Solution60
1334Stone Game IV LeetCode Solution60
1335Flatten Binary Tree to Linked List LeetCode Solution59
1336Range Sum Query 2D – Immutable LeetCode Solution59
1337Valid Triangle Number LeetCode Solution58
1338Is Graph Bipartite? LeetCode Solution57
1339Reveal Cards In Increasing Order Leetcode Solution53
1340Divide Chocolate LeetCode Solution48
1341Range Sum of BST LeetCode Solution40
1342Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution38
1343Reverse Integer Leetcode Solution37
1344Sort Colors LeetCode Solution36
1345Find K Closest Elements LeetCode Solution33
1346Excel Sheet Column Number LeetCode Solution30
1347Rotate String LeetCode Solution30
1348Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution28
Translate »