Skip to content
Sharp

Collections · interview question

How would you explain the expected time complexity of get() and put() operations in a HashMap in an interview?

Multiple choiceHardchapter-4-curatedpremiumcollectionsmap-interface-and-hashmap
Choose one answer
Answer and explanation

Correct answer

B. O(1)

Why

In the average case, HashMap operations like get() and put() have a time complexity of O(1) due to the hash-based indexing. However, in the worst case, due to hash collisions, operations might degrade to O(n).

Test yourself on Collections

A free test with instant, explained results. No account needed.

Start free test
All Collections questions →