Write a function to rotate an array by k elements to the left.
HardProblem 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)}")
}
Input
A hardcoded array [1, 2, 3, 4, 5] and k = 2.
Expected Output
Rotated array: [3, 4, 5, 1, 2]