Dynamic Financial Event Prioritization
Intuit's financial analytics platform processes a real-time stream of financial events, such as transactions, alerts, or customer interactions. To ensure timely attention to critical issues, the system needs to continuously monitor and prioritize these events. This problem focuses on maintaining a live view of the most critical events within a rolling time window, reflecting the dynamic nature of financial data.
Your task is to implement a system that processes a sequence of financial events. For each incoming event, you must identify and return the IDs of the K most critical events that are currently active within a specified time window. An event's criticality is determined by a derived score: severity / processingCost. Higher criticality scores indicate more urgent events.
Specifically, for each event in the input list (processed sequentially by their timestamp):
severity / processingCost).timestamp falls outside the current rolling window. The window is defined as [current_event.timestamp - W, current_event.timestamp] (inclusive at both ends).K most critical ones.ids as a list. If there are fewer than K active events, return all of them. The output list for each event must be sorted first by criticality (descending), then by id (ascending) for ties.Input:
events: An array of Event objects. Each Event has the following structure:
id: number (a unique identifier for the event)timestamp: number (the time in seconds when the event occurred; events are guaranteed to be in strictly increasing order of timestamp)severity: number (an integer from 1 to 10, indicating urgency)processingCost: number (a positive integer representing the effort/time to process the event)K: number (the maximum number of most critical events to return)W: number (the width of the rolling time window in seconds)Output:
number[][]: An array of arrays. Each inner array contains the ids of the K most critical events for the corresponding input event, sorted as specified in the task.timestamp.ids are unique across all events.processingCost is guaranteed to be positive, so no division by zero will occur.Examples
Example 1
Input:
events = [{"id":1,"timestamp":1,"severity":5,"processingCost":1},{"id":2,"timestamp":2,"severity":10,"processingCost":2},{"id":3,"timestamp":3,"severity":3,"processingCost":1}], K = 2, W = 1
Output:
[[1],[1,2],[2]]
Note:
Example 2
Input:
events = [{"id":10,"timestamp":10,"severity":8,"processingCost":2},{"id":20,"timestamp":12,"severity":9,"processingCost":3},{"id":30,"timestamp":15,"severity":6,"processingCost":1},{"id":40,"timestamp":16,"severity":10,"processingCost":5}], K = 2, W = 5
Output:
[[10],[10,20],[30,10],[30,20]]
Note:
Example 3
Input:
events = [{"id":1,"timestamp":10,"severity":10,"processingCost":1},{"id":2,"timestamp":11,"severity":5,"processingCost":1},{"id":3,"timestamp":12,"severity":10,"processingCost":2}], K = 3, W = 1
Output:
[[1],[1,2],[2,3]]
Note:
Constraints
1 <= events.length <= 10^5 (denoted as N)1 <= K <= 1001 <= W <= 10^91 <= event.id <= 10^91 <= event.timestamp <= 10^91 <= event.severity <= 101 <= event.processingCost <= 1000events are sorted by timestamp in strictly increasing order.Loading editor...