Problem Statement
Explain the internal behavior of Go maps, including iteration order, memory management, and concurrent access patterns.
Key Interview Questions
Q1: Is the iteration order of a map deterministic?
Answer: No, iteration order is explicitly randomized by the runtime to prevent developers from relying on it.
Q2: Can you take the address of a map value? e.g., &m["key"]?
Answer: No. Map growth might move values to new buckets, invalidating pointers.
Q3: What keys can be used in a map?
Answer: Any type that is "comparable" (supports ==). Slices, maps, and functions cannot be keys.
Q4: What happens if you read from a nil map?
Q5: What happens if you write to a nil map?
Q6: Does delete(map, key) shrink the memory usage?
Answer: No! Buckets remain allocated. You must recreate the map to reclaim memory.
Q7: How do you implement a "Set" in Go?
Q8: Why use struct{} instead of bool for sets?
Answer: struct{} uses 0 bytes of memory, bool uses 1 byte per entry.