Rotate Array Problem
Rotate Array Problem — ExecCode Medium DSA Practice
Solve the Rotate Array problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Do it in-place by moving each value directly to its final index.
Examples
Input nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60], k = 15; Output [50, 55, 60, 5, 10, 15, 20, 25, 30, 35, 40, 45]. Input nums = [-1, -100, 3, 99], k = 2; Output [3, 99, -1, -100]
Constraints
1 ≤ nums.length ≤ 10⁵ -2³¹ ≤ nums[i] ≤ 2³¹ - 1 0 ≤ k ≤ 10⁵
Practice Rotate Array free on ExecCode. Browse DSA problems, topic map, and placement guides.