need help defining Constant memory requirement

Heiko Wundram heikowu at ceosg.de
Mon Sep 20 04:20:33 EDT 2004


Am Sonntag, 19. September 2004 23:28 schrieb Jani Yusef:
> Got it!! Thanks for your help.
> Here is my revised and working code
>             i=[1,2,3,4,5,6,3]
>             s0=len(i)*(len(i)+1)/2
>             s1=0
>             for a in i:
>                 sum1+=a
>             return (sum1-sum0)%len(i)
> I think my main malfunction was with thinking that this was mor
> ecomplex tna it was. By refocusing on the simple problem statement as
> suggested the solution came easier. Thanks again.

Well, actually, as Tim Peters already said, the function really isn't O(1) in 
space requirement, because len(i) and sum(i) grow with O(log(n))... But okay, 
probably your instructor just overlooked this...

Heiko.




More information about the Python-list mailing list