Dsa
Trees
Medium
All Paths From Root to Leaves
Given a binary tree, return all root-to-leaf paths as a list of strings, where each string represents a path in the format of 'node1->node2->...->leaf'. Print the list of paths.
Input format:
The input consists of a string that represents a binary tree in level order (e.g., '1,2,3').
Output format:
Print a list of strings representing the paths.
Example:
Input:
1,2,3
Output:
['1->2', '1->3']
Key concepts
treespathtraversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now