104 Maximum Depth of Binary Tree 478 Easy

In the problem a binary tree is given and we have to find out the maximum depth of the given tree. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Explanation:    There are two possible longest path as shown in below tree in red color.
Maximum Depth of Binary Tree Leetcode Solution

As the tree is empty, depth is 0.

As there are only one node, depth is 1.

To find the maximum depth of the tree we can apply a simple recursive approach. Where each function call will represent a subtree which has root node called as 'root'. We traverse the tree by a recursive function starting from the root node.

So the base case is when the subtree is empty i.e. root is NULL. So we return depth as 0.

if root is not NULL, call the same function recursively for its left child and right child.

As shown in figure, when the two child function return its depth we pick the maximum out of these two subtrees and return this value after adding 1 to it ( Adding current node which is the parent of the two subtrees).

O(N) : we visit each node exactly once, thus the time complexity is O(N), where N is the total number of nodes in the given tree.

O(N) :  In the worst case, the tree is completely unbalanced, e.g. each node has only left child node or only right child node, then recursion call would occur N times (the height of the tree). Therefore the maximum size of call stack would be O(N).
In the best case (the tree is completely balanced), the height of the tree would be log⁡(N). Therefore, the space complexity in this case would be O(log⁡(N).

S.No Interview Question Number of times has been asked 1 Delete a node in doubly linked list 2850 2 Java program to find the number of Nodes in a Binary Tree 2517 3 Reverse a string without affecting special characters 2486 4 Palindrome using Recursion 2271 5 Delete a node of a linked list at given position 1992 6 Insert nodes in a linked list in a sorted way (Ascending Order) 1679 7 Find elements pair from array whose sum equal to number 1665 8 Sort Elements by Frequency of Occurrences 1652 9 Quick Sort 1633 10 Write a program to print all permutations of a given string 1624 11 Find Minimum Distance Between Two Numbers in an Array 1491 12 Create a Doubly Linked List 1459 13 Reverse an Array 1436 14 Smallest window in a string containing all characters of another string 1413 15 Recursively remove all adjacent duplicates 1375 16 Find a Triplet That Sum to a Given Value 1367 17 First Repeating Element 1359 18 Sum of numbers in String 1334 19 Arrange Even and Odd number such that Odd comes after Even 1333 20 Smallest Positive Number Missing in an Unsorted Array 1300 21 Check if the Elements of an Array are Consecutive 1271 22 Detect a loop in the Linked List 1252 23 Largest Sum Contiguous Subarray 1239 24 Quick Sort on SIngly Linked List 1232 25 Subarray with Given Sum 1226 26 Print all Possible Combinations of R Elements in a given Array of size N 1224 27 Recursive function to do substring search 1214 28 Find the Maximum Repeating Number in Array 1179 29 Binary Tree Level order traversal in Java 1136 30 Find the First and Second Smallest Elements 1131 31 Check if two linked lists are identical 1122 32 Maximum Subarray Sum using Divide and Conquer 1118 33 Remove characters from first string which are in second 1086 34 Find Leaders in an Array 1071 35 Swap nodes in the linked list 1054 36 Find the Number Occurring Odd Number of Times in an Array 1014 37 Find the second most frequent character 1008 38 Arrange given Numbers to Form the Biggest Number II 1007 39 Given a string find its first non-repeating character 984 40 Find Triplet in Array With a Given Sum 980 41 Given a sorted array and a number x, find the pair in array whose sum is closest to x 966 42 A Program to check if strings are rotations of each other or not 965 43 Total number of occurrences of a given item in the linked list 964 44 Print all possible words from phone digits 948 45 Find the Missing Number 939 46 Rearrange Positive and Negative Numbers Alternatively in Array 932 47 Longest Palindromic Substring 919 48 Segregate even and odd nodes in a linked list 903 49 Print Longest common subsequence 898 50 Union and Intersection of Two Linked Lists 886 51 Transform one string to another using minimum number of given operations 885 52 Check rearranged string can form a palindrome 867 53 Rearrange given Array in Maximum Minimum Form 856 54 Iterative Implementation of Quick Sort 847 55 Insertion Sort 836 56 Count Possible Triangles 835 57 Multiplication of Two Matrices 817 58 Count of Triplets With Sum Less than Given Value 810 59 Check if the linked list is palindrome 808 60 Rotate a Linked List 805 61 Stock Buy Sell to Maximize Profit 802 62 Concatenation of two strings 777 63 Tug of War 776 64 Print all duplicates in the input string 770 65 Count Number of Substrings with K Distinct Character's 769 66 Find Nearest Greater and Smaller Element 758 67 Reverse String Without Temporary Variable 755 68 The Celebrity Problem 752 69 Find Pythagorean Triplets from Array 750 70 Remove 'b' and 'ac' from a given string 747 71 Find all Common Elements in Given Three Sorted Arrays 738 72 Remove all duplicates in an unsorted linked list 720 73 Find the Row with Maximum Number of 1's 718 74 Find the Peak Element from an Array 711 75 Find the subarray whose sum is equal to a given number X 710 76 Remove Minimum Characters so that Two Strings Become Anagrams 707 77 Find Smallest Missing Number in a Sorted Array 706 78 Generate all Binary Strings Without Consecutive 1's 698 79 Addition of Two Matrices 698 80 A Product Array Puzzle 697 81 Implement Two Stacks in an Array 686 82 Maximum Sum of Non Consecutive Elements 686 83 Maximum Product Subarray II 671 84 Lexicographic rank of string 668 85 Multiplication of Previous and Next 663 86 Check if Two given Matrices are Identical 661 87 Subtraction of Two Matrices 650 88 Move All the Zeros to the End of the Given Array 645 89 Merge K Sorted Arrays and Print Sorted Output 644 90 Online Algorithm for Checking Palindrome in a Stream 640 91 Divide a string in N equal parts 640 92 Form Minimum Number from Given Sequence of D's and I's 638 93 Check whether two strings are anagram of each other 636 94 Remove recurring digits in a given number 628 95 Maximum Circular Subarray Sum 621 96 Sort a linked list that is sorted alternating ascending and descending 621 97 Sort a stack using a temporary stack 621 98 Find the Minimum Element in a Sorted and Rotated Array 619 99 Subarray and Subsequence 615 100 First Circular Tour to Visit all the Petrol Bunks 613 101 Move last element of the Linked List at first place 613 102 Compare two strings(linked lists) 607 103 Largest Subarray with Equal Number of 0's and 1's 606 104 Maximum Element in an Array which is Increasing and then Decreasing 604 105 Flattening a linked list 602 106 Palindrome Permutations of a String 601 107 Palindromes in a given range 595 108 Run length encoding 592 109 Elements Appear more than N/K times in Array 592 110 Minimum insertions to form a shortest palindrome 591 111 Majority Element 590 112 Pangram Checking 589 113 Print all permutations with repetition 588 114 Minimum Characters to be Added at Front to Make String Palindrome 580 115 Remove all duplicates in a sorted linked list 578 116 Rotate string to get lexicographically minimum string 577 117 Repeated Subsequence of Length Two or More 576 118 Most repeating character in a string 576 119 Merge a linked list into another at alternate positions 575 120 Rearrange a given linked list in-place 575 121 Minimum number of Merge Operations to make an Array Palindrome 574 122 Print all anagrams together in a sequence of words 566 123 Two Sum Leetcode Solution 565 124 Reorder an Array According to the Given Indexes 560 125 3Sum Leetcode Solution 559 126 Pancake Sorting Problem 555 127 Merge Overlapping Intervals II 549 128 Clone a Linked List with next and random pointer 548 129 Size of The Subarray With Maximum Sum 539 130 Transpose of a Matrix 538 131 Remove Extra Spaces from a String 538 132 Removing Spaces from a String using stringstream 538 133 Remove duplicates from a string 538 134 Smallest Palindrome after Replacement 535 135 Check if a given string is a rotation of a palindrome 534 136 Maximum Sum Increasing Subsequence 534 137 Longest Palindrome can be Formed by Removing or Rearranging Characters 532 138 Partition Problem 531 139 Generate all Binary Strings from Given Pattern 523 140 Check whether Strings are K Distance Apart or Not 519 141 Length of Longest valid Substring 517 142 Find Zeros to be Flipped so that Number of Consecutive 1's is Maximized 513 143 Delete Last Occurrence 512 144 Check if Two given Strings are Isomorphic to each other 511 145 Insert Node in the Sorted Linked List 511 146 Program to Toggle all Characters in a String 503 147 Maximum difference between two elements such as larger element comes after smaller 503 148 Given string is interleaving of two other strings or not 496 149 Count Minimum Steps to Get the given Array 495 150 Number of Smaller Elements on Right Side 489 151 Find Pair with Given Difference 489 152 Merge sort better than quick sort for linked lists 488 153 Check length of a String is Equal to the Number Appended at its Last 487 154 Check if all Rows of a Matrix are Circular Rotations of Each Other 485 155 Longest Common Prefix using Divide and Conquer 484 156 Find nth node of the Linked list from the end 479 157 Compare Two Version Numbers 476 158 Sort 0s 1s and 2s in an Array 473 159 Print all interleavings of given two strings 472 160 Find a Fixed Point in a Given Array 470 161 Reverse words in a given string 469 162 Reorder Array Using Given Indexes 468 163 Merge two sorted linked lists such that merged list is in reverse order 467 164 Median of Two Sorted Arrays LeetCode Solution 466 165 Print Reverse of a string (Recursion) 466 166 Find the Subarray of given length with Least Average 465 167 Split linked list using alternate nodes 462 168 Print string of odd length in 'X' format 451 169 Find Element Using Binary Search in Sorted Array 448 170 Print all Palindromic Partitions of a String 446 171 Swap Kth Node from beginning with Kth Node from End 445 172 Find K Length Subarray of Maximum Average 444 173 Find Duplicates in an Array in Most Efficient Way 436 174 print all palindromic partitions 433 175 Shortest Superstring Problem 431 176 Flatten a multilevel linked list 430 177 Check if String Follows Order of Characters by a Pattern or not 427 178 Maximum Length of Chain Pairs 426 179 Sort a String According to Another String 425 180 Sorting a K Sorted Array 421 181 Longest Span with same Sum in two Binary Arrays II 411 182 Reverse a Linked List in groups 408 183 Find a Sorted Subsequence of size 3 407 184 Find the two Numbers with Odd Occurrences in an Unsorted Array 405 185 Program to add two binary digits 405 186 Recursively print all the sentences that can be formed from list of word lists 404 187 Longest Common Prefix Using Binary Search II 402 188 Reverse a Singly Linked List (Iterative/Non-Recursive) 400 189 Caesar Cipher 397 190 Kth Non-repeating Character 395 191 Rearrange a linked list in Zig-Zag 392 192 Check if String can Become Empty by Recursively Deleting given Substring 391 193 Pancake Sorting 386 194 Longest Common Prefix Word by Word Matching 386 195 Rotate Image by 90 degrees 383 196 Permutations of a Given String Using STL 383 197 Perfect Reversible String 380 198 Merging Two Sorted Arrays 377 199 Increasing Subsequence of Length three with Maximum Product 377 200 Find First non-repeating character in a string 375 201 1`s and 2`s complement of binary number 371 202 Find the point where a monotonically increasing function becomes positive first time 371 203 Sort a linked list with 0s, 1s and 2s 370 204 Four Elements that Sum to Given 370 205 Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes 369 206 List items containing all characters of a given word 368 207 Longest Common Prefix using Character by Character Matching 366 208 Count Number of Occurrences in a Sorted Array 362 209 Delete N nodes after M 362 210 Maximum occurring character in a string 359 211 Palindrome string (number) 357 212 Minimum Characters to be Removed to Make a Binary String Alternate 356 213 Split a string 355 214 Sorting the array of strings 348 215 Recursive Implementation of atoi() 347 216 Valid Parentheses LeetCode Solution 347 217 Convert a String that is Repetition of a Substring of Length K 345 218 Even Substring Count 345 219 Check if a Linked list of Strings form a Palindrome 343 220 Print All Distinct Elements of the Array 342 221 Find the first Repeating Number in a Given Array 339 222 Reverse a singly linked list recursively 337 223 Print Shortest Path to Print a String on Screen 337 224 Reverse a String using Stack 336 225 Maximum Subarray Leetcode Solution 335 226 Convert string1 to string2 in one edit 334 227 Nth Character in Concatenated Decimal String 334 228 wildcard character matching 333 229 Can we reverse a linked list in less than O(n) time ? 333 230 Count the number of words 332 231 Binary Tree to Doubly linked list 330 232 Lower Case To Upper Case 329 233 Sort Elements by Frequency II 327 234 Merge Two Sorted Arrays 324 235 Split Four Distinct Strings 323 236 Find the Lost Element From a Duplicated Array 322 237 Matrix Chain Multiplication using Dynamic Programming 319 238 Find middle of the Linked List 319 239 Longest Common Subsequence with Permutations 318 240 Count the Pairs at Same Distance as in English Alphabets 315 241 Next Greater Element in an Array 308 242 Roman to Integer Leetcode Solution 308 243 Palindrome Permutation 302 244 Find Nth Node 297 245 Find All Pairs With a Given Difference 297 246 Word Search Leetcode Solution 295 247 Searching a node in a Binary Search Tree 295 248 String(represents an integer) to value 292 249 Triplet from three linked lists with given sum 291 250 Print all Possible Ways to Break a String in Bracket Form 290 251 Delete a Tree 290 252 Toeplitz Matrix 290 253 Reverse a String 289 254 Count Pairs With Given Sum 289 255 How to Efficiently Implement k Stacks in a Single Array? 288 256 N queen problem 288 257 Reverse Bits 287 258 Delete a node under given conditions 286 259 Sort an array of strings 286 260 Change Gender of a given String 286 261 First non Repeating Element 284 262 Binary Tree 284 263 Number of sub-strings which recursively add up to 9 284 264 Move all negative elements to one side of array 282 265 Repeated Substring Pattern 281 266 Meeting Rooms II LeetCode Solution 280 267 Number of Islands LeetCode Solution 279 268 Longest Common Extension 278 269 Longest Palindromic Substring LeetCode Solution 277 270 Min Stack 276 271 Remove spaces from a string 275 272 Remove middle points in a linked list of line segments 274 273 Shuffle a given Array 273 274 Most Frequent Element in an Array 272 275 Dijkstra Algorithm 271 276 Fibonacci numbers 268 277 House Robber Leetcode Solution 268 278 Sudoku Solver 267 279 Cuckoo sequence program 267 280 Find, second, frequent, character 267 281 Minimize the maximum difference between the heights 266 282 Max stack 264 283 Word Search 264 284 Expression Evaluation 263 285 KMP Algorithm 261 286 Search Insert Position Leetcode Solution 260 287 Subset Leetcode 258 288 Number Of 1 bits 258 289 Sort linked which is sorted on absolute values 258 290 Plus One Leetcode Solution 257 291 Clone a linked list with next and random pointer (Hashing) 257 292 Valid Palindrome Leetcode Solution 256 293 Combination Sum Leetcode Solution 255 294 Min Stack Leetcode Solution 255 295 Evaluation of Postfix Expression 255 296 Reverse words in a string 254 297 Set Matrix Zeroes 249 298 Merge Sorted Arrays Leetcode Solution 249 299 Backspace String Compare 249 300 How to Delete a Linked List 248 301 Pair of Positive Negative Values in an Array 247 302 Subarray with 0 sum 246 303 Rabin Karp Algorithm 245 304 Reversing a Queue 244 305 Common elements in all rows of a given matrix 244 306 Delete middle element of a stack 243 307 Count of index pairs with equal elements in an array 242 308 Contains Duplicate II Leetcode Solution 241 309 Sqrt(x) Leetcode Solution 240 310 Combination Sum 240 311 Intersection of Two Arrays II Leetcode Solution 239 312 Tower Of Hanoi 239 313 Pascal Triangle Leetcode 238 314 Find Top K (or Most Frequent) Numbers in a Stream 237 315 Product of array except self 236 316 Reverse individual words 235 317 String Compression 235 318 Sliding Window Technique 235 319 Integer to Roman Leetcode Solution 235 320 Count subarrays with equal number of 1's and 0's 234 321 Second Most Repeated Word in a Sequence 234 322 Page Replacement Algorithms in Operating Systems 234 323 Contains Duplicate 234 324 Minimum swaps required to bring all elements less than or equal to k together 233 325 Implementation of Deque using Doubly Linked List 233 326 Segregate even and odd numbers 233 327 Construct Binary Tree from Given Inorder and Preorder Traversals 232 328 Single Number Leetcode Solution 231 329 Count Odd Numbers in an Interval Range Leetcode Solution 231 330 Add Binary Leetcode Solution 230 331 K-th Smallest Element in a Sorted Matrix 229 332 Group Words With Same Set of Characters 229 333 Smallest Subarray with k Distinct Numbers 229 334 Bellman Ford Algorithm 229 335 Pow(x, n) Leetcode Solution 228 336 Arithmetic Expression Evaluation 228 337 Maximum Number of Balloons Leetcode Solution 228 338 Kruskal Algorithm 228 339 Minimum Value to Get Positive Step by Step Sum Leetcode Solution 228 340 Palindrome Linked List Leetcode Solution 227 341 Design a stack that supports getMin() in O(1) time and O(1) extra space 227 342 Postfix to Infix Conversion 227 343 Next Permutation 227 344 Sort elements by frequency 227 345 Find sum of non-repeating elements (distinct) elements in an array 226 346 Sum of minimum and maximum elements of all subarrays of size k 226 347 Longest Common Prefix Leetcode Solution 225 348 Majority Element Leetcode Solution 224 349 Find Lucky Integer in an Array Leetcode Solution 224 350 Minimum operation to make all elements equal in array 224 351 Top K Frequent Words 223 352 Swap Nodes in Pairs Leetcode Solutions 222 353 Given two unsorted arrays find all pairs whose sum is x 222 354 Evaluate Division 222 355 Sorting array using Stacks 221 356 Scramble String 221 357 Third Maximum Number Leetcode Solution 220 358 Convex Hull Algorithm 220 359 Count subarrays having total distinct elements same as original array 220 360 Permutations Leetcode Solution 220 361 Longest Substring Without Repeating Characters LeetCode Solution 220 362 Find Numbers with Even Number of Digits Leetcode Solution 220 363 Maximum Subarray 219 364 First element occurring k times in an array 219 365 Minimum Steps to reach target by a Knight 219 366 Special Number 218 367 Number of Good Pairs Leetcode Solution 218 368 Spiral Matrix LeetCode Solution 217 369 Prefix to Infix Conversion 217 370 Maximal Square 217 371 Reverse a Number Using Stack 217 372 Check if two arrays are equal or not 216 373 Minimum Path Sum 216 374 Range Sum Query 2D – Immutable Leetcode Solution 215 375 Reversing the First K elements of a Queue 215 376 Find the Town Judge Leetcode Solution 215 377 Maximum possible difference of two subsets of an array 214 378 Find duplicates in a given array when elements are not limited to a range 214 379 Huffman Coding 213 380 Pascal's Triangle II Leetcode Solution 213 381 Merge Two Sorted Lists Leetcode Solutions 213 382 Minimum Absolute Difference Leetcode Solution 213 383 Fizz Buzz Leetcode 213 384 Power of Two Leetcode Solution 213 385 Missing Number Leetcode Solution 213 386 Single Number 213 387 Search in Rotated Sorted Array Leetcode Solution 212 388 Count Primes Leetcode Solutions 212 389 Sort Array by Increasing Frequency Leetcode Solution 212 390 Leetcode Permutations 212 391 Running Sum of 1d Array Leetcode Solution 212 392 Group Anagrams 212 393 Find the Closest Palindrome number 211 394 Expression Contains Redundant Bracket or Not 211 395 Maximum Depth of Binary Tree Leetcode Solution 211 396 Top K Frequent Elements 210 397 Implement Stack and Queue using Deque 210 398 Find Number of Employees Under every Employee 210 399 Palindrome Substring Queries 210 400 Unique Paths Leetcode Solution 209 401 Convert String To Int 209 402 Find the first repeating element in an array of integers 209 403 Check if Array Contains Contiguous Integers With Duplicates Allowed 209 404 Best Time to Buy and Sell Stock  II Leetcode Solution 209 405 Sorting using trivial hash function 209 406 Average Salary Excluding the Minimum and Maximum Salary Leetcode Solution 209 407 Find All Numbers Disappeared in an Array Leetcode Solution 209 408 Maximum Distance Between two Occurrences of Same Element in Array 209 409 Bipartite Graph 209 410 House Robber II Leetcode Solution 209 411 Subset sum problem 209 412 Cumulative Frequency of Count of Each Element in an Unsorted Array 209 413 Unique Paths 208 414 Find top three repeated in array 208 415 Zigzag Conversion 208 416 How to Implement Stack Using Priority Queue or Heap? 208 417 Happy Number Leetcode Solution 207 418 Find Minimum In Rotated Sorted Array 207 419 Coin Change 2 Leetcode Solution 207 420 Prim's Algorithm 207 421 Subarray Sum Equals k 207 422 Find Winner on a Tic Tac Toe Game Leetcode Solution 207 423 Length of the largest subarray with contiguous elements 207 424 Print All Distinct Elements of a Given Integer Array 207 425 Letter Case Permutation 207 426 Remove Minimum Number of Elements Such That no Common Element Exist in both Array 206 427 Matrix Diagonal Sum Leetcode Solution 206 428 Subarray Sum Equals K LeetCode Solution 206 429 Subarrays with distinct elements 205 430 Smallest Element Repeated Exactly K Times 205 431 Find Median from data Stream 205 432 Max Consecutive Ones Leetcode Solution 205 433 Sort Integers by The Number of 1 Bit Leetcode Solution 205 434 Difference between highest and least frequencies in an array 205 435 LRU Cache Implementation 205 436 Count Substrings with equal number of 0s, 1s and 2s 205 437 Best Time to Buy and Sell Stock III Leetcode Solution 204 438 Decode String 204 439 How Many Numbers Are Smaller Than the Current Number Leetcode Solution 204 440 Find all pairs (a, b) in an array such that a % b = k 204 441 Print all subarrays with 0 sum 203 442 Check If N and Its Double Exist Leetcode Solution 203 443 Capacity To Ship Packages Within D Days Leetcode Solution 203 444 Sort a stack using recursion 203 445 Remove Duplicates from Sorted Array Leetcode Solution 202 446 Reverse a Stack Using Recursion 202 447 Fibonacci Number LeetCode Solution 202 448 Fizz Buzz 202 449 Nth Catalan Number 202 450 Reverse a linked list 201 451 Count pairs from two linked lists whose sum is equal to a given value 201 452 Monotonic Array LeetCode Solution 201 453 Reverse Integer 201 454 Find Common Characters Leetcode Solution 201 455 Edit Distance 201 456 Subtract the Product and Sum of Digits of an Integer Leetcode Solution 201 457 Find The Duplicate Number 200 458 Generate a String With Characters That Have Odd Counts Leetcode Solution 200 459 Delete a Node from linked list without head pointer 200 460 Reverse Vowels of a String Leetcode Solution 200 461 Kth largest element in an Array Leetcode Solutions 199 462 Trapping Rain Water Leetcode Solution 199 463 Reverse a String 199 464 Find the Difference Leetcode Solution 199 465 Find elements which are present in first array and not in second 199 466 The K Weakest Rows in a Matrix Leetcode Solution 199 467 Shortest Palindrome 198 468 Longest Common Prefix using Trie 198 469 Target Sum 198 470 Count and Say 198 471 Iterative Tower of Hanoi 198 472 Sum of Subarray Ranges Leetcode Solution 198 473 Find distinct elements common to all rows of a matrix 198 474 Longest subarray not having more than K distinct elements 198 475 Integer to English words 198 476 Excel Sheet Column Number Leetcode Solution 198 477 Find the Duplicate Element 197 478 Balanced Binary Tree Leetcode Solution 197 479 Priority Queue Using Singly Linked List 197 480 Top View of Binary Tree 197 481 Merge Two Sorted Linked Lists 197 482 Text Justification LeetCode Solution 197 483 MiniMax Algorithm 197 484 Degree of an array 197 485 Floyd Warshall Algorithm 197 486 Design Parking System Leetcode Solution 197 487 Slowest Key Leetcode Solution 197 488 Flood Fill LeetCode 197 489 Shuffle String Leetcode Solution 196 490 Word Ladder LeetCode Solution 196 491 Next Greater Element I Leetcode Solution 196 492 Find Index of Closing Bracket for a Given Opening Bracket in an Expression 196 493 Iterative Inorder Traversal of a Binary Tree 196 494 Prefix to Postfix Conversion 196 495 Sorting a Queue without Extra Space 196 496 Concatenation of Array LeetCode Solution 196 497 Find any one of the multiple repeating elements in read only array 195 498 Shuffle the Array Leetcode Solution 195 499 Reverse Words in a String III LeetCode Solution 195 500 Find First and Last Position of Element in Sorted Array Leetcode Solution 194 501 Jump Game Leetcode Solution 194 502 Minimum Moves to Equal Array Elements Leetcode Solution 194 503 Priority Queue in C++ 194 504 Valid Parenthesis String 194 505 Max Area of Island 194 506 Pair with given product 194 507 Number of Steps to Reduce a Number to Zero Leetcode Solution 194 508 Longest Common Subsequence 194 509 Substring With Concatenation Of All Words 194 510 Postfix to Prefix Conversion 193 511 Multiply Strings Leetcode Solution 193 512 Rearrange a binary string as alternate x and y occurrences 193 513 Count and Say Leetcode Solution 193 514 Find missing elements of a range 193 515 Find four elements that sum to a given value (Hashmap) 193 516 Find subarray with given sum (Handles Negative Numbers) 192 517 Implement a stack using single queue 192 518 Merge Overlapping Intervals 192 519 K-th Distinct Element in an Array 192 520 Check if a given array contains duplicate elements within k distance from each other 192 521 Zigzag Conversion LeetCode Solution 191 522 Kids With the Greatest Number of Candies Leetcode Solution 191 523 Check for Balanced Parentheses in an Expression 191 524 Arrange given numbers to form the biggest number 191 525 Recursion 191 526 Kth Largest Element in a Stream Leetcode Solution 191 527 Next Greater Frequency Element 191 528 Implement Stack using Queues 190 529 Convert array into Zig-Zag fashion 190 530 Longest Common Prefix using Sorting 190 531 The Stock Span Problem 190 532 Move Zeroes LeetCode Solution 190 533 Peak Index in a Mountain Array 190 534 Smallest Subarray With all Occurrences of a Most Frequent Element 190 535 Mobile Numeric Keypad Problem 190 536 Intersection of Two Arrays 190 537 Minimum Bracket Reversals 190 538 Count number of triplets with product equal to given number 189 539 Length of Last Word Leetcode Solution 189 540 Minimum Delete Operations to make all Elements of Array Same 189 541 Shuffle an Array 189 542 Find N Unique Integers Sum up to Zero Leetcode Solution 189 543 Isomorphic Strings Leetcode Solution 189 544 Container with Most Water 188 545 First negative integer in every window of size k 188 546 Koko Eating Bananas Leetcode Solution 188 547 Largest Sum Contiguous Subarray 188 548 Valid Sudoku 188 549 Excel Sheet Column Title Leetcode Solution 187 550 Change the Array into Permutation of Numbers From 1 to N 187 551 Convert a normal BST to Balanced BST 187 552 Delete Node in a Linked List Leetcode Solution 187 553 Distribute Candies to People Leetcode Solution 187 554 Sum of Left Leaves Leetcode Solutions 187 555 Largest Perimeter Triangle Leetcode Solution 187 556 Last Stone Weight 187 557 Linked List Cycle II LeetCode Solution 187 558 Minimum Knight Moves LeetCode Solution 187 559 Island Perimeter Leetcode Solution 186 560 Count the number of nodes at given level in a tree using BFS 186 561 Gold Mine Problem 186 562 Valid Anagrams 186 563 Is Subsequence Leetcode Solution 186 564 Find Words That Can Be Formed by Characters Leetcode Solution 186 565 Best Time to Buy and Sell Stock 186 566 Contiguous Array Leetcode 186 567 The Knapsack Problem 185 568 Maximum sum rectangle in a 2D matrix 185 569 Build Array From Permutation Leetcode Solution 185 570 Group Multiple Occurrence of Array Elements Ordered by first Occurrence 185 571 Number of Provinces Leetcode Solution 185 572 Hamming Distance 185 573 Find Sum of all unique sub-array sum for a given array 184 574 How to check if two given sets are disjoint? 184 575 N-th Tribonacci Number Leetcode Solution 184 576 3Sum Closest LeetCode Solution 184 577 Integer to Roman 184 578 Minimum Operations to convert X to Y 183 579 Summary Ranges Leetcode Solution 183 580 Remove Linked List Elements Leetcode Solution 183 581 Convert Sorted Array to Binary Search Tree Leetcode Solution 183 582 Assign Cookies Leetcode Solution 183 583 Implementation of Deque using circular array 183 584 Combinations Leetcode Solution 183 585 Find if an Expression has Duplicate Parenthesis or Not 183 586 Decode Ways 182 587 Relative Sort Array Leetcode Solution 182 588 Maximum difference between first and last indexes of an element in array 182 589 Minimum number of subsets with distinct elements 182 590 01 Matrix LeetCode Solution 182 591 Jewels and Stones Leetcode Solution 182 592 Shortest Path in a Grid with Obstacles Elimination LeetCode Solution 182 593 Unique Binary Search Trees 182 594 Maximum path sum in a triangle 182 595 Count all subsequences having product less than K 182 596 Sieve of Eratosthenes 182 597 Maximum Distance in Array 182 598 Longest Increasing Subsequence 181 599 Find minimum difference between any two elements 181 600 Sort Characters By Frequency LeetCode Solution 180 601 Trapping Rain Water LeetCode Solution 180 602 Maximum Number of Occurrences of a Substring Leetcode Solution 180 603 Bubble sort using two Stacks 180 604 Rotate List Leetcode Solution 180 605 LRU Cache LeetCode Solution 180 606 Find the smallest positive integer value that cannot be represented as sum of any subset of a given array 179 607 Word Pattern 179 608 Rotate Image LeetCode Solution 179 609 How to Create Mergable Stack? 179 610 Insert Interval Leetcode Solution 179 611 Minimum number of distinct elements after removing m items 179 612 Distance Between Bus Stops Leetcode Solution 178 613 Same Tree LeetCode Solution 178 614 Word Wrap Problem 178 615 Minimum Cost to Hire K Workers 178 616 Reverse a stack without using extra space in O(n) 178 617 XOR Operation in an Array Leetcode Solution 178 618 Remove All Occurrences of a Substring LeetCode Solution 178 619 Minimum Number of Steps to Make Two Strings Anagram Leetcode Solutions 178 620 Tracking current Maximum Element in a Stack 178 621 Permutation in String Leetcode Solution 178 622 Check if a queue can be sorted into another queue using a stack 177 623 Iterative Method to find Height of Binary Tree 177 624 Non-overlapping sum of two sets 177 625 Check If It Is a Straight Line Leetcode Solution 177 626 Smallest Good Base 177 627 House Robber 177 628 Applications of Breadth First Search and Depth First Search 177 629 Minimum insertions to form a palindrome with permutations allowed 177 630 Printing brackets in Matrix Chain Multiplication Problem 176 631 Maximum Number of Chocolates to be Distributed Equally Among k Students 176 632 Maximum Consecutive Numbers Present in an Array 176 633 License Key Formatting Leetcode Solution 176 634 GCD Of Two Numbers 176 635 Kth Missing Positive Number Leetcode Solution 176 636 Isomorphic Strings 176 637 Delete consecutive same words in a sequence 176 638 Coin Change Problem 176 639 Frog Jump Leetcode Solution 176 640 Find Largest d in Array such that a + b + c = d 175 641 Find the Duplicate Number LeetCode Solution 175 642 Defanging an IP Address Leetcode Solution 175 643 Valid Palindrome II Leetcode Solution 175 644 Strobogrammatic Number LeetCode Solution 175 645 Best Time to Buy and Sell Stock LeetCode Solution 175 646 Reducing Dishes LeetCode Solution 175 647 Optimal Account Balancing LeetCode Solution 175 648 Reorganize String 175 649 Sort Array By Parity LeetCode Solution 175 650 Minimum Depth of Binary Tree Leetcode Solution 174 651 Painting Fence Algorithm 174 652 Find the Distance Value Between Two Arrays Leetcode Solution 174 653 K Empty Slots LeetCode 174 654 Merge Two Balanced Binary Search Trees 174 655 Segregate 0s and 1s in an Array 174 656 Stone Game LeetCode 174 657 Longest Substring with At Most K Distinct Characters LeetCode Solution 173 658 Moving Average from Data Stream Leetcode Solution 173 659 Binary Tree Zigzag Level Order Traversal LeetCode Solution 173 660 Flipping an Image LeetCode Solution 173 661 Form minimum number from given sequence 173 662 Find Maximum Level sum in Binary Tree 173 663 Queries for counts of array elements with values in given range 173 664 Distance of nearest cell having 1 in a binary matrix 173 665 Replace Elements with Greatest Element on Right Side Leetcode Solution 173 666 Wiggle Sort 173 667 First Unique Character in a String LeetCode Solution 173 668 Longest Substring with At Least K Repeating Characters LeetCode Solution 172 669 Letter Combinations of a Phone Number 172 670 Reservoir Sampling 172 671 Longest Increasing Path in a Matrix LeetCode Solution 172 672 Sum of f(a[i], a[j]) over all pairs in an array of n integers 172 673 K Empty Slots 172 674 Find pairs with given sum such that elements of pair are in different rows 172 675 Convert an array to reduced form 172 676 Employee Free Time LeetCode Solution 172 677 Partition Labels LeetCode Solution 172 678 Find Pair with Greatest Product in Array 171 679 Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest 171 680 Maximum Product of Two Elements in an Array Leetcode Solution 171 681 Sum of All Odd Length Subarrays Leetcode Solution 171 682 Best Time to Buy and Sell Stock with Cooldown Leetcode Solution 171 683 Find the largest multiple of 3 171 684 BFS vs DFS for Binary Tree 170 685 Find the node with minimum value in a Binary Search Tree 170 686 Ugly Number Leetcode Solution 170 687 Valid Perfect Square Leetcode Solution 170 688 Print the Fibonacci numbers in reverse order 170 689 Number of Dice Rolls With Target Sum LeetCode Solution 170 690 Path With Maximum Minimum Value LeetCode Solution 170 691 Unique Paths II Leetcode Solution 170 692 Valid Palindrome 170 693 Partition Array Into Three Parts With Equal Sum Leetcode Solution 169 694 Power of Four Leetcode Solution 169 695 Snakes and Ladders LeetCode Solution 169 696 Populating Next Right Pointers in Each Node 169 697 Reverse Only Letters LeetCode Solution 169 698 Count Good Nodes in Binary Tree Leetcode Solution 169 699 Increasing Decreasing String Leetcode Solution 169 700 Recover Binary Search Tree 169 701 Lucky Numbers in a Matrix Leetcode Solution 169 702 Longest Span with same Sum in two Binary arrays 169 703 Reversing a Queue using Recursion 169 704 Find the Smallest Divisor given a Threshold Leetcode Solution 169 705 Inorder Successor of a node in Binary Tree 169 706 Factorial Trailing Zeroes Leetcode Solution 169 707 Subset Sum Leetcode 169 708 Check If Two String Arrays are Equivalent Leetcode Solution 169 709 Permutation Sequence LeetCode Solution 168 710 Robot Room Cleaner Leetcode Solution 168 711 Find Leaves of Binary Tree LeetCode Solution 168 712 Find whether an array is subset of another array 168 713 Non-decreasing Array LeetCode Solution 168 714 Dynamic Programming Basics 168 715 To Lower Case Leetcode Solution 168 716 Delete Nth node from the end of the given linked list 168 717 Check if Two Expressions With Brackets are Same 168 718 Construct BST from given Preorder Traversal 168 719 Sort Array by Increasing Frequency Leetcode Solution 168 720 Binary Tree zigzag level order Traversal 168 721 Maximum Number of Coins You Can Get Leetcode Solution 168 722 String to Integer (atoi) LeetCode Solution 167 723 String Compression LeetCode Solution 167 724 Largest Rectangle in Histogram LeetCode Solution 167 725 Remove Invalid Parentheses Leetcode Solution 167 726 Minimum Distance Between BST Nodes Leetcode Solution 167 727 Find Maximum Depth of Nested Parenthesis in a String 167 728 Convert a Number to Hexadecimal Leetcode Solution 167 729 Largest subarray with equal number of 0s and 1s 167 730 Find unique character in a string 167 731 Edit Distance LeetCode Solution 167 732 Generate all possible sorted arrays from alternate elements of two given sorted arrays 167 733 Count quadruples from four sorted arrays whose sum is equal to a given value x 166 734 Bulb Switcher LeetCode Solution 166 735 Numbers with prime frequencies greater than or equal to k 166 736 Rank Transform of an Array Leetcode Solution 166 737 Add and Search Word – Data structure design LeetCode 166 738 Morris Traversal 166 739 Binary Tree Maximum Path Sum LeetCode Solution 166 740 Student Attendance Record I Leetcode Solution 166 741 Majority Element II Leetcode Solution 166 742 Word Pattern LeetCode Solution 165 743 Race Car LeetCode Solution 165 744 Restore IP Addresses Leetcode Solution 165 745 Maximum Depth of N-ary Tree Leetcode Solution 165 746 Stack Permutations (Check if an array is stack permutation of other) 165 747 Maximum Product of Three Numbers LeetCode Solution 165 748 Minimum Cost For Tickets Leetcode Solution 165 749 Sorted Linked List to Balanced BST 164 750 Tiling Problem 164 751 Find All Duplicates in an Array LeetCode Solution 164 752 Perform String Shifts Leetcode 164 753 A Space Optimized DP solution for 0-1 Knapsack Problem 164 754 Merge Two Binary Trees LeetCode Solution 164 755 Number of NGEs to the Right 164 756 Best Meeting Point LeetCode Solution 164 757 Maximum Profit in Job Scheduling Leetcode Solution 164 758 Print a Binary Tree in Vertical Order 164 759 Invert Binary Tree LeetCode Solution 164 760 k-th missing element in increasing sequence which is not present in a given sequence 164 761 Hamming Distance Leetcode Solution 163 762 Diagonal Traversal of Binary Tree 163 763 Regular Expression Matching 163 764 Count items common to both the lists but with different prices 163 765 Keyboard Row Leetcode Solution 163 766 Finding K closest element 163 767 Total Numbers With no Repeated Digits in a Range 163 768 Maximum Length of a Concatenated String with Unique Characters Leetcode Solution 163 769 Queue based approach for first non-repeating character in a stream 163 770 Decompress Run-Length Encoded List Leetcode Solution 163 771 Minimize Maximum Pair Sum in Array LeetCode Solution 163 772 Growable array based stack 163 773 Evaluate Reverse Polish Notation LeetCode Solution 163 774 Remove brackets from an algebraic string containing + and – operators 163 775 Maximum 69 Number Leetcode Solution 163 776 Binomial Coefficient 163 777 Search in a Binary Search Tree Leetcode Solution 162 778 Jump Game 162 779 Given an Array of Pairs Find all Symmetric Pairs in it 162 780 Minimum time required to rot all oranges 162 781 Merge K Sorted Linked Lists 162 782 Program for Bridge and Torch problem 162 783 Minimum Height Trees 162 784 Valid Number 162 785 Nested List Weight Sum II LeetCode Solution 162 786 Deletion in a Binary Tree 162 787 Elements to be added so that all elements of a range are present in array 162 788 Find Median from Data Stream LeetCode Solution 162 789 Symmetric Tree Leetcode Solution 161 790 Find All Possible Recipes from Given Supplies LeetCode Solution 161 791 Course Schedule II – LeetCode 161 792 String comparison containing wildcards 161 793 Remove Duplicates from Sorted List LeetCode Solution 161 794 Check If Array Pairs Are Divisible by k LeetCode Solution 161 795 Longest Subarray Having Count of 1s One More than Count of 0s 161 796 Partition to K Equal Sum Subsets Leetcode Solution 161 797 Merge Sorted Array LeetCode Solution 161 798 Form Minimum Number From Given Sequence 161 799 Kth ancestor of a node in binary tree 160 800 Maximum Nesting Depth of the Parentheses Leetcode Solution 160 801 Find if Path Exists in Graph Leetcode Solution 160 802 Maximum Difference Between Increasing Elements LeetCode Solution 160 803 Top K Frequent Words LeetCode Solution 160 804 Subarray Product Less Than K LeetCode Solution 160 805 N-Queens LeetCode Solution 160 806 Crawler Log Folder Leetcode Solution 160 807 Circular Queue 160 808 Base 7 Leetcode Solution 160 809 One Edit Distance LeetCode Solution 160 810 Special Array With X Elements Greater Than or Equal X Leetcode Solution 160 811 Linked List Cycle 160 812 Check for Palindrome after every character replacement Query 160 813 Tree Traversal (Preorder, Inorder & Postorder) 159 814 Largest rectangular sub-matrix whose sum is 0 159 815 Check if an Array is Stack Sortable 159 816 Final Prices With a Special Discount in a Shop Leetcode Solution 159 817 Split a String in Balanced Strings Leetcode Solution 159 818 Can Place Flowers LeetCode Solution 159 819 Sort an array according to the order defined by another array 159 820 Priority Queue using doubly linked list 159 821 Last Stone Weight II LeetCode Solution 159 822 Number of Islands II LeetCode Solution 159 823 Brick Wall LeetCode Solution 159 824 Remove Nth Node From End of List Leetcode Solution 159 825 Minimum Swaps to Make Strings Equal Leetcode Solution 159 826 Search a 2D Matrix II Leetcode Solution 159 827 Number Complement Leetcode Solution 158 828 Check if stack elements are pairwise consecutive 158 829 Minimum sum of multiplications of n numbers 158 830 Maximum size subarray sum equals k 158 831 Interval Tree 158 832 Subset with sum divisible by m 158 833 Best Time to Buy and Sell Stock with Transaction Fee Leetcode Solution 158 834 Sort Colors 158 835 Identify and Mark Unmatched Parenthesis in an Expression 158 836 Transpose Graph 158 837 Minimum Time Visiting All Points Leetcode Solution 158 838 Iterative Preorder Traversal 158 839 Partition List Leetcode Solution 158 840 Minimum Number of Taps to Open to Water a Garden LeetCode Solution 158 841 Minimum Jumps to Reach Home LeetCode Solution 158 842 Balanced Expression with Replacement 158 843 Repeated Substring Pattern LeetCode Solution 158 844 Remove Duplicates from Sorted List II 158 845 LCS (Longest Common Subsequence) of three strings 157 846 Sort Array By Parity II Leetcode Solution 157 847 Reorder Data in Log Files LeetCode Solution 157 848 Missing Element in Sorted Array LeetCode Solution 157 849 Binary Search Tree Search and Insertion 157 850 Relative Ranks Leetcode Solution 157 851 Valid Parentheses Leetcode Solution 157 852 Find Maximum Sum Possible Equal Sum of Three Stacks 157 853 Nearest Exit from Entrance in Maze LeetCode Solution 157 854 Subsequence of Size K With the Largest Even Sum LeetCode Solution 157 855 Sum of nearest smaller and greater number 157 856 Minimum swaps to make sequences increasing 157 857 Find the subarray with least average 157 858 Permutation Coefficient 156 859 Check if a given array can represent Preorder Traversal of Binary Search Tree 156 860 Number of Days Between Two Dates LeetCode Solution 156 861 Insert Delete GetRandom 156 862 Convert BST to Min Heap 156 863 Alien Dictionary LeetCode Solution 156 864 Sorted Array to Balanced BST 156 865 Spiral Matrix II Leetcode Solution 156 866 Minimum number of jumps to reach end 156 867 Matrix Chain Multiplication 156 868 Minimum Sum Path in a Triangle 155 869 Count Distinct Elements in Every Window of Size K 155 870 Level order Traversal in Spiral Form 155 871 Friends Pairing Problem 155 872 Robot Bounded In Circle LeetCode Solution 155 873 Clone Graph LeetCode Solution 155 874 Get Maximum in Generated Array Leetcode Solution 155 875 Brightest Position on Street LeetCode Solution 155 876 Iterative Postorder Traversal Using Two Stacks 155 877 Count ways to reach the nth stair using step 1, 2 or 3 155 878 Diagonal Traverse LeetCode Solution 154 879 Find all triplets with zero sum 154 880 Lexicographical Numbers Leetcode Solution 154 881 Insert into a Binary Search Tree Leetcode Solution 154 882 Path with maximum average value 154 883 Find the Only Repetitive Element Between 1 to N-1 154 884 Trim a Binary Search Tree 154 885 Water Bottles Leetcode Solution 154 886 Time Based Key-Value Store LeetCode Solution 154 887 Range sum queries without updates 154 888 Delete And Earn 154 889 Design a Stack With Increment Operation Leetcode Solution 154 890 A program to check if a binary tree is BST or not 154 891 Make Two Arrays Equal by Reversing Sub-arrays Leetcode Solution 154 892 Check whether a given Binary Tree is Complete or not 154 893 An Interesting Method to generate Binary Numbers from 1 to n 154 894 Range LCM Queries 153 895 Check if the given array can represent Level Order Traversal of Binary Search Tree 153 896 Union and Intersection of two Linked Lists 153 897 Design Browser History LeetCode Solution 153 898 Count Negative Numbers in a Sorted Matrix LeetCode Solution 153 899 Alien Dictionary 153 900 Shortest Word Distance Leetcode Solution 153 901 Distinct adjacent elements in an array 153 902 Median of Two Sorted Arrays 153 903 Find all permuted rows of a given row in a matrix 153 904 Guess Number Higher or Lower II 153 905 Daily Temperatures Leetcode Solution 153 906 Count Subarrays with Same Even and Odd Elements 152 907 GCDs of given index ranges in an array 152 908 Construct Complete Binary Tree from its Linked List Representation 152 909 Dividing Array into Pairs With Sum Divisible by K 152 910 Rearrange an Array Such that arr[i] is equal to i 152 911 Sequences of given length where every element is more than or equal to twice of previous 152 912 Maximum Score After Splitting a String Leetcode Solution 152 913 Averages of Levels in Binary Tree 152 914 Guess Number Higher or Lower LeetCode Solution 152 915 Set Matrix Zeroes Leetcode Solution 152 916 Infix to Postfix 152 917 Least Number of Unique Integers after K Removals Leetcode Solution 152 918 Find Common Characters Leetcode Solution 152 919 Queue using Stacks 152 920 3 Sum 151 921 Analyze User Website Visit Pattern LeetCode Solution 151 922 Queries for GCD of all numbers of an array except elements in a given range 151 923 Three way partitioning of an array around a given range 151 924 Merge Two Sorted Lists Leetcode 151 925 Diagonal Traversal LeetCode Solution 151 926 Find distance between two nodes of a Binary Tree 151 927 My Calendar I LeetCode Solution 151 928 Lemonade Change Leetcode Solution 151 929 Destination City Leetcode Solution 151 930 BFS for Disconnected Graph 151 931 Number of Distinct Islands Leetcode Solution 151 932 Convert Sorted List to Binary Search Tree 151 933 Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i 151 934 Pattern Occurrences using Stack 151 935 K'th Largest Element in BST when modification to BST is not allowed 151 936 Vertical sum in a given binary tree 150 937 All Unique Triplets that Sum up to a Given Value 150 938 Sliding Window Maximum 150 939 Count subarrays where second highest lie before highest 150 940 Construct the Rectangle Leetcode Solution 150 941 Rearrange Spaces Between Words Leetcode Solution 150 942 Longest Palindromic Subsequence 149 943 Minesweeper LeetCode Solution 149 944 Maximum Product Subarray 149 945 Combination Sum IV LeetCode Solution 149 946 Strongly Connected Component 149 947 Number of Equivalent Domino Pairs Leetcode Solution 149 948 Intersection of Two Linked Lists LeetCode Solution 149 949 Spiral Matrix III LeetCode Solution 149 950 Largest area rectangular sub-matrix with equal number of 1's and 0's 149 951 Three Consecutive Odds Leetcode Solution 149 952 Minimum Height Trees LeetCode Solution 149 953 Reverse Nodes in K-Group 149 954 Split Array Into Consecutive Subsequences 148 955 Remove Duplicates from Sorted List II LeetCode Solution 148 956 Maximum Frequency Stack Leetcode Solution 148 957 Create Maximum Number 148 958 Maximum Subarray Sum Excluding Certain Elements 148 959 Valid Boomerang Leetcode Solution 148 960 Special Positions in a Binary Matrix Leetcode Solution 148 961 Construct BST from its given Level Order Traversal 148 962 Count Submatrices With All Ones LeetCode Solution 148 963 Binary array after M range toggle operations 148 964 Print Fibonacci sequence using 2 variables 148 965 Difference Array | Range update query in O(1) 148 966 Maximize Sum of Array after K Negations Leetcode Solution 148 967 Can Make Arithmetic Progression From Sequence Leetcode Solution 148 968 Check if any two intervals overlap among a given set of intervals 148 969 Climbing stairs 147 970 Depth First Search (DFS) for a Graph 147 971 Binary Tree Longest Consecutive Sequence LeetCode Solution 147 972 4Sum 147 973 Merging Intervals 147 974 Product of Array Except Self LeetCode Solution 147 975 Stone Game II Leetcode 147 976 Palindrome Partitioning Leetcode Solution 147 977 Count Primes in Ranges 146 978 Length of Longest Fibonacci Subsequence 146 979 Asteroid Collision LeetCode Solution 146 980 Serialize and Deserialize Binary Tree 146 981 Breadth First Search (BFS) for a Graph 146 982 Symmetric Tree 146 983 Unique Paths II 146 984 Find Maximum of Minimum for Every Window Size in a Given Array 146 985 Word Break 145 986 Sign of the Product of an Array LeetCode Solution 145 987 Shuffle 2n integers as a1-b1-a2-b2-a3-b3-..bn without using extra space 145 988 Palindrome Partitioning 145 989 Check If a Word Occurs As a Prefix of Any Word in a Sentence Leetcode Solution 145 990 Merge Sort 145 991 Largest Substring Between Two Equal Characters Leetcode Solution 145 992 Design Hit Counter LeetCode Solution 145 993 Kth Smallest Element in a BST Leetcode Solution 145 994 Longest subsequence such that difference between adjacents is one 144 995 K Closest Points to Origin Leetcode Solution 144 996 Available Captures for Rook Leetcode Solution 144 997 Number Of Longest Increasing Subsequence 144 998 Maximum length subsequence with difference between adjacent elements as either 0 or 1 144 999 Insertion in a Binary Tree 144 1000 Find number of pairs in an array such that their XOR is 0 144 1001 Binary Search Tree Delete Operation 144 1002 Largest divisible pairs subset 144 1003 Segment Tree 144 1004 String Matching in an Array Leetcode Solution 143 1005 Find Duplicate Subtrees 143 1006 Shortest Completing Word Leetcode Solution 143 1007 Collect maximum points in a grid using two traversals 143 1008 Find the Difference Leetcode Solution 143 1009 Level Order Traversal of Binary Tree 143 1010 Count pair with Given Sum 143 1011 The Maze III LeetCode Solution 143 1012 Boundary Traversal of binary tree 143 1013 Next Greater Element III LeetCode Solution 143 1014 Height of a generic tree from parent array 143 1015 Scramble String LeetCode Solution 143 1016 Longest Nice Substring LeetCode Solution 143 1017 Find the First Circular Tour that visits all the Petrol Pumps 143 1018 Find postorder traversal of BST from preorder traversal 143 1019 Kth Smallest Element in a Sorted Matrix LeetCode Solution 143 1020 Boolean Parenthesization Problem 143 1021 The Painter's Partition Problem 143 1022 Bitwise AND of Numbers Range LeetCode Solution 142 1023 Newman-Conway Sequence 142 1024 Maximum Product of Indexes of Next Greater on Left and Right 142 1025 Compute nCr % p 142 1026 Validate Binary Search Tree 142 1027 Minimum Index Sum of Two Lists 142 1028 Maximum Sum of 3 Non-Overlapping Subarrays 142 1029 Count pairs from two sorted arrays whose sum is equal to a given value x 142 1030 Print Right View of a Binary Tree 142 1031 Level order traversal using two Queues 142 1032 Maximum subsequence sum such that no three are consecutive 142 1033 Iterative Depth First Traversal of Graph 142 1034 Construction of Longest Increasing Subsequence (N log N) 142 1035 Graph Valid Tree LeetCode Solution 142 1036 Decrypt String from Alphabet to Integer Mapping Leetcode Solution 142 1037 Rearrange array such that even positioned are greater than odd 142 1038 Maximum Number of Ways to Partition an Array LeetCode Solution 142 1039 Number of palindromic paths in a matrix 142 1040 Largest Number Leetcode Solution 142 1041 Maximum Length of Repeated Subarray 142 1042 Kill Process LeetCode Solution 141 1043 Friends Of Appropriate Ages LeetCode Solution 141 1044 Build an Array With Stack Operations Leetcode Solution 141 1045 Balanced Binary Tree 141 1046 First missing positive 141 1047 Advantages of BST over Hash Table 141 1048 Next Permutation Leetcode Solution 141 1049 Defanging an IP Address LeetCode Solution 141 1050 Binary Search Tree 141 1051 Maximum difference between frequency of two elements such that element having greater frequency is also greater 141 1052 Print Next Greater Number of Q queries 141 1053 Path Sum II LeetCode Solution 140 1054 Minimum Size Subarray Sum 140 1055 Morris Inorder Traversal 140 1056 Rearrange array such that even index elements are smaller and odd index elements are greater 140 1057 Make The String Great Leetcode Solution 140 1058 Consecutive Characters LeetCode Solution 140 1059 Ugly Numbers 140 1060 Add two numbers 140 1061 Construct Binary Tree from given Parent Array representation 140 1062 Partition Equal Subset Sum 140 1063 K maximum sums of overlapping contiguous sub-arrays 140 1064 Populating Next Right Pointers in Each Node Leetcode Solution 140 1065 Maximum weight transformation of a given string 140 1066 Find whether a subarray is in form of a mountain or not 139 1067 Lowest Common Ancestor 139 1068 Invalid Transactions LeetCode Solution 139 1069 Regular Expression Matching Regular Expression Matching LeetCode Solution 139 1070 Rearrange an array such that 'arr[j]' becomes 'i' if 'arr[i]' is 'j' 139 1071 Move all negative elements to end in order with extra space allowed 139 1072 Double the first element and move zero to end 139 1073 Find a Peak Element II LeetCode Solution 139 1074 Divisible Pairs Counting 138 1075 Super Ugly Number 138 1076 Ugly Number II LeetCode Solution 138 1077 Count minimum steps to get the given desired array 138 1078 Path Sum 138 1079 Custom Sort String Leetcode Solution 138 1080 Remove Duplicates from Sorted Array II Leetcode Solution 138 1081 Determine Whether Matrix Can Be Obtained By Rotation LeetCode Solution 138 1082 Implement Trie (Prefix Tree) Leetcode Solution 137 1083 Remove Palindromic Subsequences Leetcode Solution 137 1084 Increasing Triplet Subsequence LeetCode Solution 137 1085 Number of siblings of a given Node in n-ary Tree 137 1086 Search in Sorted Rotated Array 137 1087 Recover Binary Search Tree Leetcode Solution 137 1088 Types of Binary Tree 137 1089 Employee Importance LeetCode Solution 137 1090 Generate Parentheses Leetcode Solution 137 1091 Valid Tic-Tac-Toe State LeetCode Solution 137 1092 Kth Smallest Product of Two Sorted Arrays LeetCode Solution 136 1093 Find Peak Element 136 1094 Longest Bitonic Subsequence 136 1095 Third Maximum Number Leetcode Solution 136 1096 Maximize Distance to Closest Person LeetCode Solution 136 1097 Day of the Year Leetcode Solution 136 1098 Binary Tree Right Side View LeetCode Solution 136 1099 Queries for Number of Distinct Elements in a Subarray 136 1100 Largest BST Subtree LeetCode Solution 136 1101 Find the minimum distance between two numbers 135 1102 Construct Binary Tree from Preorder and Postorder Traversal LeetCode Solution 135 1103 Print all triplets in sorted array that form AP 135 1104 Root to Leaf path with target sum Leetcode Solutions 135 1105 Subarrays with K Different Integers Leetcode Solution 135 1106 Binary Tree Data Structure 135 1107 Serialize and Deserialize Binary Tree LeetCode Solution 135 1108 Number of Closed Islands Leetcode Solution 135 1109 Palindrome Permutation LeetCode Solution 135 1110 Distinct Subsequences 135 1111 Smallest Common Region Leetcode Solution 135 1112 Minimum sum of squares of character counts in a given string after removing k characters 134 1113 Longest Subarray of 1's After Deleting One Element LeetCode Solution 134 1114 Find Smallest Range Containing Elements from k Lists 134 1115 Reformat The String Leetcode Solution 134 1116 Number of Students Doing Homework at a Given Time Leetcode Solution 134 1117 Clone a Binary Tree with Random Pointers 134 1118 Find Three Element From Different Three Arrays Such That a + b + c = sum 134 1119 Level of Each node in a Tree from source node 134 1120 Longest Increasing Consecutive Subsequence 134 1121 Convert BST into a Min-Heap without using array 134 1122 Find maximum difference between nearest left and right smaller elements 134 1123 Cutting a Rod 133 1124 Remove duplicates from sorted array 133 1125 Mean of Array After Removing Some Elements Leetcode Solution 133 1126 Search Insert Position 133 1127 Count Largest Group Leetcode Solution 133 1128 Sum of Even Numbers After Queries 133 1129 Iterative method to find ancestors of a given binary tree 133 1130 Swap Nodes In Pairs 133 1131 Minimum Absolute Difference in BST Leetcode Solution 132 1132 Products of ranges in an array 132 1133 Constant time range add operation on an array 132 1134 Construct K Palindrome Strings LeetCode Solution 132 1135 Bottom View of a Binary Tree 132 1136 Write Code to Determine if Two Trees are Identical 132 1137 Print modified array after executing the commands of addition and subtraction 132 1138 Maximize sum of consecutive differences in a circular array 131 1139 Thousand Separator Leetcode Solution 131 1140 Minimum Score Triangulation of Polygon Leetcode Solution 131 1141 Priority Queue 131 1142 Red-Black Tree Introduction 131 1143 Maximum Product Subarray 131 1144 Cells with Odd Values in a Matrix LeetCode Solution 131 1145 Prime Palindrome LeetCode Solution 131 1146 Find maximum length Snake sequence 131 1147 Topological Sorting 131 1148 Search an Element in Sorted Rotated Array 130 1149 Palindromic Substrings Leetcode Solution 130 1150 Count even length binary sequences with same sum of first and second half bits 130 1151 Delete Nodes and Return Forest Leetcode Solution 130 1152 Possible Bipartition LeetCode Solution 130 1153 Moser-de Bruijn Sequence 130 1154 Count Pairs Whose Products Exist in Array 130 1155 Maximum Product of Splitted Binary Tree LeetCode Solution 129 1156 Bus Routes Leetcode Solution 129 1157 Closest Binary Search Tree Value Leetcode Solution 129 1158 Diameter of N-Ary Tree LeetCode Solution 129 1159 Rotate Array 129 1160 Find a sorted subsequence of size 3 in linear time 129 1161 Transform a BST to Greater sum Tree 129 1162 Binary Tree to Binary Search Tree Conversion 129 1163 Check Array Formation Through Concatenation Leetcode Solution 129 1164 Maximum Binary Tree 129 1165 Compare Strings by Frequency of the Smallest Character Leetcode Solution 129 1166 Golomb sequence 129 1167 Decision Tree 129 1168 Subset Sum Problem in O(sum) space 129 1169 Minimum Cost to Move Chips to The Same Position LeetCode Solution 129 1170 Merge two BSTs with limited extra space 129 1171 Find Two Non-overlapping Sub-arrays Each With Target Sum LeetCode Solution 128 1172 Contiguous Array LeetCode Solution 128 1173 Longest Repeated Subsequence 128 1174 Kth Smallest Number in Multiplication Table Leetcode Solution 128 1175 Remove Max Number of Edges to Keep Graph Fully Traversable Leetcode Solution 128 1176 Web Crawler LeetCode Solution 128 1177 K'th Largest element in BST using constant extra space 127 1178 Reverse a Path in BST using Queue 127 1179 Find Largest Value in Each Tree Row LeetCode Solution 127 1180 Search Suggestions System LeetCode Solution 127 1181 Given a binary tree, how do you remove all the half nodes? 127 1182 Minimum Sideway Jumps LeetCode Solution 127 1183 Factorial Trailing Zeroes LeetCode Solution 127 1184 Decrease Elements To Make Array Zigzag LeetCode Solution 126 1185 Minimum Swaps To Make Sequences Increasing LeetCode Solution 126 1186 Number of Orders in the Backlog Leetcode Solution 126 1187 First Bad Version 126 1188 How to print maximum number of A's using given four keys 126 1189 Valid Triangle Number 126 1190 Maximum number of segments of lengths a, b and c 126 1191 Find the smallest binary digit multiple of given number 126 1192 New 21 Game 125 1193 Closest Leaf in a Binary Tree LeetCode Solution 125 1194 Lowest Common Ancestor in Binary Search Tree 125 1195 Reformat Date LeetCode Solution 125 1196 Minimum Moves to Equal Array Elements LeetCode Solution 125 1197 Valid Perfect Square LeetCode Solution 125 1198 Guess The Word 125 1199 Maximum Depth Of Binary Tree 125 1200 Matchsticks to Square Leetcode Solution 125 1201 Graph and its representation 124 1202 Filter Restaurants by Vegan-Friendly, Price and Distance Leetcode Solution 124 1203 Array Queries for multiply replacements and product 124 1204 Sum of Left Leaves LeetCode Solution 124 1205 Convert Sorted Array to Binary Search Tree LeetCode Solutions 124 1206 Concatenation of Array LeetCode Solution 124 1207 Swapping Nodes in a Linked List Leetcode Solution 124 1208 Queue Reconstruction by Height 124 1209 Range Queries for Longest Correct Bracket Subsequence 123 1210 Maximum sum bitonic subarray 123 1211 Divide Two Integers Leetcode Solution 123 1212 Replace two consecutive equal values with one greater 123 1213 Champagne Tower LeetCode Solution 123 1214 Moving Stones Until Consecutive Leetcode Solution 123 1215 Range Sum Query using Sparse Table 122 1216 Queries on Probability of Even or Odd Number in given Ranges 122 1217 Path Crossing Leetcode Solution 122 1218 Maximum Value at a Given Index in a Bounded Array LeetCode Solution 122 1219 Perfect Squares LeetCode Solution 122 1220 Maximum sum of pairs with specific difference 122 1221 Maximum sum of a path in a Right Number Triangle 122 1222 Arithmetic Slices II – Subsequence LeetCode Solution 122 1223 Kth Smallest Element in a BST 122 1224 Lowest Common Ancestor of a Binary Tree Leetcode Solution 122 1225 Write a function to get the intersection point of two Linked Lists 122 1226 Print n terms of Newman-Conway Sequence 122 1227 Missing Number 122 1228 Flatten 2D Vector LeetCode Solution 121 1229 Integer Break LeetCode Solution 121 1230 BST to a Tree with Sum of all Smaller Keys 121 1231 Longest Common Prefix Using Word by Word Matching 121 1232 Convert Integer to the Sum of Two No-Zero Integers Leetcode Solution 120 1233 LRU Cache Leetcode Solution 120 1234 Check if all levels of two Binary Tree are anagrams or not 120 1235 Mean of range in array 120 1236 Print modified array after multiple array range increment operations 120 1237 Design Skiplist LeetCode Solution 120 1238 Largest Plus Sign Leetcode Solution 120 1239 Graph Cloning 120 1240 The kth Factor of n Leetcode Solution 119 1241 Sliding Window Median Leetcode Solution 119 1242 Count Subsets Having Distinct Even Numbers 119 1243 Power of Two 119 1244 Merge k Sorted Lists Leetcode Solution 119 1245 Find minimum number of merge operations to make an array palindrome 118 1246 Bold Words in String LeetCode Solution 118 1247 Verify Preorder Serialization of a Binary Tree 118 1248 Parallel Courses II LeetCode Solution 118 1249 Check Completeness of a Binary Tree LeetCode Solution 118 1250 Find Minimum in Rotated Sorted Array II LeetCode Solution 118 1251 Maximum Sum Increasing Subsequence 118 1252 Maximize Elements Using Another Array 118 1253 Check for Identical BSTs without building the trees 118 1254 Maximum Array from Two given Arrays Keeping Order Same 118 1255 Contiguous Array 118 1256 Check if each internal node of a BST has exactly one child 118 1257 Image Overlap LeetCode Solution 117 1258 Maximum Product Subarray 117 1259 Minimum Remove to Make Valid Parentheses LeetCode Solution 117 1260 Symmetric Tree LeetCode Solution Leetcode Solution 117 1261 Print Ancestors of a Given Binary Tree Node Without Recursion 116 1262 Min Cost Climbing Stairs LeetCode Solution 116 1263 Find k-th smallest element in BST (Order Statistics in BST) 116 1264 Excel Sheet Column Title LeetCode Solution 115 1265 Minimum Time to Collect All Apples in a Tree LeetCode Solution 115 1266 Next greater element 115 1267 Orderly Queue LeetCode Solution 114 1268 Count and Toggle Queries on a Binary Array 114 1269 Smallest Range II Leetcode Solution 114 1270 Check if two nodes are on the same path in a Tree 114 1271 Merge Sorted Array 113 1272 Check in binary array the number represented by a subarray is odd or even 113 1273 Palindrome Partitioning 113 1274 Different Ways to Add Parentheses Leetcode Solution 113 1275 Check If a String Can Break Another String Leetcode Solution 112 1276 Range Minimum Query (Square Root Decomposition and Sparse Table) 112 1277 Koko Eating Bananas LeetCode Solution 111 1278 Number of elements less than or equal to a given number in a given subarray 111 1279 Largest Submatrix With Rearrangements LeetCode Solution 110 1280 Array Nesting Leetcode Solution 110 1281 Find maximum average subarray of k length 110 1282 Newman–Shanks–Williams prime 109 1283 Check if X can give change to every person in the Queue 109 1284 Longest Substring Without Repeating Characters Leetcode Solution 109 1285 Peeking Iterator LeetCode Solution 109 1286 Queries for Decimal Values of Subarrays of a Binary Array 108 1287 Check given array of size n can represent BST of n levels or not 108 1288 Arranging Coins Leetcode Solution 107 1289 Encoded String With Shortest Length LeetCode Solution 107 1290 Maximum product of an increasing subsequence 106 1291 Number of indexes with equal elements in given range 106 1292 Palindrome Number LeetCode Solution 105 1293 Vertical Order Traversal of Binary Tree LeetCode Solution 104 1294 Random Pick Index LeetCode Solution 104 1295 Convert a BST to a Binary Tree such that sum of all greater keys is added to every key 104 1296 Find the Winner of the Circular Game LeetCode Solution 104 1297 Minimum Possible Integer After at Most K Adjacent Swaps On Digits LeetCode Solution 104 1298 Jump Game IV LeetCode Solution 103 1299 Add Two Numbers II Leetcode Solution 103 1300 Binary Tree to Binary Search Tree Conversion using STL set 103 1301 Reach a Number LeetCode Solution 103 1302 Minimum Total Space Wasted With K Resizing Operations LeetCode Solution 103 1303 Minimum Number of People to Teach LeetCode Solution 102 1304 Continuous Subarray Sum LeetCode Solution 102 1305 Convert to Base -2 LeetCode Solution 101 1306 Number of Subsequences That Satisfy the Given Sum Condition LeetCode solution 101 1307 Queries on XOR of greatest odd divisor of the range 101 1308 Insert Delete GetRandom O(1) Leetcode Solution 101 1309 Design Underground System Leetcode Solution 96 1310 Print Maximum Length Chain of Pairs 96 1311 Shifting Letters LeetCode Solution 94 1312 Design A Leaderboard Leetcode Solution 93 1313 Detect Capital Leetcode Solution 93 1314 Top K Frequent Elements LeetCode Solution 91 1315 Substring with Concatenation of All Words Leetcode Solution 89 1316 Count Sub Islands LeetCode Solution 88 1317 Minimum Path Sum Leetcode Solution 88 1318 Minimum Swaps to Group All 1's Together Leetcode Solution 86 1319 Odd Even Linked List Leetcode Solution 85 1320 Longest Common Subsequence LeetCode Solution 85 1321 Binary Tree Inorder Traversal LeetCode Solution 84 1322 Maximum Population Year LeetCode Solution 83 1323 Decode String Leetcode Solution 83 1324 Find the Town Judge LeetCode Solution 82 1325 Best Meeting Point LeetCode Solution 81 1326 Find the Town Judge LeetCode Solution 80 1327 Shortest Unsorted Continuous Subarray LeetCode Solution 79 1328 Sum Root to Leaf Numbers LeetCode Solution 78 1329 Rectangle Overlap LeetCode Solution 76 1330 Maximum Population Year LeetCode Solution 75 1331 Design Add and Search Words Data Structure LeetCode Solution 75 1332 Flatten Binary Tree to Linked List LeetCode Solution 73 1333 Score of Parenthesis LeetCode Solution 72 1334 Stone Game IV LeetCode Solution 72 1335 Range Sum Query 2D – Immutable LeetCode Solution 71 1336 Is Graph Bipartite? LeetCode Solution 71 1337 Insert into a Sorted Circular Linked List LeetCode Solution 71 1338 Valid Triangle Number LeetCode Solution 69 1339 Reveal Cards In Increasing Order Leetcode Solution 67 1340 Divide Chocolate LeetCode Solution 62 1341 Step-By-Step Directions From a Binary Tree Node to Another LeetCode Solution 54 1342 Range Sum of BST LeetCode Solution 52 1343 Find K Closest Elements LeetCode Solution 48 1344 Reverse Integer Leetcode Solution 47 1345 Sort Colors LeetCode Solution 45 1346 Rotate String LeetCode Solution 44 1347 Maximum Side Length of a Square with Sum Less than or Equal to Threshold LeetCode Solution 43 1348 Excel Sheet Column Number LeetCode Solution 43 1349 Monotonic Array Leetcode Solution 28 1350 Find Peak Element LeetCode Solution 25 1351 Maximum Size Subarray Sum Equals k Leetcode Solution 25 1352 Container With Most Water LeetCode Solution 23 1353 Camelcase Matching Leetcode Solution 23 1354 Most Stones Removed with Same Row or Column LeetCode Solution 23 1355 H-Index Leetcode Solution 23 1356 High Five LeetCode Solution 23 1357 Sliding Window Maximum LeetCode Solution 20 1358 Valid Anagram Leetcode Solution 20 1359 Next Permutation LeetCode Solution 20 1360 Sentence Screen Fitting LeetCode Solution 19 1361 Group Anagrams LeetCode Solution 19 1362 Paint House LeetCode Solution 18 1363 Binary Search LeetCode Solution 18 1364 Next Greater Element I Leetcode Solution 18 1365 Flatten Binary Tree to Linked List LeetCode Solution 18 1366 Pairs of Songs With Total Durations Divisible by 60 LeetCode Solution 18 1367 Group Shifted Strings Leetcode Solution 17 1368 Isomorphic Strings LeetCode Solution 17 1369 Closest Binary Search Tree Value II LeetCode Solution 16 1370 Minimum Number of Arrows to Burst Balloons LeetCode Solution 16 1371 Insert Delete GetRandom O(1) – Duplicates allowed LeetCode Solution 16 1372 Peak Index in a Mountain Array LeetCode Solution 16 1373 Valid Triangle Number LeetCode Solution 16 1374 Unique Binary Search Trees LeetCode Solution 16 1375 Swim in Rising Water LeetCode Solution 15

durieustivered.blogspot.com

Source: https://www.tutorialcup.com/leetcode-solutions/maximum-depth-of-binary-tree-leetcode-solution.htm

0 Response to "104 Maximum Depth of Binary Tree 478 Easy"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel