Facebook | Phone Screen | Pancake Sorting

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-11-15Added By Anonymous
Source: Link

Company: Meta
Role: e3, e4
Interview Stage: Phone Screen
Location: New York
Year: unknown

Original Post Content:

Location: New York

Question:
https://leetcode.com/problems/pancake-sorting/

Given a method reverse:

/**
* Reverse the first k elements.
* Eg. [2,3,1,5,4] and k =3
* Output : [2,3,1,5,4]
*/
void reverse(int[] arr, k);

write another method which will sort the array by incorporating reverse method inside sort.

sort(int[] arr) {
// call reverse method
}

You must have to call reverse(arr,k) method to sort the array. You are not allowed to modify the reverse method
final out put [1,2,3,4,5], and this is inplace reverse and sorting

Comments