Explain how a hash map works internally.
✅ Answer:
A hash map stores key value pairs by applying a hash function to the key to compute an index in an underlying array. Ideally, the hash function distributes keys uniformly to minimize collisions.
When collisions occur, common strategies include chaining using linked lists or open addressing. Lookups, insertions, and deletions are O(1) on average but can degrade toward O(n) in worst case collision scenarios.
In modern implementations like Java’s HashMap, when collision chains grow beyond a threshold, they may be converted into balanced trees to maintain efficient performance.