Tuesday common C++ interview problem: Race car.
Given a target, you are given the following car controls:
- accelerate: position += speed; speed *= 2;
- reverse: speed = (speed > 0) ? -1 : 1;
What is the minimum number of steps (A/R) to reach the target? Assume target {1..10’000} and starting speed of one.
Solve it yourself: https://compiler-explorer.com/z/cxqzsxnT4
Solution: https://compiler-explorer.com/z/Wrs17a1PM