Problem statement

https://binarysearch.com/problems/Bounded-Robot-Moves/

Solution

Equal to Leetcode 1041. Robot Bounded In Circle.

Complexity

Time is O(4n), space is O(1).

Code

class Solution:
    def solve(self, instructions):
        dx, dy, x, y = 0, 1, 0, 0
        for l in 4*instructions:
            if l == "F": 
                x, y = x+dx, y+dy
            elif l == "L":
                dx, dy = -dy, dx
            else:
                dx, dy = dy, -dx
                
        return (x, y) == (0,0)