Your question is Intersection With Duplicates. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Meta IT's mobile diagnostics workflows may compare two lists of event identifiers and need to retain repeated identifiers. Given two integer arrays, return their intersection, preserving duplicates and the order in which values appear in the first array.
A value must appear in the result as many times as it appears in both arrays. The result should include no additional values and may be returned in any order only if the ordering rule is explicitly followed: here, preserve the relative order from nums1.
Implement intersect_arrays(nums1, nums2).
nums1 and nums2.min(count(nums1, value), count(nums2, value)) times, ordered by its occurrences in nums1.def intersect_arrays(nums1, nums2):