Python Forum
fibonacci ***Time limit exceeded***
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fibonacci ***Time limit exceeded***
#2
You are making the same calculations over and over again. Say you try fib(5). That's fib(4) + fib(3). But those are fib(3) + fib(2) + fib(2) + fib(1). So far you've called fib(3) and fib(2) twice each. It would be faster to just generate the numbers until you have n of them. Now, if you have to pass multiple tests, I would save the numbers you calculate for the first test, so you don't have to calculate them again.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
fibonacci ***Time limit exceeded*** - by frequency - Nov-24-2018, 02:49 AM
RE: fibonacci ***Time limit exceeded*** - by ichabod801 - Nov-24-2018, 03:55 AM
RE: fibonacci ***Time limit exceeded*** - by nilamo - Nov-27-2018, 10:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fibonacci Yasunaga 7 4,636 May-16-2021, 02:36 PM
Last Post: csr
  Assign a value if datetime is in between a particular time limit klllmmm 2 3,731 Jan-02-2021, 07:00 AM
Last Post: klllmmm
  Time Limit Exceeded error loves 5 4,614 Dec-03-2020, 07:15 AM
Last Post: Sofia_Grace
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 6,328 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  RecursionError: maximum recursion depth exceeded in comparison ? leoahum 11 17,094 Mar-18-2019, 01:53 PM
Last Post: leoahum
  'Time Limit Exceeded' Problem bkpee3 2 7,751 Nov-14-2018, 03:51 AM
Last Post: bkpee3
  If conditions with time limit unknowntothem 4 4,202 Nov-09-2018, 08:59 PM
Last Post: nilamo
  Fibonacci sequence Darbandiman123 2 3,498 Sep-26-2018, 02:32 PM
Last Post: Darbandiman123
  Help debug my fibonacci implementation dineshpabbi10 6 5,447 May-16-2018, 12:12 PM
Last Post: dineshpabbi10
  maximum recursion depth exceeded saba_keon 3 9,292 Apr-08-2018, 07:30 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020