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

Programming Exercises

Write a function to rotate an array by k elements to the left.

Hard

Problem Statement

Write a function to rotate an array by k elements to the left.

Sample Input

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

Sample Output

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

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun rotateArrayLeft(nums: Array<Int>, k: Int): List<Int> { // Add your code here to rotate the array } fun main() { val nums = arrayOf(1, 2, 3, 4, 5) val k = 2 println("Rotated array: ${rotateArrayLeft(nums, k)}") }
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: [3, 4, 5, 1, 2]