Process Execution

Reported in interviews at Citadel

Problem statement

A cloud platform added n processors; the i-th provides compute power power[i]. Processors interfere: if you use a processor of power v, then every processor whose power is v + 1 or v - 1 becomes unusable. You may, however, use all processors of power exactly v together. Each processor is used at most once. Choose a subset of processors to maximize the total chosen power, and return that maximum.

Implement:

def getMaximumPower(power):

It returns the maximum achievable sum of chosen powers (use 64-bit / arbitrary precision integers).

Example: power = [3, 3, 3, 4, 4, 1, 8]. Take all three processors of power 3 (total 9), the one of power 1, and the one of power 8; you cannot also take the 4s because 4 is adjacent to 3. Sum = $9 + 1 + 8 = 18$, which is the maximum, so the answer is 18.

Show hint

Does it matter which individual processor of a given power you use, or only which power values you commit to?

Relevant roles: ML Engineer, MLOps Engineer, Forward Deployed Engineer and AI Engineer.

Related free problems