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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started