I am trying to implement the bottom up version of fibonacci that operates in O(n) time but keep getting list assignment index errors and I have no clue why. This is my code:
def fibbu(n):
fib = [1,1]
for i in range(2, n):
fib[i] = fib[i-2] + fib[i-1]
return fib[n]
But I am getting an indexerror on the line inside of the for loop. I've spent far too long on something so simple, can anyone point out where I'm going wrong?