I had a quiz in my class and didn't do so well on it. I'm looking to find out if someone can explain to me what I did wrong here - our professor is overwhelmed with office hours as we moved online so I thought I'd post here.
def functionC(L):
for i in range(len(L)):
if L[i] == i:
v = L.pop(i)
L.insert(i, 2*v)
return
I supplied the following answer:
The above function is O(n) because the for-loop grows with the size of L. The pop and insert functions are both constant time.
the word time is crossed out, but there is no other explanation as to why I received 6/10 for the question. What did I get wrong in this and why?
Here is an image of the question and my answer to prove the quiz has already been graded and handed back.