PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Capital One

Return all root-to-leaf tree paths

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competence with binary tree structures, path enumeration and traversal techniques along with the ability to represent traversal results as formatted strings.

  • medium
  • Capital One
  • Coding & Algorithms
  • Machine Learning Engineer

Return all root-to-leaf tree paths

Company: Capital One

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given the root of a binary tree, return all **root-to-leaf** paths. - A **leaf** is a node with no children. - A path should be represented as a string with node values separated by `"->"`. ## Input - `root`: the root node of a binary tree (each node has `val`, `left`, `right`). ## Output - A list of strings, each string representing one root-to-leaf path. ## Example For the tree: ``` 1 / \ 2 3 \ 5 ``` Output: - `["1->2->5", "1->3"]` ## Constraints - Number of nodes up to 10^4. - Node values are integers.

Quick Answer: This question evaluates competence with binary tree structures, path enumeration and traversal techniques along with the ability to represent traversal results as formatted strings.

Related Interview Questions

  • Solve Four Coding Assessment Tasks - Capital One (medium)
  • Write SQL using joins and window functions - Capital One (medium)
  • Review Preprocessing Code and Tests - Capital One (easy)
  • Remove nodes with a given value - Capital One (medium)
  • Solve multiple algorithmic interview questions - Capital One (hard)
Capital One logo
Capital One
Dec 15, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
3
0

Given the root of a binary tree, return all root-to-leaf paths.

  • A leaf is a node with no children.
  • A path should be represented as a string with node values separated by "->" .

Input

  • root : the root node of a binary tree (each node has val , left , right ).

Output

  • A list of strings, each string representing one root-to-leaf path.

Example

For the tree:

   1
  / \
 2   3
  \
   5

Output:

  • ["1->2->5", "1->3"]

Constraints

  • Number of nodes up to 10^4.
  • Node values are integers.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Capital One•More Machine Learning Engineer•Capital One Machine Learning Engineer•Capital One Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.