Create a generic Map type that supports integer keys and allows inserting, retrieving, and deleting key-value pairs.
HardProblem Statement
Create a generic Map type that supports integer keys and allows inserting, retrieving, and deleting key-value pairs.
Sample Input
m := NewMap[int, string](); m.Set(1, "Go")
Sample Output
Go
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
package main
import "fmt"
type Map[K comparable, V any] struct {
// Your code here
}
func NewMap[K comparable, V any]() *Map[K, V] {
return &Map[K, V]{}
}
func main() {
m := NewMap[int, string]()
m.Set(1, "Go")
fmt.Println(m.Get(1)) // Expected output: "Go"
}
Input
m := NewMap[int, string](); m.Set(1, "Go")
Expected Output
Go