Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time Limit Exceeded error
#2
Your solution is slow because the algorithm is inefficient. You are computing every possible volume (area) and picking the max. With 5000 heights this is 4999 * 4999 / 2 volumes to calculate and compare. When I run your solution it took 19 seconds.

Take some time and think about the problem instead of the code. There is a way to solve this problem with less than 5000 calculations and comparisons.

I'll give you three hints.
1. Solving for height[0], height[4999] is a good first guess because width is important.
2. The shorter "wall" limits the volume.
3. Draw a bar chart on paper with different sized walls when thinking about the problem.

I have a solution that runs in 0.0193 seconds and it isn't using any fancy Python to speed things up. Just an efficient algorithm.
Reply


Messages In This Thread
Time Limit Exceeded error - by loves - Dec-02-2020, 09:40 PM
RE: Time Limit Exceeded error - by deanhystad - Dec-02-2020, 11:31 PM
RE: Time Limit Exceeded error - by Sofia_Grace - Dec-03-2020, 07:15 AM
RE: Time Limit Exceeded error - by deanhystad - Dec-02-2020, 11:40 PM
RE: Time Limit Exceeded error - by loves - Dec-02-2020, 11:47 PM
RE: Time Limit Exceeded error - by deanhystad - Dec-03-2020, 06:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Plotting by Time, error mansoorahs 1 811 May-16-2023, 09:46 AM
Last Post: Larz60+
  Assign a value if datetime is in between a particular time limit klllmmm 2 2,853 Jan-02-2021, 07:00 AM
Last Post: klllmmm
  Time conversion error tester_V 1 2,102 Oct-28-2020, 10:48 PM
Last Post: tester_V
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,904 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  Read CSV error: python KeyError: 'Time' charlicruz 1 5,337 Jun-27-2020, 09:56 AM
Last Post: charlicruz
  Error when running the second time metro17 3 3,879 Aug-30-2019, 12:09 PM
Last Post: ThomasL
  RecursionError: maximum recursion depth exceeded in comparison ? leoahum 11 13,346 Mar-18-2019, 01:53 PM
Last Post: leoahum
  fibonacci ***Time limit exceeded*** frequency 18 10,626 Nov-29-2018, 09:03 PM
Last Post: frequency
  pyad time conversion error (plus solution) PapaZod 2 3,623 Nov-25-2018, 02:42 PM
Last Post: PapaZod
  'Time Limit Exceeded' Problem bkpee3 2 5,603 Nov-14-2018, 03:51 AM
Last Post: bkpee3

Forum Jump:

User Panel Messages

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