A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-153.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6s:=[]int{}
7fori:=0;i<3;i++{
8s=append(s,i)
9}
10fmt.Println(len(s),cap(s))
11}
Slices
Answer & explanation
Console output
3 4
Why
Starting from an empty slice (cap 0), each overflowing append doubles capacity: 0 to 1 to 2 to 4. After three appends len is 3, and capacity has reached 4. The capacity climbs in powers of two for small slices, so it overshoots the length.