PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Chicago

Determine if tree has path sum

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of binary tree data structures and traversal techniques, along with the ability to accumulate and track root-to-leaf path sums while correctly handling edge cases such as empty trees and negative values.

  • easy
  • Chicago
  • Coding & Algorithms
  • Data Scientist

Determine if tree has path sum

Company: Chicago

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem Given the `root` of a binary tree and an integer `targetSum`, return `true` if the tree has a **root-to-leaf** path such that adding up all the values along the path equals `targetSum`. Otherwise, return `false`. - A **leaf** is a node with no children. - A **root-to-leaf** path starts at the root and ends at any leaf. ## Input - `root`: binary tree node with fields `val`, `left`, `right` - `targetSum`: integer ## Output - Boolean indicating whether such a path exists. ## Example For a tree with root-to-leaf path values `[5,4,11,2]` and `targetSum = 22`, return `true` because `5 + 4 + 11 + 2 = 22`. ## Notes / Constraints (assumptions) - Node values and `targetSum` may be negative. - You should handle an empty tree (`root = null`). ## Task Implement a function (e.g., in Python) to solve this problem efficiently.

Quick Answer: This question evaluates understanding of binary tree data structures and traversal techniques, along with the ability to accumulate and track root-to-leaf path sums while correctly handling edge cases such as empty trees and negative values.

Related Interview Questions

  • Merge Nested Dictionaries Iteratively - Chicago (easy)
Chicago logo
Chicago
Feb 9, 2026, 1:39 PM
Data Scientist
Technical Screen
Coding & Algorithms
2
0
Loading...

Problem

Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum. Otherwise, return false.

  • A leaf is a node with no children.
  • A root-to-leaf path starts at the root and ends at any leaf.

Input

  • root : binary tree node with fields val , left , right
  • targetSum : integer

Output

  • Boolean indicating whether such a path exists.

Example

For a tree with root-to-leaf path values [5,4,11,2] and targetSum = 22, return true because 5 + 4 + 11 + 2 = 22.

Notes / Constraints (assumptions)

  • Node values and targetSum may be negative.
  • You should handle an empty tree ( root = null ).

Task

Implement a function (e.g., in Python) to solve this problem efficiently.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Chicago•More Data Scientist•Chicago Data Scientist•Chicago Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.