Quant Memo
Coding/●●●●●

Integer square root without a library call

You need the floor of n\sqrt{n} for an integer n >= 0, and you cannot use floating point (a risk system flagged rounding drift). Return the largest integer r with r * r <= n.

n = 8  -> 2      (2*2 = 4 <= 8, 3*3 = 9 > 8)
n = 16 -> 4
n = 0  -> 0

Return floor(sqrt(n)) using O(logn)O(\log n) integer operations.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions