Lesson overview · Free interview practice

Hash Tables

Delve into hash table implementation and its various use cases.

Topics in the full lesson
  • Concept and Use Cases
  • Types of Hash Tables
  • When to Use
  • Time and Space Complexity
  • Hash Table Operations and Methods
  • Iterating Over Elements
  • Practical Tips and Tricks
  • Advanced Topics
  • Common Gotchas
  • Hash Table Algorithms
  • Interview Tips and Tricks
  • Common Mistakes

Practice Problems

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

Completion marks record your own progress, not an automatically checked result. The task type does not determine whether it is optional.

CodingEasy

Ransom Note

Question

Given two strings ransomNote and magazine, return true if ransomNote can be constructed using the letters of magazine, where each letter in magazine may be used at most once.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Design a RandomizedSet class that supports the following operations in average O(1) time: insert(val) (adds val, returns false if it was already present), remove(val) (removes val, returns false if it wasn't present), and getRandom() (returns a uniformly random current element). The trick: combine a Map<number, index> with a number[] — on remove, swap the target with the last element and pop, so the array stays compact.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Design a TimeMap class that supports two operations:

  • set(key, value, timestamp) — stores key -> value at timestamp. All timestamps for a given key are strictly increasing.
  • get(key, timestamp) — returns the value set for key at the largest timestamp_prev <= timestamp, or "" if none exists.

Use a per-key sorted list of (timestamp, value) and binary-search inside get.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Calculate the dot product of two sparse vectors, which are vectors where most elements are zero, by efficiently identifying and multiplying non-zero elements.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Hash Tables material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium