Trains the technique from
LeetCode 350Intersection of Two Arrays IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two service vans each carry a bin of spare parts. nums1 lists the catalogue number of every part in the first bin and nums2 does the same for the second bin; a bin may hold several copies of the same part.
A dispatcher wants the list of parts the two vans have in common, counted with copies: if one van carries three copies of part 8 and the other carries two, then part 8 belongs in the answer twice, because only two matching pairs can be made.
Return that list. Its entries may be given in any order.
Example 1
The first bin holds three copies of part 8 and the second holds two, so part 8 is reported twice. Part 3 appears twice in the first bin and once in the second, so it is reported once. Part 0 is missing from the second bin.
Example 2
Only two pairs of part 7 can be made, so the answer lists it twice.
Example 3
The bins share no catalogue number, so the answer is empty.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def intersect(nums1: list[int], nums2: list[int]) -> list[int]:public int[] intersect(int[] nums1, int[] nums2)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.