Binary Tree Maximum Path Sum (Animated Walkthrough) (LeetCode)
AlgosWithMichael
View ChannelAbout
Hi! My name is Michael. I make coding tutorials to help people pass their technical interviews. I release videos each week and plan to branch out to project videos as well so stay tuned!
Latest Posts
Video Description
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. Check out my interview prep platform for learning the patterns! 📢 Interview Prep Platform: https://algoswithmichael.com 🔗 Social 🔗 🎧 Join the community Discord: https://discord.gg/aVWsAaaCtT 💰 Support me on Patreon: https://www.patreon.com/michaelmuinos 🔗Follow me on LinkedIn: https://www.linkedin.com/in/michael-muinos 📂Follow me on Github: https://github.com/MichaelMuinos ⭐️ Timestamps ⭐️ 00:00 - Intro 00:19 - Problem Overview 02:22 - Algorithm Walkthrough 07:35 - Code Walkthrough 10:52 - Time & Space Complexity
Upgrade Your Tech Today
AI-recommended products based on this video

Wireless Charger for Samsung - NANAMI 3 in 1 Charging Station for Multiple Devices,Fast Charger Stand Dock for Galaxy S25 S24 S23 Ultra S22 S21 S20 Z Flip Fold,Galaxy Watch 5/5 Pro/4/3,Galaxy Buds Pro

45W Super Fast Charger USBC Charger, 2Pack 10FT Samsung Charger Fast Charging Cord Cable& Samsung Type C Charger Block for Galaxy S25 S24 S23 S22 S21 Ultra/Plus, Tab S10 S9 S8 S7,iPad,Android Phone

Samsung Galaxy Tab S10 Ultra Gray 256GB - AI Tablet, 14.6", AMOLED 2X, Anti-Reflection, 420 Nits, Vapor Chamber, S Pen Included (CAD Version & Warranty)

Wireless Charger for Samsung - NANAMI 3 in 1 Charging Station for Multiple Devices,Fast Charger Stand Dock for Galaxy S25 S24 S23 Ultra S22 S21 S20 Z Flip Fold,Galaxy Watch 5/5 Pro/4/3,Galaxy Buds Pro

Super Fast Charger Type C, 2 Pack 25W USB C Wall Charger Fast Charging for Samsung Galaxy S25 Edge/S25 Ultra/S25/S25+/S24/S24+/S24 Ultra/S23/S22/S21 /S20/Note 20/10 with 10FT Long Type C Charging Cord

Galaxy S24 S25 USB C Charging Block 25W PD Super Fast Charger Type C Wall Plug Adapter Quick Charge for Samsung Galaxy S25/S24/S23/S22/S21/S20/Z Fold 3/4/5/Note20/iPhone 15/16/iPad/Tablet/Watch-1Pack

SanDisk 128GB 2-Pack microSDXC Card, Licensed for Nintendo Switch (2x128GB) - SDSQXAO-128G-GN6Z2

SanDisk 256GB Ultra microSDXC UHS-I Memory Card with Adapter - Up to 150MB/s, C10, U1, Full HD, A1, MicroSD Card - SDSQUAC-256G-GN6MA

SanDisk 64GB Extreme PRO SDXC UHS-I Memory Card - C10, U3, V30, 4K UHD, SD Card - SDSDXXU-064G-GN4IN

SanDisk 128GB Extreme PRO SDXC UHS-I Memory Card - C10, U3, V30, 4K UHD, SD Card - SDSDXXD-128G-GN4IN
![Spigen Case for Galaxy S25 Case, Tough Armor (Ai) MagFit [Wireless Charging] Compatible with MagSafe - Black](https://m.media-amazon.com/images/I/71dL2NiwINL._AC_UL960_FMwebp_QL65_.jpg)
Spigen Case for Galaxy S25 Case, Tough Armor (Ai) MagFit [Wireless Charging] Compatible with MagSafe - Black

Spigen Case for iPhone 16 Case, Tough Armor Designed for Apple iPhone 16 - Black
![Spigen Case for iPhone 16 Pro Case, Tough Armor [MagFit] Compatible with MagSafe - Black](https://m.media-amazon.com/images/I/61rMnLID99L._AC_UL960_FMwebp_QL65_.jpg)
Spigen Case for iPhone 16 Pro Case, Tough Armor [MagFit] Compatible with MagSafe - Black
![Spigen Case for iPhone 16 Plus Case, Tough Armor (AI) [MagFit] Compatible with MagSafe - Black](https://m.media-amazon.com/images/I/61Ygh697e4L._AC_UL960_FMwebp_QL65_.jpg)
Spigen Case for iPhone 16 Plus Case, Tough Armor (AI) [MagFit] Compatible with MagSafe - Black

Girl Moments: Coloring Book for Adults and Teens Featuring Cute Cozy Daily Activities for Relaxation

Samsung Galaxy Tab S10 Ultra Gray 256GB - AI Tablet, 14.6", AMOLED 2X, Anti-Reflection, 420 Nits, Vapor Chamber, S Pen Included (CAD Version & Warranty)

Samsung Galaxy Tab A9+ 27.94 cm(11.0 inch) Display, RAM 4 GB, ROM 64 GB Expandable, Wi-Fi, Tablet, (Gray)

Samsung Galaxy Tab A7 10.4" (32GB, 3GB) Ultra-Slim Wi-Fi Only Android 10 One UI Tablet, Snapdragon 662, 7040mAh Battery, SM-T503 (64GB SD Bundle) (Dark Gray)

Samsung Galaxy Tab A9+ 64 GB Graphite (CAD Version and Warranty)

Magnetic Wireless Charger for iPhone: Fodable 3 in 1 Charging Station for Multiple Apple Devices - Travel Charging Pad Dock for Apple Watch iPhone 16 15 14 13 12 Pro Max Plus & Airpod Global Recycled Standard

2 Pack Magnetic Wireless Charger 15W Fast Mag-Safe Charger Stand Compatible with iPhone 16/15/14/13/12 Series Wireless Charging Pad for AirPods 3/2/Pro 2/Pro White Portable Mag Safe Kickstand

Wireless Earbuds, 2025 Bluetooth 5.4 Bass Stereo Headphones with 4 ENC Mic, 48H Playback Ear Buds with Charging Case LED Display,Sport Earphones IPX7 Waterproof for Phone, Android, Pad, White

USB C Cable 6ft Type C Charger Cable 3.1A Fast Charging Nylon Braided USB A to USB C Charge Cord for Samsung Galaxy S25 S24 S23 S22 S21 S20 A12 A13 A14 A15 A16 A32 A53 5G Android Phone Tablet PS5 LG

45W Super Fast Charger USBC Charger, 2Pack 10FT Samsung Charger Fast Charging Cord Cable& Samsung Type C Charger Block for Galaxy S25 S24 S23 S22 S21 Ultra/Plus, Tab S10 S9 S8 S7,iPad,Android Phone























