- Arrays, Reverse, rotation, subarray

Print array after it is right rotated K times | Set 2

Given an array arr[] of size N and a value K, the task is to print the array rotated by K times to the right.Examples:Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.Input: arr = {1, 3, 5, 7, 9}, K = 2Output: 7 9 1 3 5Input: arr = {1, 2, 3, 4, 5}, K = 4Output: 2 3 4 5 1 Algorithm: The given problem can be solved by reversing subarrays. Below steps can be followed to solve the problem:Reverse all the array elements from 1 to N -1Reverse the array elements from 1 to K – 1Reverse the array elements from K to N -1C++  #include using namespace std;  void RightRotate(int Array[], int N, int K){          reverse(Array, Array + N);          reverse(Array, Array + K);              reverse(Array + K, Array + N);          for (int i = 0; i < N; i++) {          cout