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
7 Answers
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
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
This website seems to have Facebook Interview tips from a Facebook employee
https://www.rooftopslushie.com/search/facebook
One or more comments have been removed.
Please see our Community Guidelines or Terms of Service for more information.
To comment on this, Sign In or Sign Up.
Would you like us to review something? Please describe the problem with this {0} and we will look into it.
Your feedback has been sent to the team and we'll look into it.
static void merge(int[][]a){
int[]index=new int[a.length];
int total=0;
for(int i=0;i