var x = readLine()!.characters.split { $0 == " " }.map { Int(String($0))! }
var y = readLine()!.characters.split { $0 == " " }.map { Int(String($0))! }
var n = x[0]
var k = x[1]
var q = x[2]
for _ in 0..<k {
y.insert(y[n-1], at: y.startIndex)
y.removeLast() }
for _ in 0..<q {
var i = Int(readLine()!)!
print(y[i]) }
currently stuck on hackerrank where it gives you three Ints (n, k, q) as a string and then another line of n Ints as a string. It wants you to rotate the array right (remove the last index and put it at the start) k number of times and then it provides q number of queries about what element is at the index queried.
the above code works (the compiler must be Swift 2.0 because I can't use .components and have to use .split.) However, it times out on the larger ones, say 100000 100000 500 (array of 100000 Ints, rotate 100000 times and then query 500 times the different index and elements). I know in release build this would be fine but anyone know of a way to optimise this code in Swift to prevent time out in hackerrank a Swift compiler?
Thank you