Code Room
CodingEasycod-g1262
Subject HashingLevel Entry–Mid~10 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development

Question

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).

Implement
position_map(a: list[int], b: list[int]) → list[int]
Examples
in[[12,28,46],[46,12,28]]out[1,2,0]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.