three reverse are required for this.
- Reverse the whole string.
- Now count K from last.
- Reverse the first half (1 to n-k+1)
- reverse 2nd half (n-k+2 to n).
for Ex-
ABCDEF, n=6
rotate around D (K=4)
- 1st rotation FEDCBA
- Pivot is 6-4+1=3
- Rev FED
- Rev CBA
You will get
DEFABC
thats what you want.
--
Ajay Kr. Gautam
Postgraduate Student,
Dept. of Computer Science & Engg., IT-BHU
Varanasi-221005, UP
India
-----------------------------------------------------------------
"Easy reading is damned hard writing."
~ Nathaniel Hawthorne