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
Core interview problems are free with a full runner and lessons; Pro opens the complete library.