Question: In python. Write a function max_increase(seq) which takes as argument a sequence of numbers and returns the maximum increase from one element in the sequence

In python.

Write a function max_increase(seq) which takes as argument a sequence of numbers and returns the maximum increase from one element in the sequence to an element at a higher index. However, these can not be any two points: the low point must come before the high point. For example

1500, 999, 1000, 229, 337, 300, 364, 485, 529, 511. 

The biggest increase is from 229 to 529, so we should get a return of 300.

Assumptions and restrictions:

1 - The function must return a number.

2- If there is no increasing pair in the sequence, the function should return 0. This may happen for example if the sequence is decreasing, or if it contains fewer than 2 elements.

3 - You can assume that the argument is a sequence, and that its elements are numbers (integer or decimal), but other than that you should not make any assumptions. In particular, you should not assume that it is any particular type of sequence (list, array, etc) and use only operations that are applicable to all sequence types.

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!