Ctrl K

Where Did Each Number Go

Easy
A warehouse kept a list of box numbers, original. After the move the boxes were put back in a different order, giving shuffled: the same numbers, rearranged. All numbers are distinct. For every position i of original, report the position in shuffled where that box now stands. Return the array of these positions (0-based).
Example 1
original=[7, 3, 9, 1], shuffled=[1, 9, 7, 3] → [2, 3, 1, 0]

In the copy, 7 sits at position 2, 3 at position 3, 9 at position 1 and 1 at position 0.

Example 2
original=[40, 15], shuffled=[40, 15] → [0, 1]

The order did not change, so every box stayed in place.

Example 3
original=[4], shuffled=[4] → [0]
Constraints
  • 1 ≤ len(original) ≤ 10⁵
  • len(shuffled) == len(original)
  • 0 ≤ original[i], shuffled[i] ≤ 10⁵
  • All numbers in original are distinct, and shuffled is a rearrangement of them
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyRepeat Within Reach EasyThe Lost Ticket Easy
loading Python…
Input
original=[7, 3, 9, 1], shuffled=[1, 9, 7, 3]
Expected
[2, 3, 1, 0]

Run checks the first 3 tests in your browser. Submit checks all 41 tests on the server, hidden ones included.