Facebook | Phone Screen | Pancake Sorting
Anonymous User
1252

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 (4)