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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Data structure with Insert Remove GetRandom
00:00
5 left

Data structure with Insert Remove GetRandom

HardPython

Problem

Design a data structure supporting Insert, Remove, and GetRandom

Asked in the Tech screening (CS Fundamentals) stage. Described as "DSA Insert-Remove-GetRandom".

Implement randomized_set_operations(operations, seed). Each operation is a two-item list such as ["insert", 5], ["remove", 5], or ["getRandom", null]. Return an array containing each insert/remove result as a Boolean and each GetRandom result as an integer. The set starts empty, duplicate inserts and removals of missing values return false. For deterministic grading, initialize Python's random generator with seed before processing operations.

Constraints

  • Values are integers
  • At least one value exists before every getRandom operation
  • 1 <= operations.length <= 10^5
  • Each operation is insert, remove, or getRandom

Function Signature

def randomized_set_operations(operations, seed):
Interviewer

Your question is Data structure with Insert Remove GetRandom. 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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.