Back to problems

Earliest Coordinate Reach with Optional Moves

Algorithm · IBM · Medium

Requirements Input values: directions, a length-n string whose characters are drawn from E, S, W, and N. The starting point (startX, startY) plus the destination (endX, endY). During second i, you may either take a one-unit step indicated by directions[i] or ignore that instruction and remain where you are. Determine the first second by which the destination point is attainable. Return -1 when arriving at the destination is impossible during the n available seconds.…

Checking your access…