-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberOfK.java
More file actions
27 lines (25 loc) · 895 Bytes
/
NumberOfK.java
File metadata and controls
27 lines (25 loc) · 895 Bytes
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
26
27
package dev.solar.level1;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class NumberOfK {
public int[] solution(int[] array, int[][] commands) {
//TODO
int[] answer = new int[commands.length];
for (int i = 0; i < commands.length; i++) {
List<Integer> tempList = new ArrayList<>();
for (int j: commands[i]) {
tempList.add(j);
}
int[] copyArray = Arrays.copyOf(array, array.length);
int[] ints = Arrays.copyOfRange(copyArray, tempList.get(0)-1, tempList.get(1));
Arrays.sort(ints);
// System.out.println(tempList.get(2)-1);
answer[i] = ints[tempList.get(2)-1];
// for (int z = 0; z < ints.length; z++) {
// System.out.println(ints[z]);
// }
}
return answer;
}
}