Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Custom HashMap Implementation

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

Your question is Custom HashMap Implementation. 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

Canva's design services need predictable key-value behavior for in-memory metadata. Implement a custom HashMap for integer keys without using Python dictionaries, sets, or hash-map utility classes.

Your function receives an ordered list of operations and returns the result of every get and contains operation. Use separate chaining to resolve collisions and resize the bucket array when the load factor exceeds 0.75.

Formal Specification

Implement implement_hash_map(operations), where operations is a list of operation arrays:

  • ['put', key, value]: Insert or replace the value for key.
  • ['get', key]: Return the associated value, or None if absent.
  • ['remove', key]: Delete key if present. This produces no output.
  • ['contains', key]: Return True if key exists, otherwise False.

Return a list containing results from get and contains operations in their original order. Keys and values are integers. The implementation must not use dict, set, or hash().

Constraints

  • 1 <= len(operations) <= 10^5
  • -10^9 <= key <= 10^9
  • -10^9 <= value <= 10^9
  • The initial bucket count is 8.
  • The load-factor threshold is 0.75.
  • Operations are valid and use only the specified operation names.

Function Signature

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