HI, can someone please help figuring out what I am doing wrong here

- https://play.golang.org/p/wmvsBoR4SvL
 
Confusion is in this part of the answer - 
Result is [[] [0] [3] [0 3] [5]]
I is 1 size is 4 subset is [0]
subset is [0 5] added n 5
Len and cap for result is 5 8
Len and cap for result after append is 6 8
Result is [[] [0] [3] [0 5] [5] [0 5]]
I am not able to figure out why does index 4 in Result get overwritten

I am doing an append on result.
You already invited:

Cyrus

Upvotes from:

when you range over nums, the value n gets reused. That's almost certainly your problem.
I saw `for _, n := range nums{` and then `subset = append(subset, n)`

n is a slice...and when it gets reused and you modify it...

If you wanna answer this question please Login or Register