Facebook Interview Question
347 Interview Reviews |
Back to all Facebook Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at Facebook:
Compute the square root of a number down to a certain precision. ie sqrt(num, precision) returns a number that is in-between sqrt(num) - precision and sqrt(num) + precision.
Helpful Question?
Yes |
No
Inappropriate?



1 of 1 people found this helpful
by Newton Rapheson:
while (x * x - num).abs > precision
x -= (x * x - num) / (2 * x)
end
More generally, x -= (f(x) / f'(x)), and the derivative of (x * x - num) is 2x.