05AB1E, 32 31 bytes
XˆXˆG[N¯2(è<›¯¤NÊsN¢¯Nè‹&&#]N.ˆ
ExplanationExplanation
XˆXˆ # initialize global list as [1,1]
G # input-1 times do:
[ #] # loop until expression is true
N¯2(è<› # n > list[-2]-1
¯¤NÊ # list[-1] != N
sN¢¯Nè‹ # count(list, N) < list[N]
&& # logical AND of the 3 expressions
N.ˆ # add N to global list
and output last value in list and end of program
We are technically in loop G
when we add N to come after further golfingglobal list, but all loops in 05AB1E use the same variable N as index, so the inner loop [...]
has overwritten the N of G
meaning we can add it outside the loop.
Issues with nested loops and conditionals prevents us from doing this inside the loop.