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
Data Structure for Efficient Retrieval
00:00
5 left

Data Structure for Efficient Retrieval

HardPython

Problem

Given a set of requirements, design a data structure that allows for efficient retrieval and updates.

Implement process_operations(operations). Each operation is a list: ['set', key, value], ['get', key], ['delete', key], or ['kth', rank]. Maintain unique integer keys and support updates to existing keys. Return an output for every operation except set: get returns its value or None, delete returns None, and kth returns the key with the zero-based rank or None when the rank is invalid. All operations should be efficient; do not sort all keys for each kth request.

Constraints: at most 500 operations, integer keys and values, and ranks may be negative or out of range.

Constraints

  • 1 <= len(operations) <= 500
  • Each operation is a valid list with one of the specified operation names
  • Keys and values are integers
  • Ranks are integers and may be negative or greater than the number of stored keys
  • The number of distinct keys is at most 500

Function Signature

def process_operations(operations):
Interviewer

Your question is Data Structure for Efficient Retrieval. 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.