I encountered a simple (as I thought) exercise of rotating string:
To rotate string by K characters means to cut these characters from the beginning and transfer them to the end. If K is negative, characters, on contrary should be transferred from the end to the beginning.
I at once invented solution which uses concatenation of two substrings. However, I found the following addition:
if you want more serious challenge, you are encouraged to perform rotation "in-place"
task is from here - be sure it is not my college assignment etc
I could not see any simple way to do this (I suppose there should be O(N) algorithm). If I copy 0-th char to temporary variable and copy K-th char to its place, then 2K-th char to the place of K-th etc. - I will succeed provided that K and string length are co-prime. I think I can manage with other Ks adding outer loop to repeat the process from 1-th char, then 2-th etc - I think up to GCD(K, strlen(S))
But it looks too clumsy.