Most Indices Visited by Bounded Downhill Jumps

Quick Overview

Most Indices Visited by Bounded Downhill Jumps. Choose any starting index. A jump from i to j is legal when0<abs(i-j)<=d, j is in bounds, and arr[i] is strictly greater than arr[j] and every intervening value.

Most Indices Visited by Bounded Downhill Jumps

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Choose any starting index. A jump from i to j is legal when 0<abs(i-j)<=d, j is in bounds, and arr[i] is strictly greater than arr[j] and every intervening value. Return the greatest number of indices that can be visited, including the start. ```cpp class Solution { public: int maxJumps(vector<int>& arr, int d); }; ``` ### Examples **Example 1:** ```text Input: arr = [5,4,3], d = 1 Output: 3 Explanation: Jump0->1->2, visiting every index. ``` **Example 2:** ```text Input: arr = [4,2,4,1], d = 3 Output: 2 Explanation: A4 can reach a neighboring lower value but cannot cross the other4. No lower destination has a further legal downhill jump. ``` ### Constraints - The array length is 1 to 1000. - Values are integers in `[1,100000]`. - `1 <= d <= arr.length`. ### Contract considerations The start is freely chosen, but no jump can leave the array or pass a nonlower blocker. ```hint Read the boundary condition Check equal-height barriers and destinations near either array boundary. Count visited indices, including the freely chosen start. ``` ### Boundary reminders The start is freely chosen, but no jump can leave the array or pass a nonlower blocker.

Overview: Most Indices Visited by Bounded Downhill Jumps. Choose any starting index. A jump from i to j is legal when0<abs(i-j)<=d, j is in bounds, and arr[i] is strictly greater than arr[j] and every intervening value.

Google logo
Google
Jun 11, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Choose any starting index. A jump from i to j is legal when 0<abs(i-j)<=d, j is in bounds, and arr[i] is strictly greater than arr[j] and every intervening value. Return the greatest number of indices that can be visited, including the start.

class Solution {
public:
    int maxJumps(vector<int>& arr, int d);
};

Examples

Example 1:

Input: arr = [5,4,3], d = 1
Output: 3
Explanation: Jump0->1->2, visiting every index.

Example 2:

Input: arr = [4,2,4,1], d = 3
Output: 2
Explanation: A4 can reach a neighboring lower value but cannot cross the other4. No lower destination has a further legal downhill jump.

Constraints

  • The array length is 1 to 1000.
  • Values are integers in [1,100000] .
  • 1 <= d <= arr.length .

Contract considerations

The start is freely chosen, but no jump can leave the array or pass a nonlower blocker.

Boundary reminders

The start is freely chosen, but no jump can leave the array or pass a nonlower blocker.