2 ms·
Here is how I did it start: left skipNext goto start goto double double: left left goto doubl
by verroq 11y ago
Here is how I did it
start: left
skipNext
goto start
goto double
double: left
left
goto double
The idea comes from the "find a loop in a singlely linked list in O(1) space" problem.
One pointer moves twice as fast the as the other one.
- kanche 11y agoYou don't need the 'goto double' line, execution is anyway going skip to 'double: left' making the line redundant Also say each step takes one unit of time, so one 'start' loop requires 3 units to go one unit of distance, whereas 'double' takes 3 units to go 2 units of distance, even if you use one left statement in the 'double' loop, robot will still move faster than the other as it will require only two units of time to go one unit of distance. :)