← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Your car starts at position 0 with speed +1 on an infinite number line. You can drive in both positive and negative directions. Your car automatically moves according to the following rules:
Given a target position (a positive integer), your task is to determine the minimum number of commands required to reach the target exactly. The car can go into negative positions, and you want to find the shortest sequence of "A" and "R" commands that lands the car exactly on the target.
This is a classic search problem where the state is defined by the car's current position and speed, and each state has exactly two outgoing transitions corresponding to the two commands.