Given the scan log, return all over-stocked item IDs, which are items that appear more than twice.
Explanation: Step-by-step: Given the input [1, 2, 3, 4, 4, 4, 4], we first count the occurrences of each item using a frequency map. The frequency map will be {1: 1, 2: 1, 3: 1, 4: 5}. Then, we iterate over the frequency map and add the item ID to the result list if its frequency is greater than 2. In this case, only item 4 appears more than twice, so the output will be [4].
Explanation: Step-by-step: Given the input [1, 1, 1, 1, 1, 2, 2, 2, 2, 2], we first count the occurrences of each item using a frequency map. The frequency map will be {1: 5, 2: 5}. Then, we iterate over the frequency map and add the item ID to the result list if its frequency is greater than 2. In this case, both items 1 and 2 appear more than twice, so the output will be [1, 2].
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak