Ezvor

3682. Minimum Index Sum of Common Elements

MediumArray Preparing judge… LeetCode
ArrayHash Table

Hints

Hint 1
Build a hash map pos1 that stores, for each value in nums1, the smallest index where it appears.
Hint 2
Iterate through nums2. For each index j, if nums2[j] exists in pos1, compute pos1[nums2[j]] + j.
Hint 3
Track the minimum index sum across all such matches.
Hint 4
If no common element is found, return -1.