FunctionRacerProblemsRace

Steps to Reduce to Zero

BeginnerMathPython, JavaScript, TypeScript, Java, C++

In one step, if the current number is even divide it by 2, otherwise subtract 1. Return how many steps it takes to reach 0 starting from num.

Example 1

num 14
returns 6

14, 7, 6, 3, 2, 1, 0: six steps.

Example 2

num 0
returns 0

Already zero.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems