How does a Python dict work, and when would you choose C++ instead?

MediumConcept12 minSWEREPro outline

The question

Explain how a Python dictionary stores keys and finds them. What makes a key usable, and why do lookups stay fast as it grows?

Then compare Python and C++ for writing a performance-critical part of an ML system.

What the interviewer is looking for

  • Hashing plus open addressing with a compact layout that keeps insertion order
  • Keys must be hashable and their hash must not change, so lists are not allowed
  • Load factor and resizing keep average lookups O(1)
  • Honest trade-offs: Python for speed of iteration and libraries, C++ for control over memory and latency
  • Mentions that most heavy ML compute already runs in native kernels called from Python

Your answer

Saved in this browser only. Nobody else sees it.

Why this question

Written by BlogLLM in the style of a publicly reported Google DeepMind question type: language internals, such as how a Python dictionary works or Python versus C++ trade-offs.

Reported in: leetml.org

Practice question written by BlogLLM based on publicly reported interview formats. Not an official Google DeepMind question.