You are given an integer array nums and an integer k.
Your task is to rotate the array to the right by k steps, where k is non-negative.
A right rotation means that the last k elements of the array move to the front,
and all other elements shift to the right.
You must modify the array in-place, without using extra space for another array.
Input: nums = [10, 20, 30, 40, 50, 60], k = 2
Output: [50, 60, 10, 20, 30, 40]
Explanation:
After 1 rotation → [60, 10, 20, 30, 40, 50] After 2 rotations → [50, 60, 10, 20, 30, 40]
Input: nums = [5, 8, 9, 12, 15], k = 3
Output: [9, 12, 15, 5, 8]
Explanation:
After 1 rotation → [15, 5, 8, 9, 12] After 2 rotations → [12, 15, 5, 8, 9] After 3 rotations → [9, 12, 15, 5, 8]
Accepted:
Submission: