Map indices between lists

Write codeEasy10 min

Your task

A quiz app shuffled its question ids. You have the original order in list a and the shuffled order in list b; both lists contain exactly the same distinct integers, just arranged differently. For each position i of a, find where that id landed in b, and return the list r with r[i] equal to the index of a[i] within b. For example, a = [12, 28, 46] and b = [46, 12, 28] give [1, 2, 0]. Avoid searching b repeatedly, one preprocessing pass should make every lookup O(1).

Examples

position_map(a: list[int], b: list[int]) -> list[int]
Example 1
Inputposition_map([12, 28, 46], [46, 12, 28])
Output[1, 2, 0]