Walmart Labs Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: Phone Interview
You could do a binary search for the square root. This is the most elementary approach that requires you to know the least math. It's also arguably a very comp-sciency way of doing it.
But the q asks abt .. most precise.. how can we get most precise value of a number using BS?
If we had to just return the |sqr_root(n)| to zero decimal places,
1) make a large array such that A[i]=i^2;
2) bin search this array for the input number(x) or the number just less than x(say y);
3) return index of x or y as per case.
Did they really expect someone to know NR for telephonic?? :O
Newton Raphson method.
- BVarghese January 09, 2012