#include <stdio.h>
void rotate_left(int arr[], int n, int k) {
// Your logic here
int i,j=0;
for(int i=0;i<k;i++){
for(j=0;j<n-1;j++){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
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;
}
int i,j=0; // step 1 :- intialize i and j with zero
for(int i=0;i<k;i++){ step 2:- iterate the loop till k times
for(j=0;j<n-1;j++){ step 3 :- iterate the loop till n-1 times
int temp = arr[j]; step 4 :- store the arr[j] in temp;
arr[j] = arr[j+1]; step 5 :- store the arr[j + 1] in arr[j]
arr[j+1] = temp; step 6 :- store the temp value in arr[j]
}
}
Input
5 2 1 2 3 4 5
Expected Output
3 4 5 1 2