1765. Map of Highest Peak Medium

@problem@discussion
#Array#Breadth-First Search#Matrix



1/**
2 * [1765] Map of Highest Peak
3 *
4 * You are given an integer matrix isWater of size m x n that represents a map of land and water cells.
5 * 
6 * 	If isWater[i][j] == 0, cell (i, j) is a land cell.
7 * 	If isWater[i][j] == 1, cell (i, j) is a water cell.
8 * 
9 * You must assign each cell a height in a way that follows these rules:
10 * 
11 * 	The height of each cell must be non-negative.
12 * 	If the cell is a water cell, its height must be 0.
13 * 	Any two adjacent cells must have an absolute height difference of at most 1. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).
14 * 
15 * Find an assignment of heights such that the maximum height in the matrix is maximized.
16 * Return an integer matrix height of size m x n where height[i][j] is cell (i, j)'s height. If there are multiple solutions, return any of them.
17 *  
18 * Example 1:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82045-am.png" style="width: 220px; height: 219px;" />
20 * 
21 * Input: isWater = [[0,1],[0,0]]
22 * Output: [[1,0],[2,1]]
23 * Explanation: The image shows the assigned heights of each cell.
24 * The blue cell is the water cell, and the green cells are the land cells.
25 * 
26 * Example 2:
27 * <img alt="" src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82050-am.png" style="width: 300px; height: 296px;" />
28 * 
29 * Input: isWater = [[0,0,1],[1,0,0],[0,0,0]]
30 * Output: [[1,1,0],[0,1,1],[1,2,2]]
31 * Explanation: A height of 2 is the maximum possible height of any assignment.
32 * Any height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.
33 * 
34 *  
35 * Constraints:
36 * 
37 * 	m == isWater.length
38 * 	n == isWater[i].length
39 * 	1 <= m, n <= 1000
40 * 	isWater[i][j] is 0 or 1.
41 * 	There is at least one water cell.
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/map-of-highest-peak/
47// discuss: https://leetcode.com/problems/map-of-highest-peak/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn highest_peak(is_water: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
53        vec![]
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_1765() {
65    }
66}
67


Back
© 2025 bowen.ge All Rights Reserved.