Simulate one pass through the instructions. Check if position is origin or direction changed.
function isRobotBounded(instructions):
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
x = 0
y = 0
dir = 0
for ch in instructions:
if ch == 'G':
x += dx[dir]
y += dy[dir]
elif ch == 'L':
dir = (dir + 3) % 4
elif ch == 'R':
dir = (dir + 1) % 4
return (x == 0 and y == 0) or dir != 0
time, space.