Menu
Coddy logo textTech

Rotate Array

Lesson 1 of 3 in Coddy's Interview Coding Challenges - Pack IX course.

challenge icon

Challenge

Easy

Write a function named rotateArray that, given an integer array and a number k, rotates the array to the right by k steps, where k is non-negative, and returns the rotated array.

Example:

Input: nums = [1,2,3,4,5,6,7], k = 3
Output: [5,6,7,1,2,3,4]
Explanation:

Rotate 1 steps to the right: [7,1,2,3,4,5,6]
Rotate 2 steps to the right: [6,7,1,2,3,4,5]
Rotate 3 steps to the right: [5,6,7,1,2,3,4]

Try it yourself

int* rotateArray(int* nums, int numsSize, int k, int* returnSize) {
    // Write code here
}

All lessons in Interview Coding Challenges - Pack IX