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

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Math problems