Given chat logs, find the top k users with the most frequent chat activity.
Asked in the Virtual Onsite stage. A variant of Top K Frequent Elements (LeetCode 347). Discussed merge sort, max heap, and quick select approaches, including pseudocode, time complexity, and space complexity analysis.
Write a SQL query to return the top k users by message count from a chat log table.
user_id ascending for ties.k users.| Column | Type | Description |
|---|---|---|
| log_idPK | BIGINT | Unique chat log row identifier |
| user_id | BIGINT | User who sent the chat message |
| message_id | BIGINT | Unique message identifier |
| sent_at | TIMESTAMP | Timestamp when the message was sent |