← 返回 snapchat 的题目列表Sort Chat Messages
类型:online_judge
Given a list of chat messages, sort the messages in order from most recent to earliest. Implement server-side code to sort the records. Once sorted, consider how to implement pagination on the client side. Specific requirements:
Input is a list of chat messages, each containing a unique message ID, content, and timestamp.
Output the sorted chat messages.
Implement a pagination mechanism assuming a maximum of 10 records per page.
Provide a time complexity analysis and the implementation of pagination.
Example Input:
[
{"id": 1, "content": "Hello", "timestamp": "2023-10-05T14:48:00.000Z"},
{"id": 2, "content": "Hi", "timestamp": "2023-10-04T09:12:00.000Z"},
{"id": 3, "content": "Greetings", "timestamp": "2023-10-06T07:15:00.000Z"}
]
Example Output: The sorted records with pagination applied
Example
Input
[{"id": 1, "content": "Hello", "timestamp": "2023-10-05T14:48:00.000Z"}, {"id": 2, "content": "Hi", "timestamp": "2023-10-04T09:12:00.000Z"}, {"id": 3, "content": "Greetings", "timestamp": "2023-10-06T07:15:00.000Z"}]