Problem · Array

Maximum Information (DA)

Learn this problem
EasyJPMorgan ChaseINTERNOA

Problem statement

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.

Function

maximumInformation(security_val: int[], k: int) → int

Examples

Example 1

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

Constraints

  • 1 <= n <= 10^6
  • -10^3 <= security_val[i] <= 10^3
  • 1 <= k <= n

More JPMorgan Chase problems

drafts saved locally
public int maximumInformation(int[] security_val, int k) {
  // write your code here
}
security_val[2, -3, 4, 6, 1]
k2
expected7
checking account