Design a Dictionary for Heterogeneous Key and Value Types

Read the full interview experience this question came from →

Quick Overview

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

Design a Dictionary for Heterogeneous Key and Value Types

Company: Microsoft

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Onsite

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? ### What a Strong Answer Covers A consistent equality/hash contract, typed representation, collision resolution, lifetime management, and realistic complexity including variable-length keys. ### 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?

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

Read the full Microsoft Software Engineer interview experience this question came from

|Home/Software Engineering Fundamentals/Microsoft
Microsoft logo
Microsoft
Aug 30, 2026
mediumSoftware EngineerOnsiteSoftware Engineering Fundamentals
0
0

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 Guidance

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?

What a Strong Answer Covers Guidance

A consistent equality/hash contract, typed representation, collision resolution, lifetime management, and realistic complexity including variable-length keys.

Follow-up Questions Guidance

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?

Loading comments...