Square Interview Question

In a 2d matrix, an arrow is placed, move it as per string command.