Loading problem…
You're building a carousel or image slider component that needs to rotate items. Given an array, you need to rotate it to the right by k steps.
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative.
// Example 1
let nums = [1,2,3,4,5,6,7];
rotate(nums, 3);
// nums becomes [5,6,7,1,2,3,4]
// Rotated right by 3: [1,2,3,4,5,6,7] → [5,6,7,1,2,3,4]
// Example 2
let nums = [-1,-100,3,99];
rotate(nums, 2);
// nums becomes [3,99,-1,-100]This problem models real frontend scenarios: