It’s possible to exploit the fact that inputs to hasDuplicates function are always of a known fixed size, and avoid extra allocation like this:
const width = 14 func hasDuplicates(bb []byte) bool { if len(bb) != width { panic(fmt.Errorf("want []byte of len %d, got %d", width, len(bb))) } var x uint64 for _, b := range bb { x |= (1 << (b - 'a' - 1)) } return bits.OnesCount64(x) == width }
Same result, but we use a single uint64 as a bitmap.
It’s possible to exploit the fact that inputs to hasDuplicates function are always of a known fixed size, and avoid extra allocation like this:
Same result, but we use a single uint64 as a bitmap.