Tap here to switch tabs
Problem
Submissions

Problem: Queries on a Permutation With Key

med
30 min
Try to solve the Queries on a Permutation With Key problem.

Statement

Given an array of positive integers queries and an integer m, consider a permutation P containing all integers from 11 to m initialized in increasing order.

For each query queries[i]:

  • Find the 00 indexed position of queries[i] in the permutation P.

  • Move queries[i] to the start of the permutation P.

Return an array containing the resulting positions for all processed queries.

Constraints:

  • 1≤1 \leq m ≤103\leq 10^3

  • 1≤1 \leq queries.length ≤\leq m

  • 1≤1 \leq queries[i] ≤\leq m

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Queries on a Permutation With Key

med
30 min
Try to solve the Queries on a Permutation With Key problem.

Statement

Given an array of positive integers queries and an integer m, consider a permutation P containing all integers from 11 to m initialized in increasing order.

For each query queries[i]:

  • Find the 00 indexed position of queries[i] in the permutation P.

  • Move queries[i] to the start of the permutation P.

Return an array containing the resulting positions for all processed queries.

Constraints:

  • 1≤1 \leq m ≤103\leq 10^3

  • 1≤1 \leq queries.length ≤\leq m

  • 1≤1 \leq queries[i] ≤\leq m