Concept

HashMap

Average lookup and update are O(1) when hashes spread well. Heavy collisions degrade toward O(n) — interview material covers capacity and load factor in depth.

Where it fits

  1. Core Java
  2. Collections

Packages: Core Java (pkg1core)

Learn

Existing chapters for this concept.

  • Collections

    Core Java

    Average lookup and update are O(1) when hashes spread well. Heavy collisions degrade toward O(n) — interview material covers capacity and load factor in depth.

    Open lesson

See it in code

Existing Java examples.

  • core 29 Hash Map Demo

    Core Java · pkg1core/core29HashMapDemo.java · pkg1core · core29HashMapDemo.java

    - Keys are unique; put with an existing key replaces the value. - Lookup uses hashCode (bucket) then equals (match within the bucket). - Mutating a key after…

    Open example
  • core 19 Collections Demo

    Core Java · pkg1core/core19CollectionsDemo.java · pkg1core · core19CollectionsDemo.java

    - List: ordered, indexed, allows duplicates (ArrayList / LinkedList). - Set: no duplicates (HashSet=unordered, LinkedHashSet=insertion, TreeSet=sorted). -…

    Open example
  • datastructures 6 Hash Table Impl

    Data structures · pkg3datastructures/datastructures6HashTableImpl.java · pkg3datastructures · datastructures6HashTableImpl.java

    Open example

Practice

Existing LeetCode material in JavaForge.

  • Clone Graph

    Blind 75 · Graph · pkg5leetcode/blind75/blind75_LC133CloneGraph.java · pkg5leetcode · blind75_LC133CloneGraph.java

    BFS/DFS with HashMap old->clone node. Time O(V+E), Space O(V)

    Open practice
  • Two Sum

    Blind 75 · Array · pkg5leetcode/blind75/blind75_LC1TwoSum.java · pkg5leetcode · blind75_LC1TwoSum.java

    One-pass hash map stores value->index; check complement each step. Time O(n), Space O(n)

    Open practice
  • Group Anagrams

    Blind 75 · String · pkg5leetcode/blind75/blind75_LC49GroupAnagrams.java · pkg5leetcode · blind75_LC49GroupAnagrams.java

    HashMap keyed by sorted char signature. Time O(n k log k), Space O(nk)

    Open practice
  • LRU Cache

    Interview 150 · pkg5leetcode/interview150/interview150_LC146LRUCache.java · pkg5leetcode · interview150_LC146LRUCache.java

    HashMap + doubly linked list for O(1) get/put eviction. Time O(1) per op, Space O(capacity)

    Open practice
  • Isomorphic Strings

    Interview 150 · pkg5leetcode/interview150/interview150_LC205IsomorphicStrings.java · pkg5leetcode · interview150_LC205IsomorphicStrings.java

    Two hash maps enforce one-to-one char mapping. Time O(n), Space O(1)

    Open practice
  • Contains Duplicate II

    Interview 150 · pkg5leetcode/interview150/interview150_LC219ContainsDuplicateII.java · pkg5leetcode · interview150_LC219ContainsDuplicateII.java

    Hash map stores last index; check distance <= k. Time O(n), Space O(n)

    Open practice
  • Subarray Sum Equals K

    Interview 150 · pkg5leetcode/interview150/interview150_LC560SubarraySumEqualsK.java · pkg5leetcode · interview150_LC560SubarraySumEqualsK.java

    Prefix sum hash map counts subarrays with needed prefix. Time O(n), Space O(n)

    Open practice
  • Two Sum

    Starter · Hashing · pkg5leetcode/leetcode1TwoSum.java · pkg5leetcode · leetcode1TwoSum.java

    Given an array and a target, return indices of the two numbers that add up to target. one-pass hash map. For each x, check if (target - x) was seen. Time…

    Open practice
  • Unique Number of Occurrences

    LeetCode 75 · Hash Map / Set · pkg5leetcode/official75/official75_LC1207UniqueNumberOfOccurrences.java · pkg5leetcode · official75_LC1207UniqueNumberOfOccurrences.java

    Count frequencies; set size equals max frequency count. Time O(n), Space O(n)

    Open practice
  • Determine if Two Strings Have Equal Character Frequency

    LeetCode 75 · Hash Map / Set · pkg5leetcode/official75/official75_LC1657DetermineIfTwoStringsHaveEqualCharacterFrequency.java · pkg5leetcode · official75_LC1657DetermineIfTwoStringsHaveEqualCharacterFrequency.java

    Same length and same sorted char frequency arrays. Time O(n), Space O(1)

    Open practice
  • Max Number of K-Sum Pairs

    LeetCode 75 · Two Pointers · pkg5leetcode/official75/official75_LC1679MaxNumberOfKSumPairs.java · pkg5leetcode · official75_LC1679MaxNumberOfKSumPairs.java

    Hash map counts complements for k-sum pairs. Time O(n), Space O(n)

    Open practice
  • Find the Difference of Two Arrays

    LeetCode 75 · Hash Map / Set · pkg5leetcode/official75/official75_LC2215FindTheDifferenceOfTwoArrays.java · pkg5leetcode · official75_LC2215FindTheDifferenceOfTwoArrays.java

    Sets for unique elements in each direction. Time O(n+m), Space O(n+m)

    Open practice
  • Equal Row and Column Pairs

    LeetCode 75 · Hash Map / Set · pkg5leetcode/official75/official75_LC2352EqualRowAndColumnPairs.java · pkg5leetcode · official75_LC2352EqualRowAndColumnPairs.java

    Hash row signatures; count matching columns. Time O(n^2), Space O(n^2)

    Open practice
  • Path Sum III

    LeetCode 75 · Tree DFS · pkg5leetcode/official75/official75_LC437PathSumIII.java · pkg5leetcode · official75_LC437PathSumIII.java

    Prefix sum on tree paths with hash map. Time O(n), Space O(n)

    Open practice

Prepare

Existing interview questions.