프로그래머스
1. Python
def solution(array, commands):
answer = []
for i, j, k in commands:
answer.append(sorted(array[i - 1: j])[k - 1])
return answer
2. C++
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solution(vector<int> array, vector<vector<int>> commands) {
vector<int> answer;
vector<int> temp;
for(int i = 0; i < commands.size(); i++) {
temp = array;
sort(temp.begin() + commands[i][0] - 1, temp.begin() + commands[i][1]);
answer.push_back(temp[commands[i][0] + commands[i][2] - 2]);
}
return answer;
}
3. JavaScript
function solution(array, commands) {
var answer = [];
let temp;
for(let [i, j, k] of commands){
temp = array.slice(i - 1, j);
temp.sort((a, b) => a - b);
answer.push(temp[k - 1]);
}
return answer;
}