Algorithms
Medium
2849
3056
Determine if a Cell Is Reachable at a Given Time
determine-if-a-cell-is-reachable-at-a-given-time
"""
You are given four integers sx, sy, fx, fy, and a non-negative integer t.

In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.

Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.

A cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.

Example 1:

[https://assets.leetcode.com/uploads/2023/08/05/example2.svg]

Input: sx = 2, sy = 4, fx = 7, fy = 7, t = 6
Output: true
Explanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.

Example 2:

[https://assets.leetcode.com/uploads/2023/08/05/example1.svg]

Input: sx = 3, sy = 1, fx = 7, fy = 3, t = 3
Output: false
Explanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.


Constraints:

 * 1 <= sx, sy, fx, fy <= 109
 * 0 <= t <= 109
"""
class Solution:
    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:
        
You are given four integers sx, sy, fx, fy, and a non-negative integer t.

In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.

Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.

A cell's adjacent cells are the 8 cells around it that share at least one corner with it. You can visit the same cell several times.

Example 1:

[https://assets.leetcode.com/uploads/2023/08/05/example2.svg]

Input: sx = 2, sy = 4, fx = 7, fy = 7, t = 6
Output: true
Explanation: Starting at cell (2, 4), we can reach cell (7, 7) in exactly 6 seconds by going through the cells depicted in the picture above.

Example 2:

[https://assets.leetcode.com/uploads/2023/08/05/example1.svg]

Input: sx = 3, sy = 1, fx = 7, fy = 3, t = 3
Output: false
Explanation: Starting at cell (3, 1), it takes at least 4 seconds to reach cell (7, 3) by going through the cells depicted in the picture above. Hence, we cannot reach cell (7, 3) at the third second.


Constraints:

 * 1 <= sx, sy, fx, fy <= 109
 * 0 <= t <= 109


Please complete the code below to solve above prblem:
```python
class Solution:
    def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool:
        
```

my_solution = Solution()

test_input = { "sx": 3, "sy": 1, "fx": 7, "fy": 3, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 2, "sy": 4, "fx": 7, "fy": 7, "t": 6 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 1, "fy": 2, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 2, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 3, "fy": 4, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 3, "fy": 5, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 1, "fy": 1, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 1, "fy": 3, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 4, "fy": 1, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 4, "fy": 2, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 1, "fy": 4, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 1, "fy": 5, "t": 8 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 2, "fy": 1, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 4, "fy": 3, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 2, "fy": 2, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 4, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 5, "fy": 1, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 2, "fy": 3, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 5, "fy": 2, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 1, "fx": 2, "fy": 5, "t": 6 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 3, "fy": 1, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 3, "fy": 2, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 3, "fy": 3, "t": 9 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 4, "fy": 5, "t": 9 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 5, "fy": 3, "t": 9 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 5, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 1, "fy": 1, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 1, "fx": 5, "fy": 5, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 1, "fy": 2, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 1, "fy": 3, "t": 6 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 1, "fy": 4, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 2, "fy": 5, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 3, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 1, "fy": 5, "t": 5 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 3, "fy": 5, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 4, "fy": 1, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 2, "fy": 1, "t": 10 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 2, "fy": 2, "t": 9 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 2, "fy": 3, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 4, "fy": 2, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 2, "fy": 4, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 4, "fy": 3, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 4, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 3, "fy": 1, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 3, "fy": 2, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 4, "fy": 5, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 3, "fy": 3, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 5, "fy": 1, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 5, "fy": 3, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 2, "fx": 5, "fy": 2, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 5, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 1, "fy": 1, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 1, "fy": 2, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 2, "fx": 5, "fy": 5, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 2, "fy": 1, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 2, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 1, "fy": 3, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 1, "fy": 4, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 1, "fy": 5, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 2, "fy": 2, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 2, "fy": 3, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 3, "fy": 1, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 2, "fy": 5, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 4, "fy": 1, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 3, "fy": 2, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 3, "fy": 3, "t": 8 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 4, "fy": 5, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 5, "fy": 1, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 5, "fy": 2, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 5, "fy": 3, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 5, "fy": 4, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 5, "fy": 5, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 3, "fy": 4, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 3, "fy": 5, "t": 2 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 1, "fy": 2, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 3, "fx": 4, "fy": 2, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 4, "fy": 3, "t": 10 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 3, "fx": 4, "fy": 4, "t": 10 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 1, "fy": 1, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 1, "fy": 3, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 1, "fy": 4, "t": 6 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 2, "fy": 2, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 1, "fy": 5, "t": 6 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 2, "fy": 4, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 2, "fy": 1, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 3, "fy": 3, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 2, "fy": 3, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 2, "fy": 5, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 3, "fy": 1, "t": 4 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 3, "fy": 2, "t": 5 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 4, "fy": 1, "t": 7 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 3, "fy": 4, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 4, "fy": 4, "t": 10 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 4, "fy": 5, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == True

test_input = { "sx": 1, "sy": 4, "fx": 3, "fy": 5, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 4, "fy": 2, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 4, "fy": 3, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 5, "fy": 2, "t": 1 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 5, "fy": 4, "t": 3 }
assert my_solution.isReachableAtTime(**test_input) == False

test_input = { "sx": 1, "sy": 4, "fx": 5, "fy": 5, "t": 0 }
assert my_solution.isReachableAtTime(**test_input) == False