MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / processQueries

Method processQueries

QueriesOnAPermutationWithKey.java:2–23  ·  view source on GitHub ↗
(int[] queries, int m)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int[] processQueries(int[] queries, int m) {
3 List<Integer> result = new ArrayList<>();
4 int ans[] = new int[queries.length];
5 for(int i=1;i<=m;i++)
6 {
7 result.add(i);
8 }
9 for(int i=0;i<queries.length;i++)
10 {
11 for(int j=0;j<=m;j++)
12 {
13 if(result.get(j)==queries[i])
14 {
15 ans[i]=j;
16 result.remove(j);
17 result.add(0,queries[i]);
18 break;
19 }
20 }
21 }
22 return ans;
23 }
24}

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected