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 = 37

Output: log2 = 5

Example 2

n = 16

Output: log2 = 4

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Math problems