We use analytics and advertising cookies to understand how the site is used and whether our ads on Facebook and Instagram work. They are set only if you accept. See our Privacy Policy for details.
Most tree problems are one of three traversals plus a small amount of state threaded through the recursion. BST problems add one extra fact worth remembering: an in-order traversal of a BST is sorted, which turns validation and kth-smallest into near-trivial exercises. Get comfortable returning a tuple from the recursion - depth and validity together, for instance - and the hard path-sum problems open up.
A TreeNode input, or anything about depth, ancestry, or in-order ordering.
20 problems. Each one runs in an in-browser editor against real test cases, with hints and a worked solution.
The patterns cheat sheet covers all of these in one page - what each one looks like in a problem statement, and the template that follows.