3 ms·
I don't think it works that way. 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
by Timothee 18y ago
I don't think it works that way.
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.
So, you always revert the same number of elements in the vector. In your example, you revert 5 elements and then 4.
Your example would give the following sequence:
[1 2 3 4 5 6]
[1 6 5 4 3 2]
[3 4 5 6 1 2]
[3 2 1 6 5 4]
[5 6 1 2 3 4]
[5 4 3 2 1 6]
[1 2 3 4 5 6]
For that case (6 elements and N=5), it looks like not many vectors V have a solution... but I'm too tired to keep going :)
- endtime 18y agoWhoops, you're right, I didn't read it correctly.