Facebook

  www.facebook.com
Work in HR? Unlock Free Profile

Facebook Software Engineer Interview Question

I interviewed in Menlo Park, CA and was asked:
"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."
Add Tags [?]
Answer

Part of a Software Engineer Interview Review - one of 1,070 Facebook Interview Reviews

Answers & Comments

0
of 0
votes
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
3
of 3
votes
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
2
of 2
votes
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
1
of 4
votes
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;
        if(x==i)
              break;
    }

 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
3
of 3
votes
<?php

$a = 25;

print "The number is $a <br />";

$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 < 1) { print "The number is negative" ; }

    $prec = 0.00001;

    $start = 0;
    $end = $a;

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

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
0
of 0
votes
The answer by rajan should have i initialised at 1.
- anjali on Oct 9, 2012
0
of 0
votes
The answer by rajan should have i initialised at 1.
- anjali on Oct 9, 2012
0
of 0
votes
function sqroot($number){
 $squ = 0;
 $mod = 1;
 for($i = 0; $i < $number; $squ+=$mod, $i++){
     if($squ*$squ > $number){
       $squ-=$mod;
       $mod/=10;
     }
 }
 return $squ;
}
- Hesh on Nov 8, 2012

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.