In-place array rotation
How do you rotate an array left by positions in time and extra space?
Show hints (2)+
- Reversal can be done in place.
- Three well-chosen reversals compose into a rotation.
Answer
Reveal answer →Final answer
Reverse first , reverse the rest, reverse the whole - the triple-reversal trick
Create a free account to see the full worked solution and track your progress.
Interview format: Hedge Fund Quant, Options Trading