#430 HashMap Complexity with Identical hashCode Values

Companies:
Sberbank
Themes:
JavaCollections & GenericsCode Review

What is the complexity of the operations?

public class HashmapTimeComplexity {

public static void main(String[] args) {
    Map<KeyMap, String> msg = new HashMap<>();
    KeyMap key = new KeyMap(200, "foo");


    // 1...N different elements are added to the map
    // what is the complexity of adding the key below
    map.put(key, "123");
    map.remove(key);
    map.get(key);

    }
}
record KeyMap(int first, String second) {

    @Override
    public int hashCode() {
        return 42;
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in