본문으로 바로가기
import Foundation

func solution(_ array:[Int], _ commands:[[Int]]) -> [Int] {
    
    var arr = array
    var arr2 = [Int]()
    var result = [Int]()
    
    for i in 0..<commands.count {
        for _ in commands[i][0]...commands[i][1] {
            let a = arr.remove(at: commands[i][0] - 1)
            arr2.append(a)
        }
        arr2 = arr2.sorted()
        result.append(arr2[commands[i][2] - 1])
        arr = array
        arr2 = [Int]()
    }

    return result
}