Back to problems

Simulate a Robot Following Commands on a Grid

Algorithm · Shopify · Easy

Implement final_position(R, C, x0, y0, S) to simulate a robot moving on a two-dimensional grid. The origin (0, 0) sits at the bottom-left corner. A step to the right increases x by one, while a step upward increases y by one. The grid dimensions are given by R and C; permitted coordinates satisfy $$0 \le x < C$$ and $$0 \le y < R$$. The robot starts at (x0, y0). The string S is a sequence of commands drawn from U, D, L, and R, meaning up, down, left, and right respectively.…

Checking your access…