Facebook Interview Question


Country: United States
Interview Type: Phone Interview




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

the missing and very relevant constraint is that the input numbers can be negative and the returned array should be sorted

- Carlos February 26, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// ZoomBA
// Not in place 
l = list ( arr ) -> { $.o ** 2 }
// in place 
fold ( arr ) -> { $.c[$.i] = $.o ** 2 }

- NoOne January 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function squareNums(arr) {
  return arr.map(function(val) { 
    return Math.pow(val, 2); // or return val * val;
  });
}

- IdontKNow January 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function square(arr) {
  return arr.map(function(val) {
    return Math.pow(val, 2);
  });

}

- dontKnow January 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function square(arr) {
  return arr.map(function(val) {
    return Math.pow(val, 2);
  });

}

- dontKnow January 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Use Power function in log time
int power(int x, unsigned int y)
{
int temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}

2. Use hash for duplicate numbers in the set.

I am still trying to understand the rationale behind this question.

- ankushbindlish January 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void squareArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = (int) Math.pow(array[i], 2);
        }
    }

- farazromani January 23, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why is everyone giving complicated solutions? Am I missing something?

x <- c(1,3,9)
res <- x^2

myfun <- function(x) {
x <- x
res <- x ^ 2
return(res)
}

myfun(x)

- Anonymous February 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Seems like a simple question

public class FacebookQuestion {
  
  public static void main(String[] args)
  {
    int[] input = {1,3,5};
    
    System.out.print("input array: {");
    
    for(int i = 0; i < input.length; i++){
      System.out.print(input[i]);
      if(i < input.length - 1){
      	System.out.print(", ");
      }
    }
    
    System.out.println("}");
    
    
    int[] squareArray = squareArray(input);
    
    System.out.print("squared array: {");
    
    for(int i = 0; i < squareArray.length; i++){
      System.out.print(squareArray[i]);
      if(i < squareArray.length - 1){
      	System.out.print(", ");
      }
    }
    
    System.out.println("}");
    
  }
  
  public static int[] squareArray(int[] input){
    
    for(int i = 0; i < input.length; i++){
    
    	input[i] = input[i] * input[i];
      
    }
    
    return input;
    
  }
}

- DCIS February 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public void squareArray(int[] inputArray)
{	    
	    int length = inputArray.length;
	    for(int i = 0 ;i < length; i++)
	    {
	    	inputArray[i] = inputArray[i] * inputArray[i];
	    }
	   System.out.print(Arrays.toString(inputArray));		
}

- Dhara Padia February 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

squareArray = fmap (^2)

- yilmazhuseyin February 07, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C# IEnumerable LINQ

static int[] Squares(int[] arr)
{
	return arr.Select(i => i * i).ToArray();
}

- JMcG February 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static int[] Squares(int[] arr)
{
            return arr.Select(i => i * i).ToArray();
}

- JMcG February 13, 2017 | Flag Reply


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