In an infinite binary tree, rows are labeled alternately:
Odd-numbered rows (1st, 3rd, …) are labeled left → right.
Even-numbered rows (2nd, 4th, …) are labeled right → left.
Given a node label, return the path of labels from the root (1) to that node.
Idea:
Let row index be 0-based (row 0 has label range [1,1], row 1 is [2,3], row 2 is [4,7], …).
For a node at row r with zigzag label label:
Convert to its normal (left→right) index within the row:
Parent’s normal index is idx // 2, which lies on row r-1.
Convert that parent normal index back to the zigzag label of row r-1:
Repeat until reaching label 1. Reverse the collected list for root→node order.
Input: label = 14
Output: [1, 3, 4, 14]
Input: label = 26
Output: [1, 2, 6, 10, 26]
Input: label = 1
Output: [1]
Accepted:
Submission: