Class Solution
java.lang.Object
g1601_1700.s1631_path_with_minimum_effort.Solution
1631 - Path With Minimum Effort.<p>Medium</p>
<p>You are a hiker preparing for an upcoming hike. You are given <code>heights</code>, a 2D array of size <code>rows x columns</code>, where <code>heights[row][col]</code> represents the height of cell <code>(row, col)</code>. You are situated in the top-left cell, <code>(0, 0)</code>, and you hope to travel to the bottom-right cell, <code>(rows-1, columns-1)</code> (i.e., <strong>0-indexed</strong> ). You can move <strong>up</strong> , <strong>down</strong> , <strong>left</strong> , or <strong>right</strong> , and you wish to find a route that requires the minimum <strong>effort</strong>.</p>
<p>A route’s <strong>effort</strong> is the <strong>maximum absolute difference</strong> in heights between two consecutive cells of the route.</p>
<p>Return <em>the minimum <strong>effort</strong> required to travel from the top-left cell to the bottom-right cell.</em></p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/10/04/ex1.png" alt="" /></p>
<p><strong>Input:</strong> heights = [[1,2,2],[3,8,2],[5,3,5]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells. This is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/10/04/ex2.png" alt="" /></p>
<p><strong>Input:</strong> heights = [[1,2,3],[3,8,4],[5,3,5]]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].</p>
<p><strong>Example 3:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/10/04/ex3.png" alt="" /></p>
<p><strong>Input:</strong> heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> This route does not require any effort.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>rows == heights.length</code></li>
<li><code>columns == heights[i].length</code></li>
<li><code>1 <= rows, columns <= 100</code></li>
<li><code>1 <= heights[i][j] <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumEffortPath
public int minimumEffortPath(int[][] heights)
-