Number of Steps to Reduce a Number to Zero Problem

Number of Steps to Reduce a Number to Zero Problem — ExecCode Easy DSA Practice

Solve the Number of Steps to Reduce a Number to Zero problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer num, return the number of steps to reduce it to zero. Your task is to in one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. Return the required answer exactly as shown in the examples.

Examples

Input {"num": 14}; Output 6. Input {"num": 8}; Output 4

Constraints

0 <= num <= 10^6

Practice Number of Steps to Reduce a Number to Zero free on ExecCode. Browse DSA problems, topic map, and placement guides.