Back to problems

Implement Integer Square Root

Algorithm · JPMorgan · Medium

Given a non-negative 32-bit signed integer x, compute its integer square root: return the greatest integer r satisfying $$r \times r \le x$$. In other words, produce the truncated value of $$\sqrt{x}$$. Two restrictions apply. You may not call any library square-root routine, and you may not use an exponentiation (power) operator. Your arithmetic must remain correct across the entire supported input range, so no intermediate product is allowed to wrap around. Once your…

Checking your access…