Foundation·Concept·2 min read

Hashing and maps

Practice this question

Overview

A hash map stores data by key-value pairs. It gives near-constant time access on average.

Problems to practice

  • First non-repeating character
  • Valid anagram
  • Top K frequent elements
  • Group anagrams
  • Two-sum using map
  • Subarray sum equals k
  • Longest substring with K distinct characters

Key idea

Use a map when you need fast lookup, counts, or grouping.

Time and space complexity

  • Put: O(1) average
  • Get: O(1) average
  • Delete: O(1) average
  • Space: O(n)

Adapted from 14_DSA_MASTER.md · “4. Hashing and maps”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.