141. Swim in Rising Water

HardArrayArray

Given an n x n grid where grid[i][j] is the elevation, water level rises over time. At time t you can swim between adjacent cells if both have elevation <= t. Return the least time to reach (n-1,n-1) from (0,0). Input: JSON 2D grid.

Input: A JSON n x n integer grid.

Output: Integer — minimum time.

Examples

Example 1
Input: [[0,2],[1,3]]
Output: 3
Explanation: Must wait until time 3 to reach bottom-right.
Example 2
Input: [[0]]
Output: 0
Explanation: Already at destination.

Constraints

Asked by

MetaGoogleAmazonMicrosoftBloomberg
Solve this problem in the editor →