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.

Interview Answer

7 Answers


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

Anonymous on Sep 21, 2014

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

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

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


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.