Algorithm · Google · Easy
A messaging platform has already recorded a batch of user interactions. Design the method below, which reports the most active users. The method must give back the k users whose interaction totals are the largest, each paired with its total, sorted from the largest total down to the smallest. When several users share the same total, they may appear in any relative order. Per-user activity is kept in a hash map count[user], and the map currently holds U users. Discuss the…