Loading...
Loading...
Loading...
A shop records the product id of every sale. Print the id sold most often and how many times, as id count. If two ids tie, print the smaller id. Calling count for every sale is too slow.
Example 1
Input
6 7 3 7 3 9 7
Output
7 3
Example 2
Input
4 5 2 5 2
Output
2 2
Try the problem first. Open one hint at a time.
items.count(x) scans everything, and doing it for every sale is O(n²).
Count all ids in one pass with a Counter, then pick the largest count, smaller id on a tie.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor