Easy · Math
Log two
Given an integer n, return floor(log₂ n), the number of times n can be halved (rounding down) before it reaches 1, or −1 if n ≤ 0.
Examples
Example 1
n = 37Output: log2 = 5
Example 2
n = 16Output: log2 = 4
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.