For each category, find the top 3 users with the highest total purchase amount.
Input format:
user_id, category_id, date, amount
u1, retail, 20210101, 100
u1, retail, 20210201, 200
u1, c, 20210102, 5000
u2, retail, 20210501, 200
...
Return the users with the highest total purchase amount for each category.
This is a classic group-by and Top K problem. First aggregate total purchase amount by <code>category_id</code> and <code>user_id</code>, then rank users within each category by their summed amount and return the top 3. A hash map is typically used for aggregation, followed by sorting or a heap to extract the Top K results. The key detail is to combine multiple records for the same user within the same category before ranking.