Find Anagram Mappings - Problem
You are given two integer arrays nums1 and nums2 where nums2 is an anagram of nums1. Both arrays may contain duplicates.
Return an index mapping array mapping from nums1 to nums2 where mapping[i] = j means the ith element in nums1 appears in nums2 at index j.
If there are multiple answers, return any of them. An array a is an anagram of an array b means b is made by randomizing the order of the elements in a.
Input & Output
Example 1 — Basic Mapping
$
Input:
nums1 = [12,28,46,32,50], nums2 = [50,12,32,46,28]
›
Output:
[1,4,3,2,0]
💡 Note:
12 maps to index 1, 28 maps to index 4, 46 maps to index 3, 32 maps to index 2, 50 maps to index 0
Example 2 — With Duplicates
$
Input:
nums1 = [84,46], nums2 = [84,46]
›
Output:
[0,1]
💡 Note:
nums1[0]=84 maps to nums2[0]=84, nums1[1]=46 maps to nums2[1]=46
Example 3 — Multiple Same Values
$
Input:
nums1 = [40,40,40], nums2 = [40,40,40]
›
Output:
[0,1,2]
💡 Note:
First 40 maps to index 0, second 40 maps to index 1, third 40 maps to index 2
Constraints
- 1 ≤ nums1.length ≤ 100
- nums2.length == nums1.length
- -105 ≤ nums1[i], nums2[i] ≤ 105
- nums2 is an anagram of nums1
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code