-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.java
25 lines (22 loc) Β· 816 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Sort.prg42748;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Solution sol = new Solution();
System.out.println(Arrays.toString(sol.solution(new int[]{1, 5, 2, 6, 3, 7, 4},
new int[][]{{2, 5, 3}, {4, 4, 1}, {1, 7, 3}})));
}
}
class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = new int[commands.length];
for (int c = 0; c < commands.length; c++) {
int i = commands[c][0] - 1, j = commands[c][1] - 1;
int[] tempArr = new int[j-i+1];
System.arraycopy(array, i, tempArr, 0, j-i+1);
Arrays.sort(tempArr);
answer[c] = tempArr[commands[c][2] - 1];
}
return answer;
}
}