Question Bank

Hash Table Basics Quiz

Difficulty: Easy

Short prompts on hash table lookup cost, collision handling, and when to reach for a Set vs a Map. Builds the mental model before harder hashing problems.

Question Bank
/

Hash Table Basics Quiz

Hash Table Basics Quiz

Short prompts on hash table lookup cost, collision handling, and when to reach for a Set vs a Map. Builds the mental model before harder hashing problems.

Question Bank
Easy
JavaScript
3 questions
hash-table
data-structures
quiz
fundamentals

483 views

13

Trace this snippet and explain what each line prints. Which of the two structures is right for counting frequencies, and which for membership testing?

Examples

Example 1:

Input: iterate 'banana' building seen (Set) and counts (Map); then print seen.size, counts.get('a'), counts.has('z')
Output: 3, then 3, then false
Explanation: Sets dedupe so seen ends as {b, a, n} (size 3). Map stores per-key totals, so counts.get('a') is 3. 'z' was never inserted, so counts.has('z') is false. Use Set for membership, Map for per-key payload.