As reported: Oracle Senior Engineer (US) tech screen with a principal engineer, Mar 2025 — 10 minutes of introductions, then on HackerRank: write a function that returns the square root of a number with precision to 4 decimal places.
Write a function that returns the square root of a non-negative number x, accurate to 4 decimal places — within 0.0001 of the true value. Don't use a built-in square root or power function.
Example 1
x = 16
Output: 4.0000
Example 2
x = 2
Output: 1.4142
Example 3
x = 0.25
Output: 0.5000
Constraints: 0 ≤ x ≤ 10^9; x may have a fractional part.
Code runner format: one JSON value per line — x. Implement squareRoot(x) returning a floating-point number; the harness prints "OK" when the result is within 0.0001 of the true square root, otherwise both values.