Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Custom Dictionary Key to Multiple Values
00:00
5 left

Custom Dictionary Key to Multiple Values

HardPython

Problem

How would you implement a custom dictionary where one key maps to multiple generic values, including the operations you would expose and their complexity?

Implement custom_dictionary(operations). Keys must be hashable, values may be any Python object, and values for each key must preserve insertion order. Each operation is a dictionary with op equal to add, get, remove, or contains. Return results for get, remove, and contains in operation order: get returns a list of values, remove returns whether one matching value was removed, and contains returns whether the key exists.

Constraints

  • 1 <= operations.length <= 10^5
  • Each key is hashable
  • Each operation has a valid operation name and required fields
  • Values may be duplicated and may be any Python object supporting equality comparison
  • Values for each key must be returned in insertion order

Function Signature

def custom_dictionary(operations):
Interviewer

Your question is Custom Dictionary Key to Multiple Values. 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
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.