Depth-First Search pattern

Path Sum

Given the root of a binary tree and a target sum, return true if there is a root-to-leaf path whose node values add up exactly to the target, and false otherwise. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 112
  • 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 112

Easy

The approach

  1. 01 Recursive DFS (carry remaining down) O(n)O(h) space
Played step by step, with its time and space.

What you will learn

  • How to read Path Sum and spot the depth-first search pattern in it
  • Recursive DFS (carry remaining down): 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 Path Sum 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.