Challenge 8: Right Rotate an Array by One
With the given array, rotate its elements by one index from right to left.
We'll cover the following
Problem statement
Implement a function rightRotate(int arr[], int size)
, which takes an array arr and rotates it right by 1
. This means that the rightmost element will appear at the leftmost position in the array.
Input
An array of integers and its size is given.
Output
The given array rotated by 1 is the output.
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 80+ hands-on prep courses.