[
simulation
hash table
]
BinarySearch 0233 Roomba
Problem statement
https://binarysearch.com/problems/Roomba/
Solution
Just check what is asked.
Complexity
It is O(n)
for time and O(1)
for space.
Code
class Solution:
def solve(self, moves, x, y):
d = {"NORTH": (0, 1), "SOUTH": (0, -1), "EAST": (1, 0), "WEST": (-1, 0)}
x0, y0 = 0, 0
for t in moves:
dx, dy = d[t]
x0 += dx
y0 += dy
return x == x0 and y == y0