Company: Rippling_13_feb
Difficulty: medium
Equalize Neural Network Layers Problem Description A neural network has n layers, where the number of neurons in the i th layer is layer[i] . In each generation, the system adjusts the neurons as follows: In odd generations: 1 neuron can be added to at most one layer. In even generations: 2 neurons can be added to at most one layer. Find the minimum generation in which all layers can have an equal number of neurons. Example 1 Input: layer = [1, 1, 2, 4] Output: 6 Explanation: The goal is to make all layers have the same number of neurons. Since we can only add neurons, the target number must be the maximum value in the current array, which is 4. The number of neurons to add to each layer is: Layer 1: 4 - 1 = 3 neurons Layer 2: 4 - 1 = 3 neurons Layer 3: 4 - 2 = 2 neurons Layer 4: 4 - 4 = 0 neurons To add neurons efficiently, we use as many even generations (adding 2 neurons) as possible. To add 3 neurons: use one even generation (+2) and one odd generation (+1). To add 2 neurons: use o