Your question is Optimized Array Transformation. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The Okta Admin Console receives refreshed activity records that may contain multiple entries with the same event_id. Implement a function that returns one record per event ID, keeping the last occurrence from the input and preserving the order in which those retained records last appeared.
Do not mutate the input list or any event objects.
Implement deduplicate_events(events). The input is a list of dictionaries, where every dictionary contains a non-empty string event_id and may contain additional fields such as actor, action, or timestamp. Return a new list of dictionaries containing the final occurrence of each unique event_id.
If an event ID appears multiple times, only its last dictionary is returned. The output order is determined by the positions of those last occurrences in events.
def deduplicate_events(events):