Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map quiz #15

Open
rusinikita opened this issue May 7, 2024 · 2 comments
Open

Map quiz #15

rusinikita opened this issue May 7, 2024 · 2 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@rusinikita
Copy link
Owner

Interviewers asks about maps internal structure:

  1. Components of maps (buckets, hashFunc)
  2. In which order for range iterates over map
  3. In which order map printed

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.

@rusinikita rusinikita added help wanted Extra attention is needed good first issue Good for newcomers labels May 7, 2024
@rusinikita
Copy link
Owner Author

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

@rusinikita
Copy link
Owner Author

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant