You are viewing a single comment's thread. Return to all comments →
There is no need to do copying of data. The question is just to print out the values. The following code suffices, I think.
b = a + k;
for(b_i = 0; b_i < n; b_i++)
if((int)(b - a) >= n)
b = a;
I also thought the same. Even if the rotations are made subsequent we can have two pointers x and y take care of the start of new array after rotations and end of new array after rotations. Then we can print from x to y.(Only in case of multiple query)
I don't think that's a valid assumption. The question is pretty clear about that:
"perform left rotations ON THE ARRAY. THEN print THE UPDATED ARRAY as a single line of space-separated integers."
Not sure about that. The instructions are two fold, and they distinguish between rotations and printing. I think it's expecting the values to physically shift.
"perform left rotations on the array. Then print the updated array as a single line of space-separated integers."