Skip to content

Commit 459f1ce

Browse files
committed
Create README - LeetHub
1 parent 92f2ec1 commit 459f1ce

File tree

1 file changed

+34
-0
lines changed
  • Dynamic Programming/1162-as-far-from-land-as-possible

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<h2><a href="https://leetcode.com/problems/as-far-from-land-as-possible/">1162. As Far from Land as Possible</a></h2><h3>Medium</h3><hr>Can you solve this real interview question? As Far from Land as Possible - Given an n x n grid containing only values 0 and 1, where 0 represents water and 1 represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return -1.
2+
3+
The distance used in this problem is the Manhattan distance: the distance between two cells (x0, y0) and (x1, y1) is |x0 - x1| + |y0 - y1|.
4+
5+
 
6+
7+
Example 1:
8+
9+
[https://assets.leetcode.com/uploads/2019/05/03/1336_ex1.JPG]
10+
11+
12+
Input: grid = [[1,0,1],[0,0,0],[1,0,1]]
13+
Output: 2
14+
Explanation: The cell (1, 1) is as far as possible from all the land with distance 2.
15+
16+
17+
Example 2:
18+
19+
[https://assets.leetcode.com/uploads/2019/05/03/1336_ex2.JPG]
20+
21+
22+
Input: grid = [[1,0,0],[0,0,0],[0,0,0]]
23+
Output: 4
24+
Explanation: The cell (2, 2) is as far as possible from all the land with distance 4.
25+
26+
27+
 
28+
29+
Constraints:
30+
31+
* n == grid.length
32+
* n == grid[i].length
33+
* 1 <= n <= 100
34+
* grid[i][j] is 0 or 1

0 commit comments

Comments
 (0)