Walmart Labs Interview Question for Software Engineer / Developers


Country: India
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
4
of 4 vote

Newton Raphson method.

public static double Sqroot(double x)
        {
            double fa = x / 2;
            double sa = x / fa;
            double ta = (fa + sa) / 2.0;
            while (Math.Abs(x - Math.Pow(ta, 2)) > 0.000000001)
            {
                fa = ta;
                sa = x / fa;
                ta = (fa + sa) / 2;
            }
            return ta;
        }

- BVarghese January 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

also called Babylonian method

- forkloop January 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

use Newton raphson method to get upto desired precision value

- scofield23 January 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

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.

- eugene.yarovoi January 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

But the q asks abt .. most precise.. how can we get most precise value of a number using BS?

- CST November 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@CST: I'm not sure I understand your question. If you want to know how I'd do it up to a certain precision, the answer is that the precision setting would determine how many iterations of the binary search I'd do.

- eugene.yarovoi November 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- Yoda July 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I would think that you'd be fine doing a binary search.

- eugene.yarovoi July 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@eugene.yarovoi, Can you please explain your solution a little.

> Do a binary search

Of what?

- Anon August 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

On the answer. Guess an answer, square it, and see if the square is too big or too small. This approach can be used for any monotonely increasing function.

- eugene.yarovoi August 28, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More