All 116 questions
How does HashMap work internally in Java?
Asked in 6 of 374 interviews · last asked Oct 16 · Concept · Senior
Show answer
Java's HashMap stores key-value pairs in an array of buckets. It mixes the key's hashCode() and uses that hash to choose a bucket. Within the bucket, it checks hashes and compares keys with equals(). Collisions use linked lists; in Java 8 and later, crowded buckets can become red-black trees.
- The bucket index is (capacity - 1) & mixedHash; capacity is a power of two.
- Tree conversion requires at least 64 buckets; smaller tables resize instead.
- The default load factor is 0.75; exceeding the size threshold normally doubles capacity and redistributes entries.
- get() and put() take O(1) time on average when hashes spread keys well.
What the interviewer checks: The interviewer checks whether you understand bucket selection, key comparison, collisions, and resizing.
Common mistake (in 5 of 6 reviewed answers): Many answers forget that the hash selects a bucket before keys inside that bucket are compared.
Other ways it was asked
- “How does Java's HashMap work?”
- “How does HashMap work in Java?”
- “How does HashMap handle internal operations in modern Java?”
What is a hash map, and how does it store and retrieve values by key?
Asked in 6 of 374 interviews · last asked Sep 18 · Concept · Junior
Show answer
A hash map stores key-value pairs. It uses a hash function to turn each key into an array position. To retrieve a value, it hashes the key again and compares keys to find the matching entry, handling cases where different keys map to the same position.
- Lookup, insertion, and deletion take O(1) time on average with good hashing.
- Collisions are handled by storing multiple entries together or searching other array positions.
- Equal keys must have equal hash values, but different keys may share a hash value.
- Worst-case operations can take O(n) time, depending on the implementation.
What the interviewer checks: The interviewer checks whether you understand hashing, key comparison, collisions, and average lookup speed.
Other ways it was asked
- “What is a HashMap?”
- “What is a HashMap in Java?”
- “How does a hash table use a unique identifier to look up a record?”
How does Java HashMap handle collisions, and how did Java 8 change crowded buckets?
Asked in 4 of 374 interviews · last asked Oct 17 · Concept · Mid-level
Show answer
HashMap stores colliding entries in the same bucket and uses hash values and equals() to find keys. Buckets normally use linked lists. Java 8 added red-black trees for crowded buckets, with a treeification threshold of 8 and a minimum table capacity of 64. Below that capacity, HashMap grows the table instead.
- In OpenJDK's put path, adding a ninth bucket entry can trigger treeification.
- Tree lookup is usually O(log n), but same-hash, non-comparable keys can still require O(n).
- Equal keys replace values; different keys can share a bucket.
What the interviewer checks: The interviewer checks whether you understand collisions, key equality, and when HashMap uses trees instead of lists.
Other ways it was asked
- “How did HashMap improve collision handling after Java 8?”
- “What changed in HashMap collision handling after Java 8?”
- “In Java, explain how HashMap handles collisions internally, and what changes when a bucket gets treeified.”
Remove duplicates from a list while preserving the original order.
Asked in 3 of 374 interviews · last asked Sep 24 · Write code · Junior
Other ways it was asked
- “How would you evaluate logic intended to return unique elements in a vector while preserving their original order?”
- “How would you fix logic that should return unique elements in a vector while preserving their original order?”
- “How would you test that C++ logic returns unique elements in a vector while preserving their original order?”
How do a HashMap and a HashSet differ, and when would you use each?
Asked in 3 of 374 interviews · last asked Sep 22 · Concept · Junior
Other ways it was asked
- “What is the difference between a HashMap and a HashSet?”
- “When would you use a Set instead of a Map?”
- “When can a problem be solved with a Set instead of a Map, and how would you choose between them?”
Find the length of the longest consecutive sequence in an unsorted array in O(n) time.
Asked in 3 of 374 interviews · last asked Sep 18 · Write code · Mid-level
Other ways it was asked
- “Design a function that takes a list of integers and returns the length of the longest consecutive sequence in the list.”
- “Given an array of integers, find the length of the longest consecutive sequence.”
- “Given an unsorted array of integers, return the length of the longest consecutive-element sequence. Aim for O(N) time. How would you approach it, and what edge cases would you consider?”
What is the difference between a List, a Set, and a Map?
Asked in 2 of 374 interviews · last asked Sep 17 · Concept · Junior
Other ways it was asked
- “What is the difference between List, Set, and Map in Apex?”
In a HashMap, what exactly happens during a resize or rehash, how are buckets redistributed, and what determines which bucket an existing entry moves to?
Asked in 2 of 374 interviews · last asked Oct 17 · Concept · Senior
Other ways it was asked
- “In Java, what happens during HashMap resizing and rehashing? How are entries redistributed across the new table without recomputing every hash from scratch?”
In Java, explain the contract between equals and hashCode, and what can go wrong in a HashMap if it's violated.
Asked in 2 of 374 interviews · last asked Oct 17 · Concept · Mid-level
Other ways it was asked
- “What contract exists between `equals` and `hashCode`, and what problem occurs if it is violated in a `HashMap`?”
What do you understand by hashing in Java?
Asked in 2 of 374 interviews · last asked Sep 16 · Concept · Junior
Other ways it was asked
- “What is hashing in Java?”
What is a dictionary?
Asked in 2 of 374 interviews · last asked Oct 18 · Concept · Junior
Group an array of strings into anagram groups using a hash map.
Asked once · last asked Sep 8 · Write code · Junior
Other ways it was asked
- “How would you group anagrams in an array of strings?”
- “How would you group anagrams without sorting each string?”
- “How would you use a hash map to group strings that are anagrams?”
How would you read drug aliases and choose a data structure to store them in?
Asked once · last asked Jul 24 · Write code · Mid-level
Other ways it was asked
- “How would you design a data structure to store drug aliases?”
Where is a hash code used, and in which data structures?
Asked once · last asked Jan 28 · Concept · Mid-level
If two separate instances of a C# class have identical property values and are used as dictionary keys, will the dictionary store one entry or two?
Asked once · last asked Jan 28 · Concept · Mid-level
Other ways it was asked
- “If two separate instances of a C# class have identical property values, will a dictionary store one entry or two?”
If two separate instances of a C# class have identical property values, will a HashSet store one item or two?
Asked once · last asked Jan 28 · Concept · Mid-level
What characterizes a good HashMap key, how does a HashMap work, what is a collision, and what contract must keys follow?
Asked once · last asked Mar 6 · Concept · Mid-level
If you use a tuple as a dictionary key, what must be true of all the items inside the tuple, and why?
Asked once · last asked Mar 16 · Concept · Mid-level
If an object used as a HashMap key changes a field that contributes to its hash code, what happens?
Asked once · last asked Mar 25 · Scenario · Mid-level
What is the difference between a LinkedList and a HashMap?
Asked once · last asked Apr 8 · Concept · Junior
What happens when a dictionary has duplicate keys?
Asked once · last asked Apr 9 · Concept · Junior
Given a list of numbers and a threshold, write code to create a dictionary that maps each number to true if it is greater than the threshold and false otherwise.
Asked once · last asked Apr 15 · Write code · Junior
When normalizing a product list, should you create a new object for each product or reuse the original product object, and why?
Asked once · last asked Apr 28 · Concept · Mid-level
Why might an application transform a product list into a normalized object, and what benefits can that structure provide over the original list?
Asked once · last asked Apr 28 · Concept · Mid-level
What other benefits can normalizing a product list provide?
Asked once · last asked Apr 28 · Concept · Mid-level
Between a flat list of products and the normalized product structure, which is faster for finding a product by ID?
Asked once · last asked Apr 28 · Concept · Mid-level
How would you ensure a set does not contain two distinct objects with the same values representing the same person?
Asked once · last asked Jun 9 · Concept · Mid-level
How would you calculate an object's hash code?
Asked once · last asked Jun 9 · Concept · Mid-level
Can you guarantee that two different objects will never have the same hash code, and how should hash collisions be handled?
Asked once · last asked Jun 9 · Concept · Mid-level
What data structure would let you associate one game action with multiple other values?
Asked once · last asked Jun 9 · Concept · Mid-level
What is the time complexity of retrieving a value from a dictionary?
Asked once · last asked Jun 11 · Concept · Mid-level
How does a hash-map implementation work when you insert a key-value pair into a dictionary?
Asked once · last asked Jun 11 · Concept · Mid-level
Given two lists of integers, how would you find the values they have in common and return them in a new list?
Asked once · last asked Jun 15 · Write code · Mid-level
Why is searching for an item in a set faster than searching for one in a list?
Asked once · last asked Jun 18 · Concept · Junior
Write a Python function that takes a list of transaction dictionaries containing a user ID, account type, category, and amount, and returns totals grouped by a selected key, such as user, account, or category.
Asked once · last asked Jun 24 · Write code · Mid-level
What data structure would provide O(1) average-time lookups and insertions while also allowing efficient sorted iteration of keys?
Asked once · last asked Jul 16 · Concept · Mid-level
In a hash table using open addressing, how does expected lookup time change as the load factor approaches one, and why?
Asked once · last asked Jul 16 · Concept · Mid-level
In an open-addressing hash table, how does expected lookup time behave as the load factor approaches one, and how does this relate to the O(n) worst-case lookup time?
Asked once · last asked Jul 16 · Concept · Mid-level
Other ways it was asked
- “In open addressing, as the load factor approaches one, does expected lookup time approach O(n) in the worst case?”
In open addressing, what condition involving the load factor α and a fixed threshold α_max should trigger a resize or rehash?
Asked once · last asked Jul 16 · Concept · Mid-level
A hash table using open addressing has intermittent lookup failures after deletions. What is the most likely root cause in the deletion implementation?
Asked once · last asked Jul 16 · Scenario · Mid-level
What unit test would reliably catch lookup failures after deletion in an open-addressing hash table? Describe the sequence of inserts, deletes, and lookups.
Asked once · last asked Jul 16 · Scenario · Mid-level
In a linear probing hash table without tombstones, what invariant must deletion preserve so keys later in the probe sequence remain searchable?
Asked once · last asked Jul 16 · Concept · Senior
In backward-shift deletion for linear probing, what condition involving a key's home bucket and wraparound determines whether an entry at position i should move into an earlier empty slot j?
Asked once · last asked Jul 16 · Concept · Senior
What happens when two objects with different keys have the same hash code in a Java HashMap?
Asked once · last asked Jul 16 · Concept · Mid-level
How does a Java HashMap look up an element?
Asked once · last asked Jul 16 · Concept · Mid-level
What is the SHA-256 function, and why is it considered central to blockchain?
Asked once · last asked Jul 8 · Concept · Junior
What happens to a block's final hash if an attacker changes even one kopeck in a transaction?
Asked once · last asked Jul 8 · Scenario · Junior
When documenting a newly designed collection type, what should you explain about its internal workings and behavior?
Asked once · last asked Jul 18 · Concept · Mid-level
When storing drug aliases in a mapping, what would you use as the key and value?
Asked once · last asked Jul 24 · Concept · Junior
How would you store multiple aliases for each drug?
Asked once · last asked Jul 24 · Concept · Mid-level
How would you retrieve all known aliases for paracetamol?
Asked once · last asked Jul 24 · Write code · Mid-level
How would you use Python to find the best-selling product by total quantity sold?
Asked once · last asked Aug 3 · Write code · Junior
How is a HashMap structured, and when would you use a HashMap instead of a List?
Asked once · last asked Aug 5 · Concept · Mid-level
What’s the difference between List<T> and Dictionary<T, TValue>, and when would you choose one over the other?
Asked once · last asked Aug 6 · Concept · Junior
How would you implement functions that build lookup maps for users and locations by ID, and how would you test them?
Asked once · last asked Aug 13 · Write code · Mid-level
In Python, when would you use a dict versus a list for a collection, and why might a dict feel faster for lookups?
Asked once · last asked Aug 16 · Concept · Junior
In Python, how would you remove duplicates from a list while keeping the original order, and when would you accept losing order instead?
Asked once · last asked Aug 16 · Write code · Junior
What is a hash map, and when can you use one to optimize code?
Asked once · last asked Aug 21 · Concept · Mid-level
What algorithms or data structures can provide constant-time lookup?
Asked once · last asked Aug 25 · Concept · Mid-level
What is the average time complexity of looking up a key in a Python dict?
Asked once · last asked Aug 25 · Concept · Junior
How does Python's dict use hashing to store and retrieve entries, and what constraints must keys satisfy?
Asked once · last asked Aug 25 · Concept · Mid-level
What is a hash collision?
Asked once · last asked Aug 25 · Concept · Mid-level
For the longest consecutive-element sequence problem, why can the approach achieve O(N) time in the worst case?
Asked once · last asked Sep 3 · Concept · Mid-level
Find the duplicates in an array using Java.
Asked once · last asked Sep 6 · Write code · Junior
What data structure would you use to store values in a custom replacement for Unity PlayerPrefs?
Asked once · last asked Sep 8 · Design · Mid-level
What is the difference between an array or list and a hash map?
Asked once · last asked Sep 8 · Concept · Junior
Other ways it was asked
- “When would you choose an array or list over a hash map, or vice versa?”
How can you use a hash map and sorting to find the two most frequent elements in an array?
Asked once · last asked Sep 10 · Write code · Junior
In Java, how does HashMap determine which bucket a key goes into, and what roles do hashCode and equals play during put and get?
Asked once · last asked Sep 11 · Concept · Mid-level
In Java HashMap, what triggers treeification of a bucket, and what are the thresholds for treeifying and untreeifying?
Asked once · last asked Sep 11 · Concept · Senior
Design a class that supports inserting an integer, removing an integer, and returning a uniformly random value currently stored. Duplicate values should not be stored.
Asked once · last asked Sep 15 · Write code · Mid-level
How does a HashSet work internally in Java?
Asked once · last asked Sep 16 · Concept · Mid-level
What is the difference between HashMap and TreeMap?
Asked once · last asked Sep 18 · Concept · Mid-level
In C++, in a hash map that uses separate chaining, what exactly is stored in the bucket array and how are the key value pairs laid out in memory?
Asked once · last asked Sep 21 · Concept · Mid-level
In C++, for a hash map that uses open addressing like linear or quadratic probing, where are entries stored and what happens to the probe sequence when an element is erased?
Asked once · last asked Sep 21 · Concept · Mid-level
What are the typical time and space complexities of common HashMap and HashSet operations in Java?
Asked once · last asked Sep 22 · Concept · Mid-level
How would you remove duplicate users from a Dart list while handling null values?
Asked once · last asked Sep 24 · Write code · Junior
How would you count the number of times each name appears in a Dart list?
Asked once · last asked Sep 24 · Write code · Junior
What is the difference between List and Set?
Asked once · last asked Sep 30 · Concept · Junior
What is the difference between HashSet and TreeSet?
Asked once · last asked Sep 30 · Concept · Junior
How would you find duplicate values in a Python list?
Asked once · last asked Sep 30 · Write code · Junior
Given a list of AWS services, how would you count how many times each service appears?
Asked once · last asked Sep 30 · Write code · Junior
How would you use a hash map on the frontend to prevent duplicate payment requests?
Asked once · last asked Oct 1 · Scenario · Mid-level
In an unordered_map, what exactly invalidates iterators, and does a rehash invalidate references and pointers to elements as well?
Asked once · last asked Oct 4 · Concept · Senior
Group the orders by customer ID and return the total amount and number of orders for each customer.
Asked once · last asked Oct 7 · Write code · Mid-level
Can you solve this coding task: remove duplicate IDs from a list of dictionaries, keeping only the entry with the highest score?
Asked once · last asked Oct 7 · Write code · Mid-level
What is the difference between List, Queue, and Set in Java?
Asked once · last asked Oct 8 · Concept · Junior
Please write code for converting a list of names into a map grouped by first letter, case-insensitive, with keys in alphabetical order.
Asked once · last asked Oct 9 · Write code · Mid-level
What core test cases and properties would you use to validate a function that preserves item order while removing duplicates?
Asked once · last asked Oct 14 · Scenario · Junior
How would you test deduplication that preserves order when items can be objects and equality may be by reference or by value?
Asked once · last asked Oct 14 · Scenario · Mid-level
What happens internally when you use an object as a key in a HashMap?
Asked once · last asked Oct 16 · Concept · Mid-level
How would you find duplicate elements in a large collection efficiently?
Asked once · last asked Oct 16 · Write code · Mid-level
Write Java code to remove duplicate elements from a list.
Asked once · last asked Oct 16 · Write code · Mid-level
Which collection would you use when you need elements to remain ordered?
Asked once · last asked Jun 9 · Concept · Junior
Other ways it was asked
- “Which collection would you use when you need elements to be both ordered and unique?”
What characterizes a good key in a HashMap?
Asked once · last asked Mar 6 · Concept · Mid-level
What is a dictionary in programming, and how is it used?
Asked once · last asked Mar 7 · Concept · Junior
What is the Java Collections Framework?
Asked once · last asked Apr 8 · Concept · Junior
Other ways it was asked
- “What is the Collection Framework?”
How do you add a value to a dictionary?
Asked once · last asked Apr 9 · Write code · Junior
What is the difference between linked lists and maps?
Asked once · last asked May 1 · Concept · Junior
Which native collection would you use to ensure that all elements are unique?
Asked once · last asked Jun 9 · Concept · Junior
What is a Python dictionary, and when would you use one?
Asked once · last asked Jun 11 · Concept · Junior
What function maps a key to a location in a hash table?
Asked once · last asked Jun 11 · Concept · Junior
Why group drug aliases together by medication?
Asked once · last asked Jul 24 · Concept · Mid-level
Other ways it was asked
- “Why group drug aliases by medication instead of building the data structure directly from the CSV?”
Which data structure stores key-value pairs?
Asked once · last asked Jul 26 · Concept · Junior
What types of collections are available in Java?
Asked once · last asked Jul 27 · Concept · Junior
Can you differentiate between ArrayList and HashMap?
Asked once · last asked Aug 5 · Concept · Junior
Could you please explain MD5 and hashing?
Asked once · last asked Aug 10 · Concept · Junior
Given an integer array whose elements may contain multiple digits, can you return true if any digit is repeated and false otherwise?
Asked once · last asked Aug 10 · Write code · Junior
What is a hash?
Asked once · last asked Aug 11 · Concept · Junior
Can you explain how the word-count logic works?
Asked once · last asked Aug 13 · Write code · Junior
What are the drawbacks of using lookup maps to retrieve users and locations by ID?
Asked once · last asked Aug 13 · Concept · Mid-level
Other ways it was asked
- “Why create separate lookup maps for users and locations by ID, and what are their advantages over other approaches?”
Write a function that returns the unique elements in a list.
Asked once · last asked Sep 7 · Write code · Junior
If you don't use a one-line solution, how would you remove duplicates from a list in Python?
Asked once · last asked Sep 18 · Write code · Junior
What is the use of LinkedHashMap?
Asked once · last asked Sep 18 · Concept · Mid-level
What are collisions in a HashMap?
Asked once · last asked Oct 6 · Concept · Mid-level
What is your favorite Java collection, and why might you prefer it over a dynamic array?
Asked once · last asked Oct 13 · Concept · Mid-level
How would you write a program to count the occurrences of each word in a sentence?
Asked once · last asked Oct 15 · Write code · Junior
Other ways it was asked
- “How would you count the occurrences of each word in a sentence without using a collections library?”
More Data Structures and Algorithms interview questions
- All Data Structures and Algorithms interview questions
- DSA Basics and Time Complexity Interview Questions
- Array and String Interview Questions
- Linked List, Stack and Queue Interview Questions
- Searching and Sorting Interview Questions
- Tree, Graph and Heap Interview Questions
- Recursion, Dynamic Programming and Greedy Interview Questions
- Algorithm Design and Optimization Interview Questions
- Compiler, Math and Logic Puzzle Interview Questions
How this list is made
Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.
Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.
The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every Data Structures and Algorithms interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.
374 interviews, 269 candidates, Sep 2025 to Oct 2026. Updated every month with new interviews.
Or add the Chrome extension