Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Let a be a list of int numbers. It includes at least 3 elements. All elements are different. The list a is called up

image text in transcribedimage text in transcribedimage text in transcribed

Python Let a be a list of int numbers. It includes at least 3 elements. All elements are different. The list a is called up side down if when going on all elements from left to right we get either more big, more small, more big, more small and so on, or, we can get also more small, more big, more small, more big, and so on. Examples: [-7, 15, -10, 2, 1, 14, 11, 17, 12] [15,-10, 2, 1, 14, 11, 17, 12, 16,-16] As we see, all elements are different. In the start we can have more big which means that the second element is more big than the first element (1st example). Also can we have more small, as is demonstrated in the 2nd example. As said the list has at least 3 elements We say that the list is about up side down if one of the elements (ONLY one) is not in the right direction (up or down) regarding its very previous element. Examples: [-7, 15, -10, 2, 14, 11, 17, 12] 14 should be more small than 2. However it is more big. All other elements that come after the 14 are OK regarding the 14. In total we get here up, down, up, up, down, up down. The problem is that we have up up onr after the other. The problematic element is the 14. [15, -10, -15] The problematic element here is -15. It should be more big than-10, not more small. Write a function check(a) The function gets the list a. All elements are int value. All elements are dofferent. There are at least 3 elements. The list is about up side down as described. The function returns as a result the index of the problematic element. Examples: check([-7, 15, -10, 2, 14, 11, 17, 12])== 4 # a[4]==14 check([15, -10,-15])== 2 # a[2]==-15 Requirements : The function should be efficient in Time and Space. Must NOT use recursion

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago