Episode 7 — DSA with JavaScript / 7.11 — Hashing Set and Map
7.11 — Interview Questions: Hashing
Beginner
Q1. Set time O?
Answer: O(1) avg for add/has/delete
Beginner
Q2. Map vs Object?
Answer: Map: any key type, ordered, .size
Beginner
Q3. Two Sum with Map?
Answer: Store complement, check on iteration
Beginner
Q4. Set for duplicates?
Answer: Add to set, check if already present
Beginner
Q5. Hash collision?
Answer: Chaining or open addressing
Intermediate
Q6. Longest consecutive?
Answer: Set + only start sequences (no n-1)
Intermediate
Q7. Group anagrams?
Answer: Sorted string as map key
Intermediate
Q8. Subarray sum K?
Answer: Prefix sum map
Intermediate
Q9. Map iteration?
Answer: for (const [k,v] of map)
Intermediate
Q10. When hash degrades?
Answer: Many collisions → O(n) worst case
Quick-fire table
| # | Question | Answer |
|---|---|---|
| 1 | Set time O? | O(1) avg for add/has/delete |
| 2 | Map vs Object? | Map: any key type, ordered, .size |
| 3 | Two Sum with Map? | Store complement, check on iteration |
| 4 | Set for duplicates? | Add to set, check if already present |
| 5 | Hash collision? | Chaining or open addressing |
| 6 | Longest consecutive? | Set + only start sequences (no n-1) |
| 7 | Group anagrams? | Sorted string as map key |
| 8 | Subarray sum K? | Prefix sum map |
| 9 | Map iteration? | for (const [k,v] of map) |
| 10 | When hash degrades? | Many collisions → O(n) worst case |
Rapid self-check cards
SC-001
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-002
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-003
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-004
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-005
- Q: Hash collision?
- A: Chaining or open addressing
SC-006
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-007
- Q: Group anagrams?
- A: Sorted string as map key
SC-008
- Q: Subarray sum K?
- A: Prefix sum map
SC-009
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-010
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-011
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-012
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-013
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-014
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-015
- Q: Hash collision?
- A: Chaining or open addressing
SC-016
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-017
- Q: Group anagrams?
- A: Sorted string as map key
SC-018
- Q: Subarray sum K?
- A: Prefix sum map
SC-019
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-020
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-021
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-022
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-023
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-024
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-025
- Q: Hash collision?
- A: Chaining or open addressing
SC-026
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-027
- Q: Group anagrams?
- A: Sorted string as map key
SC-028
- Q: Subarray sum K?
- A: Prefix sum map
SC-029
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-030
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-031
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-032
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-033
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-034
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-035
- Q: Hash collision?
- A: Chaining or open addressing
SC-036
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-037
- Q: Group anagrams?
- A: Sorted string as map key
SC-038
- Q: Subarray sum K?
- A: Prefix sum map
SC-039
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-040
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-041
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-042
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-043
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-044
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-045
- Q: Hash collision?
- A: Chaining or open addressing
SC-046
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-047
- Q: Group anagrams?
- A: Sorted string as map key
SC-048
- Q: Subarray sum K?
- A: Prefix sum map
SC-049
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-050
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-051
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-052
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-053
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-054
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-055
- Q: Hash collision?
- A: Chaining or open addressing
SC-056
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-057
- Q: Group anagrams?
- A: Sorted string as map key
SC-058
- Q: Subarray sum K?
- A: Prefix sum map
SC-059
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-060
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-061
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-062
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-063
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-064
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-065
- Q: Hash collision?
- A: Chaining or open addressing
SC-066
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-067
- Q: Group anagrams?
- A: Sorted string as map key
SC-068
- Q: Subarray sum K?
- A: Prefix sum map
SC-069
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-070
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-071
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-072
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-073
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-074
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-075
- Q: Hash collision?
- A: Chaining or open addressing
SC-076
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-077
- Q: Group anagrams?
- A: Sorted string as map key
SC-078
- Q: Subarray sum K?
- A: Prefix sum map
SC-079
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-080
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-081
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-082
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-083
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-084
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-085
- Q: Hash collision?
- A: Chaining or open addressing
SC-086
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-087
- Q: Group anagrams?
- A: Sorted string as map key
SC-088
- Q: Subarray sum K?
- A: Prefix sum map
SC-089
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-090
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-091
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-092
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-093
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-094
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-095
- Q: Hash collision?
- A: Chaining or open addressing
SC-096
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-097
- Q: Group anagrams?
- A: Sorted string as map key
SC-098
- Q: Subarray sum K?
- A: Prefix sum map
SC-099
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-100
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-101
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-102
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-103
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-104
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-105
- Q: Hash collision?
- A: Chaining or open addressing
SC-106
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-107
- Q: Group anagrams?
- A: Sorted string as map key
SC-108
- Q: Subarray sum K?
- A: Prefix sum map
SC-109
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-110
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-111
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-112
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-113
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-114
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-115
- Q: Hash collision?
- A: Chaining or open addressing
SC-116
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-117
- Q: Group anagrams?
- A: Sorted string as map key
SC-118
- Q: Subarray sum K?
- A: Prefix sum map
SC-119
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-120
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-121
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-122
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-123
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-124
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-125
- Q: Hash collision?
- A: Chaining or open addressing
SC-126
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-127
- Q: Group anagrams?
- A: Sorted string as map key
SC-128
- Q: Subarray sum K?
- A: Prefix sum map
SC-129
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-130
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-131
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-132
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-133
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-134
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-135
- Q: Hash collision?
- A: Chaining or open addressing
SC-136
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-137
- Q: Group anagrams?
- A: Sorted string as map key
SC-138
- Q: Subarray sum K?
- A: Prefix sum map
SC-139
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-140
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-141
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-142
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-143
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-144
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-145
- Q: Hash collision?
- A: Chaining or open addressing
SC-146
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-147
- Q: Group anagrams?
- A: Sorted string as map key
SC-148
- Q: Subarray sum K?
- A: Prefix sum map
SC-149
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-150
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-151
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-152
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-153
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-154
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-155
- Q: Hash collision?
- A: Chaining or open addressing
SC-156
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-157
- Q: Group anagrams?
- A: Sorted string as map key
SC-158
- Q: Subarray sum K?
- A: Prefix sum map
SC-159
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-160
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-161
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-162
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-163
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-164
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-165
- Q: Hash collision?
- A: Chaining or open addressing
SC-166
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-167
- Q: Group anagrams?
- A: Sorted string as map key
SC-168
- Q: Subarray sum K?
- A: Prefix sum map
SC-169
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-170
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-171
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-172
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-173
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-174
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-175
- Q: Hash collision?
- A: Chaining or open addressing
SC-176
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-177
- Q: Group anagrams?
- A: Sorted string as map key
SC-178
- Q: Subarray sum K?
- A: Prefix sum map
SC-179
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-180
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-181
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-182
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-183
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-184
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-185
- Q: Hash collision?
- A: Chaining or open addressing
SC-186
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-187
- Q: Group anagrams?
- A: Sorted string as map key
SC-188
- Q: Subarray sum K?
- A: Prefix sum map
SC-189
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-190
- Q: When hash degrades?
- A: Many collisions → O(n) worst case
SC-191
- Q: Set time O?
- A: O(1) avg for add/has/delete
SC-192
- Q: Map vs Object?
- A: Map: any key type, ordered, .size
SC-193
- Q: Two Sum with Map?
- A: Store complement, check on iteration
SC-194
- Q: Set for duplicates?
- A: Add to set, check if already present
SC-195
- Q: Hash collision?
- A: Chaining or open addressing
SC-196
- Q: Longest consecutive?
- A: Set + only start sequences (no n-1)
SC-197
- Q: Group anagrams?
- A: Sorted string as map key
SC-198
- Q: Subarray sum K?
- A: Prefix sum map
SC-199
- Q: Map iteration?
- A: for (const [k,v] of map)
SC-200
- Q: When hash degrades?
- A: Many collisions → O(n) worst case