Loading...
Loading...
Loading...
A sales log has one line per sale with the product and the quantity sold. The same product appears many times.
Add up the quantity for each product and print the product with the highest total, followed by that total. If two products tie, print the one that comes first alphabetically.
Example
Input
5 mouse 3 cable 10 mouse 4 cable 2 bag 5
Output
cable 12
Cable totals 12, mouse 7, bag 5.
Try the problem first. Open one hint at a time.
Add up the quantity per product in a dictionary.
Check the products in alphabetical order and replace the best one only when a total is strictly larger. A tie then keeps the earlier name.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor