educative.io

Educative

HashMap design don't need 3 level of list nesting

Hello,

Why is Bucket a List<List> when it can simply be just a List and Entry is just a class with key, and value as members? So the HashMap can simply be List<List> instead of having three level of nesting listing like List<<List<List>>? I believe we only need two level of list nesting. Please clarify.


Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Solution: Design HashMap - Grokking Coding Interview Patterns in Java

Hello @Wing_Tang

Thank you for bringing this up. You’re correct in observing that the code uses a nested structure of a List of Buckets, where each Bucket is a List of Entries. This is the correct and expected way to implement a hash map in this case.

Regarding the question about three level of nesting, It seems that there may have been a misunderstanding. In the code provided, there is only two levels of nesting, which is the List of Buckets, where each Bucket is a List of Entries.

Can you please clarify where you see the third level of nesting, so that I can help address any confusion or misunderstandings?

Happy Learning!

You are completely wrong. If you haven’t run the code yet in the final solution provided by the author, you should. The code creates 11 redundant buckets, each containing an entire hash table.

This is very confusing for a learner, except that almost every solution provided in Educative courses contain an error and then the authors usually refuse to acknowledge it. Not sure how you get away with that. You must be a man.