List Every Original Root-to-Leaf Value Path

Quick Overview

List Every Original Root-to-Leaf Value Path. Return every tree path from root to leaf, joining node values with a right-pointing arrow separator. Preserve every path occurrence; output order is unrestricted.

List Every Original Root-to-Leaf Value Path

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return every root-to-leaf path in the binary tree as a string with values joined by "->". A leaf has no children. The source permits any output order. Keep the TreeNode* root interface and retain path multiplicity even if distinct paths spell the same values. ```cpp vector<string> binaryTreePaths(TreeNode* root); ``` ### Examples ```text root = [5,2,8,null,3] -> ["5->2->3","5->8"] root = [-2] -> ["-2"] ``` ### Constraints - There are 1 through 100 nodes. - Values lie in [-100,100]. ### Follow-up Questions Explain how the permitted output freedom is preserved without losing required values or occurrences. ### What a Strong Answer Covers Depth-first traversal maintains the current value path and records a formatted copy only at leaves. Explain why every produced result satisfies the source contract and why no required result is omitted.

Overview: List Every Original Root-to-Leaf Value Path. Return every tree path from root to leaf, joining node values with a right-pointing arrow separator. Preserve every path occurrence; output order is unrestricted.

Bloomberg logo
Bloomberg
Sep 27, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return every root-to-leaf path in the binary tree as a string with values joined by "->". A leaf has no children. The source permits any output order. Keep the TreeNode* root interface and retain path multiplicity even if distinct paths spell the same values.

vector<string> binaryTreePaths(TreeNode* root);

Examples

root = [5,2,8,null,3] -> ["5->2->3","5->8"]
root = [-2] -> ["-2"]

Constraints

  • There are 1 through 100 nodes.
  • Values lie in [-100,100].

Follow-up Questions Guidance

Explain how the permitted output freedom is preserved without losing required values or occurrences.

What a Strong Answer Covers Guidance

Depth-first traversal maintains the current value path and records a formatted copy only at leaves. Explain why every produced result satisfies the source contract and why no required result is omitted.