2849. Determine if a Cell Is Reachable at a Given Time
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 37% Topics: Math
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(1)
# Space: O(1)
# constructive algorithms, math
class Solution(object):
def isReachableAtTime(self, sx, sy, fx, fy, t):
"""
:type sx: int
:type sy: int
:type fx: int
:type fy: int
:type t: int
:rtype: bool
"""
diff1, diff2 = abs(sx-fx), abs(sy-fy)
mn = min(diff1, diff2)+abs(diff1-diff2)
return t >= mn if mn else t != 1
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions