Question: In python. Suppose we are building a game and a character in the game is a person known as Jim that loves to jump. Let's

In python. Suppose we are building a game and a character inthe game is a person known as Jim that loves to jump.In python.

Suppose we are building a game and a character in the game is a person known as Jim that loves to jump. Let's say that he can jump a maximum height of n. He is next presented with a list of buildings that he needs to jump over. Within the list are the individual heights of buildings. Hence it means that if we have the list [4, 6, 7] it would mean three buildings of height 4, 6, 7 In this game, Jim can drink a magic potion which allows him to increase the height of his jump by one unit. Suppose now the potion only allows him two jumps. So if say his maximum height is 5, he would need to drink 1 magic potion in the first jump over the building of height 6. He will need to take another drink to jump over the building of height 7. The number of potions he would require would then be equal to two in the example above. Your task is to write a function which takes as input the value n, the maximum height he can jump and array_list, the list of buildings. The function should return the number of magic potions he needs to drink. If he does not need to drink any potions, return 0. You may use the max function if you want. Input Format max_height number buildings building height one by one eg 5 4 3 4 5 6 This means the max height is 5, the number of buildings is 4 and the building heights are 3, 4, 5, 6 Constraints Heights are positive Output Format Output Format Number of potions to drink Sample Input 0 5 3 4 6 7 Sample Output 0 2 Sample Input 1 5 6 4 6 7 7 5 7 Sample Output 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!