Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimized Array Transformation

EasyPython00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Formal Specification

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.

Constraints

  • 0 <= len(events) <= 10^5
  • Each event_id is a non-empty string
  • Event dictionaries may contain arbitrary additional JSON-compatible fields
  • The input list and its dictionaries must remain unchanged

Function Signature

def deduplicate_events(events):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output