2498. Frog Jump II Medium
1/**
2 * [2498] Frog Jump II
3 *
4 * You are given a 0-indexed integer array stones sorted in strictly increasing order representing the positions of stones in a river.
5 * 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 at most once.
6 * The length 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.
7 *
8 * More formally, if the frog is at stones[i] and is jumping to stones[j], the length of the jump is |stones[i] - stones[j]|.
9 *
10 * The cost of a path is the maximum length of a jump among all jumps in the path.
11 * Return the minimum cost of a path for the frog.
12 *
13 * <strong class="example">Example 1:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2022/11/14/example-1.png" style="width: 600px; height: 219px;" />
15 * Input: stones = [0,2,5,6,7]
16 * Output: 5
17 * Explanation: The above figure represents one of the optimal paths the frog can take.
18 * The cost of this path is 5, which is the maximum length of a jump.
19 * Since it is not possible to achieve a cost of less than 5, we return it.
20 *
21 * <strong class="example">Example 2:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2022/11/14/example-2.png" style="width: 500px; height: 171px;" />
23 * Input: stones = [0,3,9]
24 * Output: 9
25 * Explanation:
26 * The frog can jump directly to the last stone and come back to the first stone.
27 * In this case, the length of each jump will be 9. The cost for the path will be max(9, 9) = 9.
28 * It can be shown that this is the minimum achievable cost.
29 *
30 *
31 * Constraints:
32 *
33 * 2 <= stones.length <= 10^5
34 * 0 <= stones[i] <= 10^9
35 * stones[0] == 0
36 * stones is sorted in a strictly increasing order.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/frog-jump-ii/
42// discuss: https://leetcode.com/problems/frog-jump-ii/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn max_jump(stones: Vec<i32>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_2498() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.