s
with [1, 2, 2]
.i
to 2, which points to the current number in s
that dictates the count of the next number to be appended.n
.s
the next number, which is 3 - s[-1]
(flipping between '1' and '2').s[i]
.i
by 1 after each append operation.n
elements of s
.