1345. Jump Game IV Hard
1/**
2 * [1345] Jump Game IV
3 *
4 * Given an array of integers arr, you are initially positioned at the first index of the array.
5 * In one step you can jump from index i to index:
6 *
7 * i + 1 where: i + 1 < arr.length.
8 * i - 1 where: i - 1 >= 0.
9 * j where: arr[i] == arr[j] and i != j.
10 *
11 * Return the minimum number of steps to reach the last index of the array.
12 * Notice that you can not jump outside of the array at any time.
13 *
14 * Example 1:
15 *
16 * Input: arr = [100,-23,-23,404,100,23,23,23,3,404]
17 * Output: 3
18 * Explanation: You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.
19 *
20 * Example 2:
21 *
22 * Input: arr = [7]
23 * Output: 0
24 * Explanation: Start index is the last index. You do not need to jump.
25 *
26 * Example 3:
27 *
28 * Input: arr = [7,6,9,6,9,6,9,7]
29 * Output: 1
30 * Explanation: You can jump directly from index 0 to index 7 which is last index of the array.
31 *
32 *
33 * Constraints:
34 *
35 * 1 <= arr.length <= 5 * 10^4
36 * -10^8 <= arr[i] <= 10^8
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/jump-game-iv/
42// discuss: https://leetcode.com/problems/jump-game-iv/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn min_jumps(arr: 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_1345() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.