image_2022-04-13_16-34-50.png
40.1 KB
#medium
#N1409. Queries on a Permutation With Key
problem link
#solution
#N1409. Queries on a Permutation With Key
problem link
#solution
class Solution {
public int[] processQueries(int[] queries, int m) {
List<Integer> list = new ArrayList<>();
for(int i=1; i<=m; i++)
list.add(i);
int[] ans = new int[queries.length];
for(int i=0; i<ans.length; i++){
ans[i]=list.indexOf(queries[i]);
list.remove(ans[i]);
list.add(0, queries[i]);
}
return ans;
}
}