All 116 questions

  1. 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?”
  2. 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?”
  3. 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.”
  4. 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?”
  5. 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?”
  6. 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?”
  7. 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?”
  8. 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?”
  9. 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`?”
  10. 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?”
  11. What is a dictionary?

    Asked in 2 of 374 interviews · last asked Oct 18 · Concept · Junior

  12. 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?”
  13. 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?”
  14. Where is a hash code used, and in which data structures?

    Asked once · last asked Jan 28 · Concept · Mid-level

  15. 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?”
  16. 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

  17. 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

  18. 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

  19. 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

  20. What is the difference between a LinkedList and a HashMap?

    Asked once · last asked Apr 8 · Concept · Junior

  21. What happens when a dictionary has duplicate keys?

    Asked once · last asked Apr 9 · Concept · Junior

  22. 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

  23. 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

  24. 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

  25. What other benefits can normalizing a product list provide?

    Asked once · last asked Apr 28 · Concept · Mid-level

  26. 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

  27. 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

  28. How would you calculate an object's hash code?

    Asked once · last asked Jun 9 · Concept · Mid-level

  29. 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

  30. What data structure would let you associate one game action with multiple other values?

    Asked once · last asked Jun 9 · Concept · Mid-level

  31. What is the time complexity of retrieving a value from a dictionary?

    Asked once · last asked Jun 11 · Concept · Mid-level

  32. 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

  33. 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

  34. 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

  35. 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

  36. 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

  37. 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

  38. 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?”
  39. 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

  40. 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

  41. 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

  42. 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

  43. 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

  44. 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

  45. How does a Java HashMap look up an element?

    Asked once · last asked Jul 16 · Concept · Mid-level

  46. What is the SHA-256 function, and why is it considered central to blockchain?

    Asked once · last asked Jul 8 · Concept · Junior

  47. 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

  48. 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

  49. When storing drug aliases in a mapping, what would you use as the key and value?

    Asked once · last asked Jul 24 · Concept · Junior

  50. How would you store multiple aliases for each drug?

    Asked once · last asked Jul 24 · Concept · Mid-level

  51. How would you retrieve all known aliases for paracetamol?

    Asked once · last asked Jul 24 · Write code · Mid-level

  52. How would you use Python to find the best-selling product by total quantity sold?

    Asked once · last asked Aug 3 · Write code · Junior

  53. 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

  54. 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

  55. 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

  56. 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

  57. 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

  58. What is a hash map, and when can you use one to optimize code?

    Asked once · last asked Aug 21 · Concept · Mid-level

  59. What algorithms or data structures can provide constant-time lookup?

    Asked once · last asked Aug 25 · Concept · Mid-level

  60. What is the average time complexity of looking up a key in a Python dict?

    Asked once · last asked Aug 25 · Concept · Junior

  61. 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

  62. What is a hash collision?

    Asked once · last asked Aug 25 · Concept · Mid-level

  63. 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

  64. Find the duplicates in an array using Java.

    Asked once · last asked Sep 6 · Write code · Junior

  65. 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

  66. 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?”
  67. 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

  68. 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

  69. 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

  70. 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

  71. How does a HashSet work internally in Java?

    Asked once · last asked Sep 16 · Concept · Mid-level

  72. What is the difference between HashMap and TreeMap?

    Asked once · last asked Sep 18 · Concept · Mid-level

  73. 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

  74. 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

  75. 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

  76. How would you remove duplicate users from a Dart list while handling null values?

    Asked once · last asked Sep 24 · Write code · Junior

  77. How would you count the number of times each name appears in a Dart list?

    Asked once · last asked Sep 24 · Write code · Junior

  78. What is the difference between List and Set?

    Asked once · last asked Sep 30 · Concept · Junior

  79. What is the difference between HashSet and TreeSet?

    Asked once · last asked Sep 30 · Concept · Junior

  80. How would you find duplicate values in a Python list?

    Asked once · last asked Sep 30 · Write code · Junior

  81. 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

  82. How would you use a hash map on the frontend to prevent duplicate payment requests?

    Asked once · last asked Oct 1 · Scenario · Mid-level

  83. 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

  84. 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

  85. 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

  86. What is the difference between List, Queue, and Set in Java?

    Asked once · last asked Oct 8 · Concept · Junior

  87. 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

  88. 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

  89. 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

  90. What happens internally when you use an object as a key in a HashMap?

    Asked once · last asked Oct 16 · Concept · Mid-level

  91. How would you find duplicate elements in a large collection efficiently?

    Asked once · last asked Oct 16 · Write code · Mid-level

  92. Write Java code to remove duplicate elements from a list.

    Asked once · last asked Oct 16 · Write code · Mid-level

  93. 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?”
  94. What characterizes a good key in a HashMap?

    Asked once · last asked Mar 6 · Concept · Mid-level

  95. What is a dictionary in programming, and how is it used?

    Asked once · last asked Mar 7 · Concept · Junior

  96. What is the Java Collections Framework?

    Asked once · last asked Apr 8 · Concept · Junior

    Other ways it was asked
    • “What is the Collection Framework?”
  97. How do you add a value to a dictionary?

    Asked once · last asked Apr 9 · Write code · Junior

  98. What is the difference between linked lists and maps?

    Asked once · last asked May 1 · Concept · Junior

  99. Which native collection would you use to ensure that all elements are unique?

    Asked once · last asked Jun 9 · Concept · Junior

  100. What is a Python dictionary, and when would you use one?

    Asked once · last asked Jun 11 · Concept · Junior

  101. What function maps a key to a location in a hash table?

    Asked once · last asked Jun 11 · Concept · Junior

  102. 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?”
  103. Which data structure stores key-value pairs?

    Asked once · last asked Jul 26 · Concept · Junior

  104. What types of collections are available in Java?

    Asked once · last asked Jul 27 · Concept · Junior

  105. Can you differentiate between ArrayList and HashMap?

    Asked once · last asked Aug 5 · Concept · Junior

  106. Could you please explain MD5 and hashing?

    Asked once · last asked Aug 10 · Concept · Junior

  107. 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

  108. What is a hash?

    Asked once · last asked Aug 11 · Concept · Junior

  109. Can you explain how the word-count logic works?

    Asked once · last asked Aug 13 · Write code · Junior

  110. 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?”
  111. Write a function that returns the unique elements in a list.

    Asked once · last asked Sep 7 · Write code · Junior

  112. 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

  113. What is the use of LinkedHashMap?

    Asked once · last asked Sep 18 · Concept · Mid-level

  114. What are collisions in a HashMap?

    Asked once · last asked Oct 6 · Concept · Mid-level

  115. 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

  116. 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

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.