4 ms·
i believe its cut off. 'read more' doesn't finish the sentence. this reminds me of the pancake sort problem, except there you can only flip a contiguous subarr
by pz 17y ago
i believe its cut off. 'read more' doesn't finish the sentence.
this reminds me of the pancake sort problem, except there you can only flip a contiguous subarray at the beginning. i got this in an interview once and then used it a few times when i had to interview folks. some people seem to get it right away... others... well, they don't
- Timothee 17y agoIt was cut off on Safari but not Firefox (for some reason). Here is the full text: You're given a vector V containing a permutation of the integers 0 to n-1. For example {0,2,1}. You're also given an integer N which is greater than or equal to 2 and less than V.size(). You can reverse N contiguous items in V at a time. For example V = {0,2,1} and N = 2 you can reverse the ints located in V[0] and V[1] to give V = {2,0,1}. You can also reverse the ints in V[1] and V[2] to give V = {0,1,2}. Write a function that takes V and N as parameters and returns the minimum number of reversals needed to sort the vector increasing. If it's not possible return -1. For example V = {0,2,1} N = 2 returns 1. (reverse V[1] and V[2])