← 返回 linkedin 的题目列表Concurrent Event Flow
类型:online_judge
In a system where several events occur, these events can happen concurrently, possibly changing some global states. Design a data structure to capture the event sequence and the changes of global states in real-time. Your data structure should support the following operations:
log_event(event_id: int, timestamp: int): Record an event occurrence.
update_state(state_id: int, state_value: int): Update a global state value.
get_event_order() -> List[int]: Return a list of event IDs recorded in chronological order.
get_state_change(state_id: int) -> List[int]: Return a list of all updated values for that state_id in order of occurrence.
Please implement these functionalities. Assume event_id and state_id are unique integer identifiers.
Input-output Example
Example 1:
log_event(1, 100)
log_event(2, 150)
update_state(1, 10)
update_state(1, 20)
get_event_order()
get_state_change(1)
Output: [1, 2]
[10, 20]
Example
Input
log_event(3, 50)
log_event(4, 200)
update_state(2, 5)
update_state(1, 20)
get_event_order()
get_state_change(1)