Floor Square Roots for an Array
Problem statement
Given an array of nonnegative integers values, return an array where result i is the floor square root of values[i].
For a number x, its floor square root is the largest integer r such that r * r <= x.
Function
floorSquareRoots(values: int[]) → int[]Examples
Example 1
values = [0,1,4,9,16]return = [0,1,2,3,4]Every value is a perfect square.
Example 2
values = [2,8,15,26]return = [1,2,3,5]Each result is rounded down to the largest integer whose square does not exceed the input.
Example 3
values = [2147395600,2147483647]return = [46340,46340]Both values have floor square root 46340; multiplication must avoid 32-bit overflow.
Constraints
1 <= values.length <= 10^5.0 <= values[i] <= 2^31 - 1.