Step 1 :
Reverse the first k elements.
Step 2:
Reverse the k+1 to n-1 elements.
Step 3:
Reverse the whole array.
Prefect!!!
Example :
arr=[1,2,3,4,5] , k=2
expected output : [3,4,5,1,2]
step 1:
[2,1,3,4,5]
step 2:
[2,1,5,4,3]
step 3:
[3,4,5,1,2]
Got it!
No comments:
Post a Comment