Facebook Interview Question: Display the sorted output of ... | Glassdoor

Interview Question

Software Engineer Interview

Display the sorted output of a merge of any number of

  sorted arrays. Then do it again, more efficiently.
Answer

Interview Answer

7 Answers

4

static void merge(int[][]a){
        int[]index=new int[a.length];
        int total=0;
        for(int i=0;i

Anonymous on Sep 21, 2014
5

pop one element from every sorted array and put into a heap, pop 1 from heap and display, pop another element from the sorted array that min element came from to heap, repeat until all arrays are empty and heap is empty

Anonymous on Oct 7, 2014
1

public Integer[] mergeSort(ArrayList input, int start, int end) {
  if(start == end) {
     return input.get(end);
  }
  if(start == end-1) {
     return merge(input.get(start), input.get(end));
  }
  Integer[] first = mergeSort(input, start, (start + end)/2);
  Integer[] second = mergeSort(input, (start + end)/2 + 1, end);
  return merge(first, second);
}
// merge(first, second) - is regular merging of two arrays

ss on Jan 12, 2015
0

This website seems to have Facebook Interview tips from a Facebook employee

https://www.rooftopslushie.com/search/facebook

Anonymous on Oct 2, 2019

One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.

Add Answers or Comments

To comment on this, Sign In or Sign Up.