Back to problems

Race Car: Minimum Instructions to Reach a Target

Algorithm · Waymo · Hard

Requirements Begin with the car at coordinate 0 and velocity +1. An A command advances the car by its present velocity, after which that velocity is multiplied by two. An R command does not move the car; instead, it flips the travel direction and sets the velocity's absolute value to 1. For a supplied destination, determine the fewest commands required to arrive exactly at that position. Examples Input: target = 1 Output: 1 Explanation: Executing A moves the car from 0 to 1.…

Checking your access…