Challenge: Right Rotate an Array by 1

Given an array, can you rotate its elements by one index from right to left? Implement your solution in C++ and see if your code runs successfully.

Problem Statement

Implement a function rightRotate(int arr[], int size) which takes an array arr and rotate it right by 1. This means that the right-most elements will appear at the left-most position in the array.


An array of integers and its size.


The given array rotated by 1.

Sample Input

arr = [1,2,3,4,5]

Sample Output

arr = [5,1,2,3,4]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.