Fewest Adjacent-or-Equal-Value Jumps to the Last Index

Quick Overview

Fewest Adjacent-or-Equal-Value Jumps to the Last Index. Start at index0. In one step, move to an in-bounds neighboring index or to any different index holding the same value.

Fewest Adjacent-or-Equal-Value Jumps to the Last Index

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Start at index 0. In one step, move to an in-bounds neighboring index or to any different index holding the same value. Return the minimum steps to the last index. ```cpp class Solution { public: int minJumps(vector<int>& arr); }; ``` ### Examples **Example 1:** ```text Input: arr = [8,1,2,8,4] Output: 2 Explanation: Jump0->3 using equal8 values, then3->4. The destination is not reachable in one step. ``` **Example 2:** ```text Input: arr = [3,2,1] Output: 2 Explanation: Distinct values leave only neighboring jumps, requiring0->1->2. ``` ### Constraints - arr contains 1 to 50000 integers. - Each value is in `[-100000000,100000000]`. ### Contract considerations Equal values may be far apart; jumps are by value equality, not numeric closeness. ```hint Read the boundary condition Check a one-element array and repeated values at distant indices. Every allowed jump has the same step cost. ``` ### Boundary reminders Equal values may be far apart; jumps are by value equality, not numeric closeness.

Overview: Fewest Adjacent-or-Equal-Value Jumps to the Last Index. Start at index0. In one step, move to an in-bounds neighboring index or to any different index holding the same value.

Amazon logo
Amazon
Aug 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Start at index 0. In one step, move to an in-bounds neighboring index or to any different index holding the same value. Return the minimum steps to the last index.

class Solution {
public:
    int minJumps(vector<int>& arr);
};

Examples

Example 1:

Input: arr = [8,1,2,8,4]
Output: 2
Explanation: Jump0->3 using equal8 values, then3->4. The destination is not reachable in one step.

Example 2:

Input: arr = [3,2,1]
Output: 2
Explanation: Distinct values leave only neighboring jumps, requiring0->1->2.

Constraints

  • arr contains 1 to 50000 integers.
  • Each value is in [-100000000,100000000] .

Contract considerations

Equal values may be far apart; jumps are by value equality, not numeric closeness.

Boundary reminders

Equal values may be far apart; jumps are by value equality, not numeric closeness.