Depth-First Search pattern
Binary Tree Tilt
Given the root of a binary tree, return the sum of every node's tilt, where a node's tilt is the absolute difference between the total value of its left subtree and the total value of its right subtree. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 563
- Easy
- 1 approach
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Depth-First SearchLeetCode 563
Easy
The approach
- 01 Post-order DFS (sum up, accumulate tilt) O(n)O(h) space
What you will learn
- How to read Binary Tree Tilt and spot the depth-first search pattern in it
- Post-order DFS (sum up, accumulate tilt): O(n) time, O(h) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Depth-First Search
See Binary Tree Tilt run, step by step
Sign in and this page opens on the animation, with all 18 Depth-First Search problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.