Facebook Interview Question: The initial question (writing... | Glassdoor

Interview Question

Software Engineer Interview Menlo Park, CA

The initial question (writing a function to calculate a

  square root) ended up being the most difficult because it threw me off. I knew there was a good iterative method for doing so, but could not recall Newton's method in the moment, and I sadly let this nagging thought get in the way of my ability to work through the problem. My failure to perform well on that question set a negative tone for the rest of the interview, since each interviewer after the first can see notes from the previous interviewers.

Interview Answer

9 Answers


Do not get nervous. I think that they just wrote down the questions that were asked such that another interviewer would not ask the same question again.

anonymous on Aug 22, 2012

Interviewers at Facebook DO NOT share feedback with each other before the interview. Your experience in one interview will not affect the next one at all.

Anonymous on Sep 3, 2012

my experience was different (or perhaps it was a test of honesty)
In my face to face interview they asked me several questions that I had already answered in the phone interview. I told the guy that I had already answered these questions, and we moved on to a more open ended scenario discussion
I eventually got the job, hopefully start in 3 weeks, wish me luck

Anon on Sep 25, 2012

For square root u dont want to remember newtons method.

number = 9

 N*N = number

    N = 9/N

   for(int i=0;i<N/2;i++)
         x = number/i;

 i know the efficiency is not good, its not bad too.

but i can understand why this didnt strike u at first.

Balaprasath Rajan on Sep 26, 2012


$x = sqrt($a);

print "The sqrt is $x";
if (!function_exists('sqrt')) {
function sqrt ($a){
    if ($a == 1 || $a == 0) { print "The sqrt of $a is $a "; }

    if ($a $prec) {
        $mid = ($start + $end)/2;
        $midsq = $mid*$mid;
        if ($midsq == $a) { return $mid; }
        else if ($midsq

Its important to understand the problem and try to solve it by hand first. Once you have figured out your solution use appropriate alogrithm techniques. Most likely its one you know or something you've come across during your coursework. The interviewer usually looks for your approach most of the time than the final solution. I hope this helps.

Anonymous on Oct 3, 2012

The answer by rajan should have i initialised at 1.

anjali on Oct 9, 2012

The answer by rajan should have i initialised at 1.

anjali on Oct 9, 2012

function sqroot($number){
 $squ = 0;
 $mod = 1;
 for($i = 0; $i $number){
 return $squ;

Hesh on Nov 8, 2012

import java.util.Scanner;

public class SquareRoot {

    public static void main(String[] args) {
        final Scanner in = new Scanner(System.in);
        while (true) {
            System.out.println("Enter number : ");
            System.out.println("Sq.Root is : " + sqRoot(in.nextInt()));

    private static float sqRoot(int num) {
        float guess = num/2f;

        float prevGuess = num;
        while (prevGuess != guess) {
            System.out.println ("Sqroot for " + num + " is guess " + guess);
            float adjustment = 1 - guess*guess/num;
            prevGuess = guess;
            guess += adjustment;

        return guess;


Ker on Feb 23, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.