Problem ยท Array

Minimize Computation Time

Learn this problem
โ— EasyPatreonINTERNOA

Problem statement

In a neural network, there are n layers, each with computational time represented by the array computationalTime. Developers are provided with an operation where they can select all layers with computation time c, an even integer. They then adjust parameters, reducing the processing time of these layers from c to c / 2. The task is to determine the minimum number of operations needed to ensure that the computational time of all layers is odd.

Function

minimizeComputationTime(computationalTime: int[]) โ†’ int

Examples

Example 1

computationalTime = [2, 4, 8, 16]return = 4

The optimal approach is:

  1. Choose c = 16 and reduce the computation time of layer 4 to 8. Thus, computationalTime = [2, 4, 8, 8].
  2. Choose c = 8 and reduce the computation time of layers 3 and 4 to 4. Thus, computationalTime = [2, 4, 4, 4].
  3. Choose c = 4 and reduce the computation time of layers 2, 3 and 4 to 2. Thus, computationalTime = [2, 2, 2, 2].
  4. Choose c = 2 and reduce the computation time of all the layers to 1. Thus, computationalTime = [1, 1, 1, 1].
The number of operations applied = 4. Thus, the answer returned is 4.

Constraints

๐Ÿ‡๐Ÿ‡

More Patreon problems

drafts saved locally
public int minimizeComputationTime(int[] computationalTime) {
  // write your code here
}
computationalTime[2, 4, 8, 16]
expected4
checking account