Long Jumps Problem

Long Jumps Problem — ExecCode Medium DSA Practice

Solve the Long Jumps problem on ExecCode. Free online medium DSA practice in DP. Write and run code in Java, C++, Python — no signup required to run.

Problem description

a is an array of positive integers. Starting at an index i, add a[i] to the score and jump to index i + a[i]. Keep jumping while the next index stays inside the array. Return the maximum score that can be collected by choosing any starting index. Use a 64-bit integer. You are given: a — positive integers Return the maximum score. Each value is positive, so every jump moves forward. A start that immediately leaves the array scores only a[i].

Examples

Input {'a': [3, 2, 1, 2, 3]}; Output 5. Input {'a': [1, 1, 1]}; Output 3. Input {'a': [1]}; Output 1

Constraints

1 <= n <= 1e5 where n = a.length 1 <= a[i] <= 1e5 The score can be large, so use a 64-bit integer O(n^2) from every start will Time Limit Exceed

Practice Long Jumps free on ExecCode. Browse DSA problems, topic map, and placement guides.