Binary Tree Maximum Path Sum (Animated Walkthrough) (LeetCode)
💰 Support me on Patreon: https://www.patreon.com/michaelmuinos
🔗Follow me on Twitter: https://twitter.com/MichaelMuinos
📂Follow me on Github: https://github.com/MichaelMuinos
00:00 - Intro
00:19 - Problem Overview
02:22 - Algorithm Walkthrough
07:35 - Code Walkthrough
10:52 - Time & Space Complexity
Binary Tree Maximum Path Sum is a popular LeetCode problem involving the knowledge of recursion, binary trees, and postorder traversal. This problem is asking at companies including Amazon, Google, Microsoft, Facebook, and Bloomberg.
For this problem, we are given a binary tree and must find the maximum path sum in the tree. A path sum is the sum of the values in a path of the binary tree. The binary tree can have negative numbers, thus our maximum does not necessarily have to be positive. To solve this efficiently, we must traverse each node in the tree computing the max sum at each step. If we encounter a negative number, we will bound that value to a zero to ensure that we always get the absolute maximum.
The time complexity of the solution will be linear because we must does each node in the tree in our traversal. The space complexity is going to be O(H) where H is the height of our tree. Since we are using recursion, in the worst case, we will have H recursive calls which will fill up our stack space.
Видео Binary Tree Maximum Path Sum (Animated Walkthrough) (LeetCode) канала Michael Muinos
🔗Follow me on Twitter: https://twitter.com/MichaelMuinos
📂Follow me on Github: https://github.com/MichaelMuinos
00:00 - Intro
00:19 - Problem Overview
02:22 - Algorithm Walkthrough
07:35 - Code Walkthrough
10:52 - Time & Space Complexity
Binary Tree Maximum Path Sum is a popular LeetCode problem involving the knowledge of recursion, binary trees, and postorder traversal. This problem is asking at companies including Amazon, Google, Microsoft, Facebook, and Bloomberg.
For this problem, we are given a binary tree and must find the maximum path sum in the tree. A path sum is the sum of the values in a path of the binary tree. The binary tree can have negative numbers, thus our maximum does not necessarily have to be positive. To solve this efficiently, we must traverse each node in the tree computing the max sum at each step. If we encounter a negative number, we will bound that value to a zero to ensure that we always get the absolute maximum.
The time complexity of the solution will be linear because we must does each node in the tree in our traversal. The space complexity is going to be O(H) where H is the height of our tree. Since we are using recursion, in the worst case, we will have H recursive calls which will fill up our stack space.
Видео Binary Tree Maximum Path Sum (Animated Walkthrough) (LeetCode) канала Michael Muinos
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Longest Increasing Path in a Matrix (DFS + Memoization)Binary Tree Maximum Path Sum - DFS - Leetcode 124 - PythonTrie Data Structure Implementation (LeetCode)Coding Interview Prep | 3 MUST KNOW Graph Problem TipsLinked List in Binary Tree (BFS + DFS + Preorder Traversal)Minimum Window Substring | Sliding Window | LeetCodeDiameter of a Binary Tree - Leetcode 543 - PythonConstruct Binary Tree from Inorder and Preorder Traversal - Leetcode 105 - PythonAmazon Coding Interview Question - First Missing Positive (LeetCode)Sliding Window Algorithm - Longest Substring Without Repeating Characters (LeetCode)Google Coding Question - Making a Large Island (Hard)FACEBOOK CODING INTERVIEW QUESTION - LOWEST COMMON ANCESTORAmazon Coding Question - Insert Delete GetRandom O(1)Amazon System Design Interview: Design Parking GarageSerialize & Deserialize A Binary Tree - Crafting Recursive Solutions To Interview ProblemsLongest Repeating Character Replacement - Leetcode 424 - PythonKadane's Algorithm - Maximum Subarray (Dynamic Programming)Word Search II - Backtracking Trie - Leetcode 212 - Python5 Tips to BEAT the LeetCode GrindTime Based Key Value Store | Netflix Coding Question | Binary Search