1119. Robot Bounded In Circle
My accepted Python solution to LeetCode problem 1119, Robot Bounded In Circle, running in 0ms.
- Difficulty: Medium
- Python
- Runtime 0ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.5MB, accepted 2026-01-02.
class Solution:
def isRobotBounded(self, instructions: str) -> bool:
# Direction vectors: North, East, South, West
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
dir_idx = 0 # Start facing North
x, y = 0, 0
for c in instructions:
if c == 'G':
x += directions[dir_idx][0]
y += directions[dir_idx][1]
elif c == 'L':
dir_idx = (dir_idx - 1) % 4
else: # R
dir_idx = (dir_idx + 1) % 4
# Bounded if: back at origin OR not facing North
return (x == 0 and y == 0) or dir_idx != 0