
import Foundation
func solution(_ array:[Int], _ commands:[[Int]]) -> [Int] {
var answer : [Int] = []
var arr : [Int] = []
for i in 0..<commands.count {
arr = array[(commands[i][0]-1)...(commands[i][1]-1)].sorted()
answer.append(arr[commands[i][2]-1])
}
return answer
}
새로운 배열을 하나 만들어서 commands 배열 조건에 맞는 숫자 범위로 해서 값을 넣었다.
commands안에 있는 번째는 1을 처음부터 하기에, 우리가 사용하는 인덱스의 개념과 달라 -1을 해주었다.