Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

(This question is a variation of the LeetCode question 347. Top K Frequent Elements. If you haven't completed that question yet, it is recommended to solve it first.)

An advertising log contains impression records. Each record in impressions has the format [timestamp, adId], where timestamp is a decimal string representing an integer timestamp and adId identifies the displayed advertisement.

Test Cases
Input
Output
Expected