Company: Salesforce_7jan
Difficulty: medium
Salesforce data processing system Problem Description A cloud infrastructure team is building an energy-efficient way to manage server power. Given a positive integer n representing a server's starting energy level, one operation can adjust that level using either of these moves: Increase the energy level by 2 i for any i ≥ 0 Decrease the energy level by 2 i for any i ≥ 0 Work out the smallest number of such operations needed to bring the energy level n all the way down to 0, so the server can shut down cleanly. Example 1 Input: n = 5 Output: 2 Explanation: n can be reduced to 0 using two operations. Choose i = 0, subtract 2 0 from 5, 5 - 1 = 4. Choose i = 2, and subtract 2 2 from 4, 4 - 4 = 0. The answer is 2. It can be shown that the answer cannot be less than 2. Example 2 Input: n = 21 Output: 3 Explanation: Choose i = 0, subtract 2 0 = 1 from 21 converting it to 20. Choose i = 2, subtract 2 2 = 4 from 20 converting it to 16. Choose i = 4, subtract 2 4 = 16 from 16 converting