Number Transformation Path
CodingPhoneSoftware EngineerReported Jun, 2026New
Examples
Example 1:
Input: a = 10, b = 3
Output: [10,5,2,1,3]
Explanation:
Example 2:
Input: a = 7, b = 8
Output: [7,3,1,3,5,2,4,6,8]
Explanation:
Example 1:
Input: a = 10, b = 3
Output: [10,5,2,1,3]
Explanation:
Example 2:
Input: a = 7, b = 8
Output: [7,3,1,3,5,2,4,6,8]
Explanation:
You are given three helper operations on positive integers:
add(num) returns num + 2sub(num) returns num - 2split(num) returns floor(num / 2)Given two positive integers a and b, return one possible path that transforms a into b using these operations.
The path should include the starting value a, every intermediate value, and the final value b. The path does not need to be shortest.
10 is split to 5, then 2, then 1. Finally, add 2 to reach 3.
After reaching 1, use 1 -> 3 -> 5 -> 2 to switch to an even value, then add by 2.
1 <= a, b <= 10^5add, sub, or split.