Question: Write a procedure unimodal to check whether or not a list of numbers is unimodal. The input should be a list and the output should be true or false..

April 23 2014 jbk99429 5

1

the sequence is non-decreasing up to some point after which it is non-increasing. Note that i can be 1 or n. A constant sequence is considered to be unimodal.

Examples of unimodal lists:

[1, 1, 1, 1, 1],
[1, 2, 2, 3, 4, 5, 5, 5],
[5, 5, 4, 4, 3, 3, 1],
[1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1],
[1, 2, 2, 3, 3, 3, 4, 4, 2, 2, 1, 1, 1]

 

Examples of lists that are not unimodal:

[1, 0, 1, 0],
[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1],
[1, 1, 2, 2, 3, 4, 5, 2, 2, 6, 4, 2, 2, 1, 0]

 

i don't have a clue

Please Wait...