#include <stdio.h>
void rotate_left(int arr[], int n, int k) {
// Your logic here
int left = 0;
int right = n - 1;
// every iteration we want to shift the array left
// we need to save the left most value to a var
// then insert it at right side of the array after all other
// shifting
for(int i=0; i<k; i++){
int tmp = arr[left];
for(int j=left; j<n; j++){
arr[j] = arr[j + 1];
}
arr[right] = tmp;
}
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
int arr[100];
// Read array elements
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
// Rotate the array
rotate_left(arr, n, k);
// Print the rotated array
for (int i = 0; i < n; i++) {
printf("%d", arr[i]);
if(i < n-1){
printf(" ");
}
}
return 0;
}
Input
5 2 1 2 3 4 5
Expected Output
3 4 5 1 2