Package g2401_2500.s2498_frog_jump_ii
Class Solution
java.lang.Object
g2401_2500.s2498_frog_jump_ii.Solution
2498 - Frog Jump II.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>stones</code> sorted in <strong>strictly increasing order</strong> representing the positions of stones in a river.</p>
<p>A frog, initially on the first stone, wants to travel to the last stone and then return to the first stone. However, it can jump to any stone <strong>at most once</strong>.</p>
<p>The <strong>length</strong> of a jump is the absolute difference between the position of the stone the frog is currently on and the position of the stone to which the frog jumps.</p>
<ul>
<li>More formally, if the frog is at <code>stones[i]</code> and is jumping to <code>stones[j]</code>, the length of the jump is <code>|stones[i] - stones[j]|</code>.</li>
</ul>
<p>The <strong>cost</strong> of a path is the <strong>maximum length of a jump</strong> among all jumps in the path.</p>
<p>Return <em>the <strong>minimum</strong> cost of a path for the frog</em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2022/11/14/example-1.png" alt="" /></p>
<p><strong>Input:</strong> stones = [0,2,5,6,7]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> The above figure represents one of the optimal paths the frog can take.</p>
<p>The cost of this path is 5, which is the maximum length of a jump.</p>
<p>Since it is not possible to achieve a cost of less than 5, we return it.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2022/11/14/example-2.png" alt="" /></p>
<p><strong>Input:</strong> stones = [0,3,9]</p>
<p><strong>Output:</strong> 9</p>
<p><strong>Explanation:</strong> The frog can jump directly to the last stone and come back to the first stone.</p>
<p>In this case, the length of each jump will be 9. The cost for the path will be max(9, 9) = 9.</p>
<p>It can be shown that this is the minimum achievable cost.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= stones.length <= 10<sup>5</sup></code></li>
<li><code>0 <= stones[i] <= 10<sup>9</sup></code></li>
<li><code>stones[0] == 0</code></li>
<li><code>stones</code> is sorted in a strictly increasing order.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxJump
public int maxJump(int[] stones)
-