Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Optimized Array Transformation
00:00
5 left

Optimized Array Transformation

EasyPython

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):
Interviewer

Your question is Optimized Array Transformation. Start with the requirements in the Question tab.

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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.