Coding interviews
Reveal answer and reasoning
A practical first design can combine an entry cap, declared-payload cap and one synchronization boundary, choosing rejection before adding eviction. Measure real representative memory separately from the accounting policy. If TTL is required, define whether expired entries are removed on access or by maintenance, and test stale-entry effects on admission explicitly.
Expected dictionary operations are constant-time, with O(u) metadata for u keys and key-text storage in addition to the stated payload budget. A zero-byte entry can still consume metadata, so a payload-byte limit alone does not bound entry count or actual process memory. Calling the counter a memory limit would overstate what it measures. It excludes keys, objects, allocator overhead and concurrency.
A compound update also needs synchronization under shared access. The implementation chooses reject rather than eviction, expiration or persistence; those policies are deliberately left for the design discussion.
A senior rubric should reward stated assumptions, measurable limits, correctness invariants, failure behavior and evidence. It should not reward adding distributed components without a requirement they solve. The sample supports that discussion with an actual rejected update and a successful replacement under a five-byte declared budget. Its limits are equally concrete: metadata can grow through zero-byte keys, payloads are not stored and no concurrency is implemented.
A good answer proposes the smallest additional policy needed to close a named gap and explains the cost of that policy instead of calling a counter a complete memory-management system.
What a strong answer covers
- A practical first design can combine an entry cap, declared-payload cap and one synchronization boundary, choosing rejection before adding eviction.
- Expected dictionary operations are constant-time, with O(u) metadata for u keys and key-text storage in addition to the stated payload budget.
- Calling the counter a memory limit would overstate what it measures.
Common pitfall
Calling the counter a memory limit would overstate what it measures. It excludes keys, objects, allocator overhead and concurrency. A compound update also needs synchronization under shared access. The implementation chooses reject rather than eviction, expiration or persistence; those policies are deliberately left for the design discussion.
Follow-up questions
- Test an oversized replacement of a and verify its previous size remains counted. Add many zero-byte distinct keys and explain why Used stays constant while metadata grows. Hint: a budget is meaningful only relative to the resource actually counted.
- Why can arbitrarily many zero-byte keys defeat a payload-only budget?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.