Java는 배열을 활용하는 문제에서 참 불편하다. Arrays.copyOfRange()를 활용했다면 for문을 많이 줄일 수 있을 것으로 보인다.
import java.util.*;
class Solution {
public static int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
int count = 0;
for (int[] command : commands) {
int[] temp = new int[command[1] - command[0] + 1];
for (int i = command[0]; i <= command[1]; i++) {
temp[i - command[0]] = array[i-1];
}
Arrays.sort(temp);
answer[count++] = temp[command[2] - 1];
}
return answer;
}
}