1409. Queries on a Permutation With Key
https://leetcode.com/problems/queries-on-a-permutation-with-key
Description
Given the array queries
of positive integers between 1
and m
, you have to process all queries[i]
(from i=0
to i=queries.length-1
) according to the following rules:
In the beginning, you have the permutation
P=[1,2,3,...,m]
.For the current
i
, find the position ofqueries[i]
in the permutationP
(indexing from 0) and then move this at the beginning of the permutationP.
Notice that the position ofqueries[i]
inP
is the result forqueries[i]
.
Return an array containing the result for the given queries
.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= m <= 10^3
1 <= queries.length <= m
1 <= queries[i] <= m
ac
Last updated