Description
Your car starts at position 0 and speed 1. You can accelerate (A) or reverse (R). Return the minimum number of instructions to reach target position.
Examples
Input:
target = 3Output:
2Explanation:
AA: position becomes 3.
Input:
target = 1Output:
1Explanation:
A: position becomes 1. Starting at position 0 with speed 1, one acceleration instruction moves the car to position 1.
Input:
target = 4Output:
4Explanation:
Sequence AAARA: A moves to position 1 (speed 2), A moves to position 3 (speed 4), A moves to position 7 (speed 8), R reverses (speed -1), A moves to position 6. The minimum number of instructions to reach position 6 is 5.
Constraints
- •
1 ≤ target ≤ 10⁴