For n = 100,000 , on an ok laptop, it runs in roughly 45 seconds
importtimen=100000print"n = %d"%ndefinsert(l,val):index=len(l)-1done=Falsewhilenotdoneandindex>=0:ifl[index]==val:done=Trueelifl[index]<val:l.insert(index+1,val)done=Trueelse:index-=1ifnotdone:l.insert(0,val)list=[1]index=0start=time.time()whileindex<n:x=list[0]y=(2*x)+1z=(3*x)+1insert(list,y)insert(list,z)# Remove unnecessary entries from the list, which otherwise
# grows to unreasonable size for large values of n.
list.remove(x)while(index+len(list))>n:list.pop()index+=1end=time.time()print"result = %d"%list[0]print"elapsed time (seconds) = %3.6f"%(end-start)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
For n = 100,000 , on an ok laptop, it runs in roughly 45 seconds