A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-147.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6s:=[]int{1,2,3,4,5}
7t:=s[1:3]
8fmt.Println(len(t),cap(t))
9}
Slices
Answer & explanation
Console output
2 4
Why
For t := s[low:high], len(t) is high-low and cap(t) is cap(s)-low. Here len is 3-1=2, and cap is 5-1=4 because the backing array still extends to s’s last element. Capacity is about how far the window can grow, not how many elements it currently shows.