Implement hashing in a 2D array
Filed under Expedia
Free read 3 of 3Determine how collisions are handled (e.g., linear probing or chaining) and maximum table size.
The question
Implement a basic hash map data structure using a 2-column 2D array to handle key-value pairs, including insert, search, and delete operations.
Constraints
- Keys are unique integers or strings.
- Fixed capacity for the 2D array.
Examples
- Input
- insert(1, "apple"), search(1)
- Output
- "apple"
- Why
- Key 1 is mapped to value "apple" in the 2D array.
Approach
Determine how collisions are handled (e.g., linear probing or chaining) and maximum table size.
Use a 2D array of size N x 2, where column 0 stores keys and column 1 stores values.
Implement insert by scanning for empty slots, search by linear search of keys, and delete by clearing the slot or marking it tombstone.
Handle duplicate key insertions (updates) and full capacity limits.
Tips
- What they are testing: Test collision handling, searching for non-existent keys, and inserting into a full structure.
- Common mistake: Failing to handle array overflow when capacity is reached.
Related Expedia questions
Collected from public candidate posts and coding forums. Updated Nov 2026.