Rotate Array
he Rotate Array problem involves shifting the elements of an array by k positions.
Given an array arr[] of size n and an integer k, the task is to rotate the array to the right by k steps.
In right rotation:
- the last elements move to the beginning
- remaining elements shift toward the right
This is an important array manipulation problem that helps in understanding array reversal, modular arithmetic, and in-place transformations.
Example 1
Input
arr[] = [1, 2, 3, 4, 5, 6] k = 2
Output
[5, 6, 1, 2, 3, 4]
Explanation
After rotating by 2 positions: 5 and 6 move to the front
Example 2
Input
nums = [-1,-100,3,99] k = 2
Output
[3,99,-1,-100]
Explanation
rotate 1 steps to the right: [99,-1,-100,3]
rotate 2 steps to the right: [3,99,-1,-100]
Constraints
Hints:
Hint 1
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Jul 18, 2026
Last updated
Aug 2, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output