A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-36.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6s:=[]int{1,2,3,4}
7t:=s[1:2:3]
8t=append(t,8)
9fmt.Println(s,t)
10}
Slices
Answer & explanation
Console output
[1 2 8 4] [2 8]
Why
s[1:2:3] gives len 1 and cap 3-1=2, so there is exactly one spare slot. append(t, 8) fits within capacity and writes 8 into the shared backing array at s[2], no reallocation. t now reads [2 8] and s shows the in-place change at index 2.