Invert Binary Tree (LeetCode 226) | Full solution with diagrams and animations | Study Algorithms
Nikhil Lohia
View ChannelAbout
I want to share with you my knowledge, that I have gained all my life. I like to see every task in your day to day life as an interesting problem to solve, and if you can understand the requirements, solving for it can become somewhat intuitive. I try to explore certain aspects of day to day life and how I can make them easier for you. This involves daily hacks, tutorials, innovations, new discoveries, experiences and all the stuff I find amusing. As a software engineer myself, I also believe that good problem solving skills can help you overcome most of the barriers in life. Programming is one of them. If you know how to approach a problem, writing a code for it in any language could be a very typical task. With this channel I aim to focus on the way to solve a problem efficiently rather than just its implementation.
Latest Posts
Video Description
Inverting a binary tree is more synonymous with mirroring a binary tree. Try to assume that there is a mirror in front of the tree and you need to return the reflection. This video explains beautifully with diagrams and animations how the reflection looks like and how to create one. All of this is done using a level order traversal technique. Actual Problem: https://leetcode.com/problems/invert-binary-tree/ Chapters: 00:00 - Intro 00:58 - Problem Statement and Description 03:15 - The thought behind the approach 05:44 - Recursive Solution 08:56 - Level Order Traversal Trick 12:05 - Dry-run of Code 14:28 - Final Thoughts π Links to topics I talk about in the video: LeetCode Problems: https://www.youtube.com/playlist?list=PLFdAYMIVJQHPaldBFQXzd59EiqfJTYkah Level Order Traversal: https://youtu.be/9M3oCwPGamE Post Order Traversal: https://youtu.be/ZIXGxg8ZLKs Tree Data Structure: https://youtu.be/6jwUjPs27Pc π A text based explanation is available at: https://studyalgorithms.com Code on Github: https://github.com/nikoo28/java-solutions/blob/master/src/main/java/leetcode/easy/InvertTree.java Test-cases on Github: https://github.com/nikoo28/java-solutions/blob/master/src/test/java/leetcode/easy/InvertTreeTest.java π Reference Books: Starting Learn to Code: https://amzn.to/36pU0JO Favorite book to understand algorithms: https://amzn.to/39w3YLS Favorite book for data structures: https://amzn.to/3oAVBTk Get started for interview preparation: https://amzn.to/39ysbkJ π To see more videos like this, you can show your support on: https://www.buymeacoffee.com/studyalgorithms π₯ My Recording Gear: Recording Light: https://amzn.to/3pAqh8O Microphone: https://amzn.to/2MCX7qU Recording Camera: https://amzn.to/3alg9Ky Tablet to sketch and draw: https://amzn.to/3pM6Bi4 Surface Pen: https://amzn.to/3pv6tTs Laptop to edit videos: https://amzn.to/2LYpMqn π» Get Social π» Follow on Facebook at: https://www.facebook.com/studyalgos Follow on Twitter at: https://www.twitter.com/studyalgorithms Follow on Tumblr at: https://studyalgos.tumblr.com/ Subscribe to RSS feeds: https://studyalgorithms.com/feed/ Join fan mail: http://eepurl.com/g9Dadv #leetcode #programming #interview
Essential Camera Gear Upgrades
AI-recommended products based on this video

COTUBLR 31 Inch Computer Desk, Home Office Desk, Simple Modern Small Desk for Bedroom, Writing Desk with Storage Bag, Study Table for Students, Grey Oak

SmallRig ZV-E1 Camera Baseplate for Sony ZV-E1, Built-in Cold Shoe Mount and QR Plate (for Arca) Quick Switch Between Tripod and Stabilizer for DJI RS 2 / RSC 2 / RS 3 / RS 3 Pro - 4314

SmallRig FX3 / FX30 HawkLock Quick Release Camera Cage Kit for Sony with Cable Clamp, Bulit-in QR Cold Shoe NATO Rail/QR Plate for Arca, Modular Design Compatible with Original XLR Handle - 4770

SmallRig FX3 / FX30 HawkLock Quick Release Camera Cage Kit for Sony with XLR Handle Extension, Wrist Strap and Cable Clamp for HDMI, QR Cold Shoe, NATO Rail/QR Plate for Arca,Titanium Gray - 4771

AC Power Cord Cable Fit for Sony PS5 PS4 PS3 Slim PlayStation 5 4 3, Xbox Series X/S, Xbox One X/S, TV, Printer Universal 2 Prong Supply Replacement - (ETL Listed Cable)

Anker USB C Charger Cable (6ft 100W, 2Pack), USB 2.0 Type C Fast Charging Cable for iPhone 15 / 15Pro / 15Plus / 15ProMax MacBook Pro 2020, iPad Pro 2020, iPad Air 4, Samsung Galaxy S23+/S23 Ultra ClimatePartner certified
![Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)](https://m.media-amazon.com/images/I/71N7xhCJnoL._AC_UL960_FMwebp_QL65_.jpg)
Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)

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

Lexar 128GB Micro SD Card, microSDXC UHS-I Flash Memory Card with Adapter - Up to 100MB/s, A1, U3, Class10, V30, High Speed TF Card

ANXRE 71" Phone Tripod, NT79 Extendable Selfie Stick for Cell PhoneοΌCamera Photo Video Kits, Travel Tripod Stand with Remote for Video Recording, Phone Holder Tripod Compatible with Phone Camera Gopro

Kaiess 62" Tripod for iPhone, Selfie Stick Tripod & Phone Tripod Stand with Remote, Cell Phone Tripod for iPhone, Extendable Travel Tripod Compatible with iPhone 14/13/12 Pro Max/Android

EUCOS 62" Phone Tripod, Tripod for iPhone & Selfie Stick Tripod with Remote, Extendable Phone Tripod Stand & Travel Tripod, Solidest Cell Phone Tripod Compatible with iPhone/Android
























