Given two supply chains, find the common product codes between the two deliveries, preserving the delivery count.
Explanation: Step-by-step: Given two arrays, we first create a hashmap to store the frequency of each element in the first array. Then, we iterate over the second array and for each element, we add it to the output list as many times as its count in the hashmap. In this example, the output is [2,2,1,1] because the frequency of 2 and 1 in the hashmap is 2 and 2 respectively, and the frequency of 2 and 1 in the second array is 2 and 2 respectively.
Explanation: Step-by-step: Given two arrays, we first create a hashmap to store the frequency of each element in the first array. Then, we iterate over the second array and for each element, we add it to the output list as many times as its count in the hashmap. In this example, the output is [1,1,2,2,3,3,4,4,5,5] because the frequency of each element in the hashmap is equal to its frequency in the second array.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak