unknown Interview Question
Software Engineer / Developersyes!
1) reverse the array.
2) reverse 0 to (k-1)th indexed part of array.
3) reverse k to (n-1)th indexed part of array.
original array 2 7 9 1 8 7 3
if we have to rotate right by 2 units. (k=2).
step 1: reverse it
3 7 8 1 9 7 2
step 2: reverse 0 to 1 st index
7 3 8 1 9 7 2
step 3: reverse 2nd to last
7 3 2 7 9 1 8
this is the required solution
Is there any in space O(n) algo for this problem ?
- Frodo Baggins August 21, 2010