Easy · Strings
Number of Steps to Reduce a Number in Binary to One
Given the binary representation s of a positive integer (no leading zeros), return the number of steps needed to reduce it to 1, where each step halves the number if it is even and adds 1 to it if it is odd.
Examples
Example 1
{
"s": "1101"
}Output: 6 steps
Example 2
{
"s": "10"
}Output: 1 step
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.