valueToIndexMap
to store the mapping from number to index for nums2
.nums2
and populate valueToIndexMap
with the number as the key and its index as the value. If a number appears multiple times, update the value with the latest index.result
to store the final mappings.nums1
and for each number, look up its index in valueToIndexMap
and add it to result
.result
array.