Open rusinikita opened 4 months ago
Consider to add question about map resize on insert.
Is insert to overwhelmed map time consuming?
Behaviour: map is not resized all at once, so it is not time consumed operation than regular insert
Links:
https://go.dev/src/runtime/map.go
Challenge code could be
import (
"fmt"
)
func main() {
var m map[int]bool
// m := make(map[int]bool)
// no panic: false. Zero value if no key. Zero map
fmt.Println(m[0])
for i := 1; i < 5; i++ {
// panic: assignment to entry in nil map
m[i] = i%2 == 0
}
// if panic fixed: prints keys in sorted order
fmt.Println(m)
var toPrint []int
for key := range m {
toPrint = append(toPrint, key)
}
// if panic fixed: prints keys in random order
fmt.Println(toPrint)
}
Interviewers asks about maps internal structure:
Trick of 2 and 3 is iterator starts at random position and stringer sorts elements.
We need to create code sample and questions to check 2 and 3 knowledge.