Fazil loves to preform different operations on arrays, and so being the Head of the higher education institution, he assigned a task to his new student Rohan.
Rohan will be provided with an integer array A of size N and an integer K , where she needs to rotate the array in the right direction by K steps and then print the resultant array.
As she is new to the school, please help her to complete the task.
Input:
The first line will consists of one integer T denoting the number of test cases.
For each test case:
The first line consists of two integers N and K,
N being the number of elements in the array and K denotes the number of steps of rotation.
The next line consists of N space separated integers , denoting the elements of the array A.
Output:
Print the array after rotation in the single line for each test case.
#include <stdio.h> int main() { int rot[100000];int n,k,j,i,t,tc; scanf("%d",&tc); while(tc--) { scanf("%d%d",&n,&k); for(j=0;j<n;j++) scanf("%d ",&rot[j]); for(j=0;j<k;j++) { t=rot[n-1]; for(i=n-1;i>0;i--) rot[i]=rot[i-1]; rot[i]=t; } for(i=0;i<n;i++) printf("%d ",rot[i]); printf("\n"); } return 0; }
INPUT_1:
2
5 2
67 45 39 31 56
6 4
14 19 37 62 81 93
OUTPUT:
31 56 67 45 39
37 62 81 93 14 19
INPUT_2:
3
5 1
48 60 15 87 73
4 2
59 30 22 61
3 2
143 23 94
OUTPUT:
73 48 60 15 87
22 61 59 30
23 94 143
Morae! Q
- Find a triplet such that triplet is minimum of all the triplets.
- Rearrange characters in a string such that no two adjacent are same.
- Return the coordinates of all cells in matrix sorted by their distance.
- Function to verify the ISBN number from the book.
- Find out the absolute difference of values of two array integers.
- Rotate the array in the right direction by K steps.
- Find the sequence of moves that wins the game, collect exactly G coins!.
- Calculate the sum of boundary elements of a matrix.
- Find the total number of ways to reach the tree house.
- Compute profit and loss of a product.
- Find the total expense of purchased items.
- Determine the maximum sequence weight.
- Find the person’s birth year is a leap year or not.
- Find the inner rating with the displayed rating.
- Find if angles are valid to form a triangle.
- Find out the winner of the game from the given statistics.
- Verify the tag to determine if one needs to arrest or allow the vehicle.
- Find the largest hexadecimal number.
- Group up all anagrams together from given words.
- Return all anagrams from the given words.