Back to problems

Move across a server grid efficiently

Algorithm · Upstart · Medium

A rectangular server farm holds height rows and width columns of machines. Coordinates use zero-based indexing: x selects the column and y selects the row, so a coordinate (x, y) lies inside the grid exactly when $$0 \le x < width$$ and $$0 \le y < height$$. Implement a function solve(x, y, direction, width, height, maxAttempts). It starts at (x, y) and repeatedly advances one cell at a time in direction. The eight permitted directions are "U", "D", "L", "R", "UR", "DR",…

Checking your access…