FastPrepFastPrep
Problem Brief

Minimize Computation Time

INTERNOA

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.

1Example 1

Input
computationalTime = [2, 4, 8, 16]
Output
4
Explanation

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

Limits and guarantees your solution can rely on.

๐Ÿ‡๐Ÿ‡
public int minimizeComputationTime(int[] computationalTime) {
  // write your code here
}
Input

computationalTime

[2, 4, 8, 16]

Output

4

Sign in to submit your solution.