I was asked this in an interview: “Tell me everything you know about hashmaps.”
I proceeded to do just that: it’s a data structure with key-value pairs; a hash function is used to locate the element; how hash collisions can be resolved, etc.
After I was done, they asked: “OK, now explain everything you just said to a 5-year-old. You can’t use technical terms, especially hashing and mapping.”
I have to say it took me by surprise and I didn’t give a good answer. How would you answer?
Lets take the big word book, or dictionary, and try to find the word zebra. We can easily guess that zebras will be near the end of the book, just like the letter “Z” is at the end of the alphabet. Now lets say that we can always find where the zebra is inside of the big word book. This is the way that we can quickly find zebras, or elephants, or any other type of thing we can think of in the big word book. Sometimes two words will be on the same page like apple and ant. We are sure which page we want to look at, but we aren’t sure how close apple and ant are to each other until we get to the page. Sometimes apple and ant can be on the same page and sometimes they might not be, some big word books have bigger words.
That’s how I would have done it.