In this tutorial, I have explained the java code to rotate an array by k steps to the right.
Given an array, rotate the array to the right by k steps, where k is non-negative.
Website - https://webrewrite.com/
Example 1:
Input: [1, 2, 3, 8, 9, 10] and k = 3
Output: [8, 9, 10, 1, 2, 3]
Explanation:
rotate 1 steps to the right: [10, 1, 2, 3, 8, 9]
rotate 2 steps to the right: [9, 10, 1, 2, 3, 8]
rotate 3 steps to the right: [8, 9, 10, 1, 2, 3]