Challenge: Right Rotate the Array by One Index

Given an array, can you rotate its elements once from right to left? Implement your solution in Java and see if your code runs successfully!

Problem Statement #

In this problem, you have to implement the void rotateArray(int[] arr) method, which takes an arr and rotate it right by 1. This means that the right-most elements will appear at the left-most position in the array.

Method Prototype #

void rotateArray(int[] arr)

Output #

Array rotated by one element from right to left

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.