2849. Determine if a Cell Is Reachable at a Given Time Medium

@problem@discussion
#Math



1/**
2 * [2849] Determine if a Cell Is Reachable at a Given Time
3 *
4 * You are given four integers sx, sy, fx, fy, and a non-negative integer t.
5 * In an infinite 2D grid, you start at the cell (sx, sy). Each second, you must move to any of its adjacent cells.
6 * Return true if you can reach cell (fx, fy) after exactly t seconds, or false otherwise.
7 * 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.
8 *  
9 * <strong class="example">Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2023/08/05/example2.svg" style="width: 443px; height: 243px;" />
11 * Input: sx = 2, sy = 4, fx = 7, fy = 7, t = 6
12 * Output: true
13 * 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. 
14 * 
15 * <strong class="example">Example 2:
16 * <img alt="" src="https://assets.leetcode.com/uploads/2023/08/05/example1.svg" style="width: 383px; height: 202px;" />
17 * Input: sx = 3, sy = 1, fx = 7, fy = 3, t = 3
18 * Output: false
19 * 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.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= sx, sy, fx, fy <= 10^9
25 * 	0 <= t <= 10^9
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/determine-if-a-cell-is-reachable-at-a-given-time/
31// discuss: https://leetcode.com/problems/determine-if-a-cell-is-reachable-at-a-given-time/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn is_reachable_at_time(sx: i32, sy: i32, fx: i32, fy: i32, t: i32) -> bool {
37        false
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_2849() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.