Correctness, Invariants & Design
![Question 2.15, GATE 2000: For array s[1…n] and 1≤k≤n, execute reverse(s,1,k),reverse(s,k+1,n),reverse(s,1,n). Does this rotate left by k,leave unchanged,reverse everything,or none?](../../assets/questions/CS-2000-Q38-1.webp)
![Question 2.15, GATE 2000: For array s[1…n] and 1≤k≤n, execute reverse(s,1,k),reverse(s,k+1,n),reverse(s,1,n). Does this rotate left by k,leave unchanged,reverse everything,or none?](../../assets/questions/CS-2000-Q38-2.webp)
Your answer
Answer & solution
Answer: A (no official key was published)
Step 1: Split the original array into consecutive blocks A=s[1…k] and B=s[k+1…n], so it is AB. The first two operations produce AR BR.
Step 2: Reversing the whole concatenation reverses block order and each block: (AR BR)R=BA. This moves the first k entries to the end while preserving order within each block.
Thus A, a left rotation by k. For k=n, the second range is empty and must be treated as a no-op; the full rotation leaves the array unchanged.