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: pos 0->1 (speed 2), then 1->3 (speed 4). Two accelerations reach position 3 exactly.
Input:
target = 1Output:
1Explanation:
A: Start at pos 0 with speed 1. One A reaches position 1 exactly.
Input:
target = 4Output:
5Explanation:
AARA then more moves needed. Can't reach 4 exactly with pure As. Optimal: 5 instructions.
Constraints
- •
1 ≤ target ≤ 10⁴