def aggregate_store_events(events: list[dict]) -> dict:
Aggregate a list of store events into a per-store health summary.
Each event dict has:
store_id(str)type(str)severity(int, 1 to 5)ts(int, Unix timestamp)
Returns a dict keyed by store_id, each value containing:
event_count(int): total events for that storemax_severity(int): highest severity seenlatest_ts(int): most recent event timestampflagged(bool):Trueif any event has severity >= 4
This problem asks you to aggregate store events into a per-store health summary. The key idea is to scan the input once and maintain a dictionary keyed by <code>store_id</code>. For each store, track the total number of events, the maximum severity, the latest timestamp, and whether any event is flagged by having severity at least 4. This is a classic hash-map aggregation task: initialize a record for each new store, then update counts and running maximums as you iterate. The solution is straightforward, efficient, and runs in linear time with respect to the number of events.