1
class Solution {
2
public int[] processQueries(int[] queries, int m) {
3
int[] results = new int[queries.length];
4
ArrayList<Integer> permutations = new ArrayList<Integer>();
5

6
// Filling the permuations array with numbers.
7
for (int i = 0; i < m; i++) permutations.add(i + 1);
8

9
// Looping on the queries & checking their index in the permuations
10
for (int i = 0; i < queries.length; i++) {
11
int query = queries[i];
12
for (int j = 0; j < permutations.size(); j++)
13
if (permutations.get(j) == query) {
14
results[i] = j;
15
int temp = permutations.get(j);
16
permutations.remove(j);
17
permutations.add(0, temp);
18
break;
19
}
20
}
21

22
return results;
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0