2849. Determine if a Cell Is Reachable at a Given Time LeetCode Solution
In this guide, you will get 2849. Determine if a Cell Is Reachable at a Given Time LeetCode Solution with the best time and space complexity. The solution to Determine if a Cell Is Reachable at a Given Time problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Determine if a Cell Is Reachable at a Given Time solution in C++
- Determine if a Cell Is Reachable at a Given Time solution in Java
- Determine if a Cell Is Reachable at a Given Time solution in Python
- Additional Resources

Problem Statement of 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:
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:
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
Complexity Analysis
- Time Complexity: O(1)
- Space Complexity: O(1)
2849. Determine if a Cell Is Reachable at a Given Time LeetCode Solution in C++
class Solution {
public:
bool isReachableAtTime(int sx, int sy, int fx, int fy, int t) {
const int minStep = max(abs(sx - fx), abs(sy - fy));
return minStep == 0 ? t != 1 : minStep <= t;
}
};
/* code provided by PROGIEZ */
2849. Determine if a Cell Is Reachable at a Given Time LeetCode Solution in Java
class Solution {
public boolean isReachableAtTime(int sx, int sy, int fx, int fy, int t) {
final int minStep = Math.max(Math.abs(sx - fx), Math.abs(sy - fy));
return minStep == 0 ? t != 1 : minStep <= t;
}
}
// code provided by PROGIEZ
2849. Determine if a Cell Is Reachable at a Given Time LeetCode Solution in Python
class Solution:
def isReachableAtTime(
self,
sx: int,
sy: int,
fx: int,
fy: int,
t: int,
) -> bool:
minStep = max(abs(sx - fx), abs(sy - fy))
return t != 1 if minStep == 0 else minStep <= t
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.