Google OA

Maximize Power Values Sum

You are provided with an array containing N power values, each representing a specific power level. Additionally, a value K is given, signifying that choosing a power value X excludes any other power values within the range of X-K to X+K exclude X itself. Your objective is to determine the maximum sum achievable by selecting the optimal power values.

Example 1 :
Input:
powerValues = [1, 2, 3, 10, 9], k = 2
Output:
13