Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to rotate an array k times to the right.

Medium

Problem Statement

Write a function to rotate an array k times to the right.

Sample Input

A hardcoded array [1, 2, 3, 4, 5] and k = 2

Sample Output

Rotated array: 4, 5, 1, 2, 3

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun rotateArray(arr: Array<Int>, k: Int): Array<Int> { // Add your code here to rotate the array } fun main() { val array = arrayOf(1, 2, 3, 4, 5) val k = 2 println("Rotated array: ${rotateArray(array, k).joinToString(", ")}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded array [1, 2, 3, 4, 5] and k = 2
Expected Output
Rotated array: 4, 5, 1, 2, 3