← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Practice/Bloomberg/Leetcode 257. Binary Tree Paths
CodingMust
Given the root of a binary tree, return all paths from the root node to every leaf node in the tree. Each path should be represented as a string with node values separated by "->".
A leaf node is defined as a node with no children (both left and right pointers are null).
Example 1:
`
Input:
1
/
2 3
/
5 6
Output: ["1->2->5", "1->2->6", "1->3"]
Explanation: There are three leaf nodes (5, 6, and 3). The paths from root to each leaf are:
Example 2:
` Input: 1
Output: ["1"]
Explanation: The tree has only one node, which is both the root and a leaf. `
Example 3:
` Input: 1 / 2 / 3
Output: ["1->2->3"]
Explanation: Only one path exists in this left-skewed tree. `