← 返回 reddit 的题目列表Merge and Sort Chat Messages
类型:online_judge
You need to implement a method merge_messages(ids: List[int]) -> List[Message], where ids is a list of integers representing chat message IDs. For each ID, you can use get_chat_messages(id: int) -> List[Message] to retrieve the message along with the 5 preceding and following messages. Your task is to:
Retrieve all related messages from the given IDs.
Merge these messages into a unique set of messages.
Remove any duplicate messages.
Sort the deduplicated messages in the order of their IDs and return them.
Input
ids: A list of integers representing message IDs.
Output
Return a list of messages sorted by message ID.
Note
Do not simply use Set for deduplication; consider alternative methods.
Follow-up
How to handle message modification and multiple versions if messages support editing and saving different versions?
Example
Input
[10, 15, 20]