Number of Steps to Reduce a Binary Number to One
Try to solve the Number of Steps to Reduce a Binary Number to One problem.
We'll cover the following
Statement
You are given a string, str
, as a binary representation of an integer. Your task is to return the number of steps needed to reduce it to
If the number is even, divide it by
. If the number is odd, add
to it.
You can always reach 1 for all provided test cases.
Constraints:
str.length
str
consists of charactersor .
Examples
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.