Explanation

554.Count How Many Times N Can Be Halved

Easy
Given a positive integer n, return how many times it can be halved (with integer division) before it becomes 1. The answer is ⌊log₂ n⌋, and the halving loop is the classic O(log n)Logarithmic Time O(log n)Work that grows by one step each time the input doubles, because every step cuts the problem in half. pattern: every step throws away half of what is left, so doubling the input adds just one more step. Binary search works the same way, which is why it can search a billion items in about 30 comparisons.

Example 1:

Input: n = 20

Output: 4

Example 2:

Input: n = 1

Output: 0

+ 5 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ n ≤ 1000000000

n =

20