Question: Will rate if done in python def climbing(heights,rest,limit): Assumption: 'heights' is a nonempty list of positive integers that are strictly increasing and both 'rest'
Will rate if done in python
| def climbing(heights,rest,limit): | |
| """ | |
| Assumption: 'heights' is a nonempty list of positive integers that are | |
| strictly increasing and both 'rest' and 'limit' are positive integers. | |
| The list 'heights' is the various heights (in feet) of ledges on a cliff. | |
| The value 'rest' represents how many seconds you have to rest between | |
| climbing "bursts" (see the description below). | |
| The value 'limit' is how many seconds you have to climb the cliff, and is | |
| guaranteed to be at least the last height in the list. | |
| Suppose you are able to climb 1 foot per second consecutively for a certain | |
| amount of time, let's call this time 'burst'. However, after at most 'burst' | |
| seconds you have to rest for 'rest' seconds on one of the ledges of the | |
| cliff to regain your stamina. You cannot rest while hanging on to the cliff, | |
| you have to be on a ledge when you rest. You rest the same amount of time | |
| even if your latest climb was not for 'burst' seconds. | |
| What is the minimum value of 'burst' such that you are able to reach the | |
| highest ledge in at most 'limit' seconds? | |
| Example 2: | |
| climbing([50, 100], 1, 100) | |
| 100 | |
| That is, you can reach the top in a single burst if you can climb for 100 | |
| seconds consecutively. | |
| However, if you can only climb for 99 seconds consecutively then the best | |
| you can do is reach ledge 50, rest for 1 second, then reach the top for a | |
| total of 101 seconds. | |
| Example 3: | |
| climbing([50, 99], 1, 100) | |
| 50 | |
| That is, if you can climb for 50 seconds consecutively then you can reach | |
| the ledge at height 50 in your first burst, rest for 1 second, then reach | |
| the top after 49 more seconds for a total of 100 seconds. | |
| But if you can only climb for 49 seconds consecutively then you can't even | |
| reach the first ledge! | |
| """ | |
| pass |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
