InterviewLegend

Path Problems

Alex Chen25 min readMedium

Property problems ask each child a question and wait for the answer to climb back up. Path problems run the other way: you hand every child the running total so far and check it once you reach a leaf. That one reversal decides the whole shape of the code, so once you internalize it these problems stop feeling like separate puzzles.

The Pattern: Path problems pass a running state DOWN the tree as you recurse. When you hit a leaf, you check or record the accumulated state.

Unlike tree properties (bottom-up/postorder), path problems flow top-down/preorder.
What's inside
  • 1 problem, worked step by step
  • about 25 min

Premium lessonData Structures & Algorithms

Keep going with Premium.

All 78 lessons and 103 worked problems in this course, plus what 100 companies ask, pulled from 20,000+ candidate reports.

100 companies. Checked every month.

Unlock the full course

$49 a year · less than $1 a week · Cancel anytime