Katkat

Design a Dictionary for Heterogeneous Key and Value Types

MicrosoftSoftware Engineer · Onsite

Last updated

Design a heterogeneous dictionary with explicit type-aware equality, hashing, collision resolution, variable-length ownership, resizing, and persistence boundaries.

Design a key-value dictionary whose keys and values may have different types and lengths. Explain hashing, equality, collision handling, and storage ownership.

Constraints & Assumptions

The reported prompt asks about arbitrary types and variable-length storage. This is an interface and representation discussion, not a demand that every runtime object automatically be a safe key. State which types are supported and how callers supply hashing or equality for custom types.

Clarifying Questions

Are types known at compile time or erased at runtime? Should integer 1 and string 1 be distinct keys? Can keys mutate after insertion? Is the dictionary in memory or serialized persistently?

Follow-up questions

  • How would resizing work? How do you handle a poor or adversarial hash function? Why is hashing raw object memory unsafe for many types? What changes for persistence across process versions?