We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5e0123c commit 21db95dCopy full SHA for 21db95d
solutions/1409-Queries-on-a-Permutation-With-Key/1409.py
@@ -0,0 +1,23 @@
1
+from typing import List
2
+
3
+class Solution:
4
+ def processQueries(self, queries: List[int], m: int) -> List[int]:
5
+ p = [x for x in range(1, m + 1)]
6
+ res = []
7
8
+ for x in queries:
9
+ temp = p.index(x)
10
+ num = p[temp]
11
+ res.append(temp)
12
+ p.remove(p[temp])
13
+ p.insert(0, num)
14
+ return res
15
16
+if __name__ == "__main__":
17
+ queries = [3,1,2,1]
18
+ m = 5
19
+ queries = [4,1,2,2]
20
+ m = 4
21
+ queries = [7,5,5,8,3]
22
+ m = 8
23
+ print(Solution().processQueries(queries, m))
0 commit comments