FastPrepMaximum Value-Distance Jump Score

Maximum Value-Distance Jump Score

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

You start at index 0 of an integer array values and must finish at the last index. From index i, jump to any j > i.

A jump scores values[j] * (j-i). Return the maximum total score over a complete path to the final index. Use signed 64-bit arithmetic.

Function

maximumJumpScore(values: int[]) → long

Examples

Example 1

values = [3,10,2,12]return = 36

Jump directly from index 0 to 3 for 12*3=36.

Example 2

values = [0,5,1]return = 6

Jump 0→1 for 5, then 1→2 for 1.

Example 3

values = [7]return = 0

No jump is needed.

Constraints

  • 1 <= values.length <= 2000.
  • -10^9 <= values[i] <= 10^9.

More Google problems

See Google hiring insights
public long maximumJumpScore(int[] values) {
    // Write your code here.
}
values[3,10,2,12]
expected36
Checking account…