FastPrepFastPrep
Problem Brief

Maximum Information (DA)

INTERNOA

There is a computer network consisting of n servers, or nodes, numbered from 1 to n, and each node has a security value security_val[i]. A hacker must choose a starting node, start jumping through the network compromising servers along the way until reaching the end. From node x, the hacker can jump to node (x + K). If node (x + K) does not exist, the jump is out of the network and the hack ends. Initially, the hacker has access to 0 servers with 0 security value. The security value at each compromised node is added to the hacker's security value sum, and values may be negative.

The task is to choose the starting node optimally such that the hacker compromises servers with the maximum possible security value sum.

1Example 1

Input
security_val = [2, -3, 4, 6, 1], k = 2
Output
7
Explanation
Example 1 illustration
The security value sum is security_val[1] + security_val[3] + security_val[5] = 2 + 4 + 1 = 7.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= n <= 10^6
  • -10^3 <= security_val[i] <= 10^3
  • 1 <= k <= n
public int maximumInformation(int[] security_val, int k) {
  // write your code here
}
Input

security_val

[2, -3, 4, 6, 1]

k

2

Output

7

Sign in to submit your solution.