Skip to content

Commit 6e94828

Browse files
committed
1970. Last Day Where You Can Still Cross: RETRY
1 parent 1e2eea7 commit 6e94828

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

src/solution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1485,3 +1485,4 @@ mod s1964_find_the_longest_valid_obstacle_course_at_each_position;
14851485
mod s1967_number_of_strings_that_appear_as_substrings_in_word;
14861486
mod s1968_array_with_elements_not_equal_to_average_of_neighbors;
14871487
mod s1969_minimum_non_zero_product_of_the_array_elements;
1488+
mod s1970_last_day_where_you_can_still_cross;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* [1970] Last Day Where You Can Still Cross
3+
*
4+
* There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively.
5+
* Initially on day 0, the entire matrix is land. However, each day a new cell becomes flooded with water. You are given a 1-based 2D array cells, where cells[i] = [ri, ci] represents that on the i^th day, the cell on the ri^th row and ci^th column (1-based coordinates) will be covered with water (i.e., changed to 1).
6+
* You want to find the last day that it is possible to walk from the top to the bottom by only walking on land cells. You can start from any cell in the top row and end at any cell in the bottom row. You can only travel in the four cardinal directions (left, right, up, and down).
7+
* Return the last day where it is possible to walk from the top to the bottom by only walking on land cells.
8+
*
9+
* Example 1:
10+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/27/1.png" style="width: 624px; height: 162px;" />
11+
* Input: row = 2, col = 2, cells = [[1,1],[2,1],[1,2],[2,2]]
12+
* Output: 2
13+
* Explanation: The above image depicts how the matrix changes each day starting from day 0.
14+
* The last day where it is possible to cross from top to bottom is on day 2.
15+
*
16+
* Example 2:
17+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/27/2.png" style="width: 504px; height: 178px;" />
18+
* Input: row = 2, col = 2, cells = [[1,1],[1,2],[2,1],[2,2]]
19+
* Output: 1
20+
* Explanation: The above image depicts how the matrix changes each day starting from day 0.
21+
* The last day where it is possible to cross from top to bottom is on day 1.
22+
*
23+
* Example 3:
24+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/27/3.png" style="width: 666px; height: 167px;" />
25+
* Input: row = 3, col = 3, cells = [[1,2],[2,1],[3,3],[2,2],[1,1],[1,3],[2,3],[3,2],[3,1]]
26+
* Output: 3
27+
* Explanation: The above image depicts how the matrix changes each day starting from day 0.
28+
* The last day where it is possible to cross from top to bottom is on day 3.
29+
*
30+
*
31+
* Constraints:
32+
*
33+
* 2 <= row, col <= 2 * 10^4
34+
* 4 <= row * col <= 2 * 10^4
35+
* cells.length == row * col
36+
* 1 <= ri <= row
37+
* 1 <= ci <= col
38+
* All the values of cells are unique.
39+
*
40+
*/
41+
pub struct Solution {}
42+
43+
// problem: https://leetcode.com/problems/last-day-where-you-can-still-cross/
44+
// discuss: https://leetcode.com/problems/last-day-where-you-can-still-cross/discuss/?currentPage=1&orderBy=most_votes&query=
45+
46+
// submission codes start here
47+
48+
impl Solution {
49+
pub fn latest_day_to_cross(row: i32, col: i32, cells: Vec<Vec<i32>>) -> i32 {
50+
0
51+
}
52+
}
53+
54+
// submission codes end
55+
56+
#[cfg(test)]
57+
mod tests {
58+
use super::*;
59+
60+
#[test]
61+
#[ignore]
62+
fn test_1970_example_1() {
63+
let row = 3;
64+
let col = 2;
65+
let cells = vec![vec![1, 1], vec![2, 1], vec![1, 2], vec![2, 2]];
66+
67+
let result = 2;
68+
69+
assert_eq!(Solution::latest_day_to_cross(row, col, cells), result);
70+
}
71+
72+
#[test]
73+
#[ignore]
74+
fn test_1970_example_2() {
75+
let row = 2;
76+
let col = 2;
77+
let cells = vec![vec![1, 1], vec![1, 2], vec![2, 1], vec![2, 2]];
78+
79+
let result = 1;
80+
81+
assert_eq!(Solution::latest_day_to_cross(row, col, cells), result);
82+
}
83+
84+
#[test]
85+
#[ignore]
86+
fn test_1970_example_3() {
87+
let row = 3;
88+
let col = 3;
89+
let cells = vec![
90+
vec![1, 2],
91+
vec![2, 1],
92+
vec![3, 3],
93+
vec![2, 2],
94+
vec![1, 1],
95+
vec![1, 3],
96+
vec![2, 3],
97+
vec![3, 2],
98+
vec![3, 1],
99+
];
100+
101+
let result = 3;
102+
103+
assert_eq!(Solution::latest_day_to_cross(row, col, cells), result);
104+
}
105+
}

0 commit comments

Comments
 (0)