Question: is _ sorted ( arr: StaticArray ) - > int: Write a function that receives a StaticArray and returns an integer that describes whether the

is_sorted(arr: StaticArray)-> int:
Write a function that receives a StaticArray and returns an integer that describes whether
the array is sorted. The method must return:
1 if the array is sorted in strictly ascending order.
-1 if the list is sorted in strictly descending order.
0 otherwise.
Arrays consisting of a single element are considered sorted in strictly ascending order.
You may assume that the input array will contain one or more homogeneous elements
(either all numbers, or strings, or custom objects, but never a mix of these). You do not
need to write checks for these conditions.
The original array must not be modified.
For full credit, the function must be implemented with O(N) complexity, with no additional
data structures (including Static Arrays) being created. Code line begins with def is_sorted(arr: StaticArray)-> int: RESTRICTIONS: You are NOT allowed to use ANY built-in Python data structures and/or their methods in any of your solutions. This includes built-in Python lists, dictionaries, or anything else. Variables to hold a single value or a tuple holding two/three values are allowed. It is OK to use built-in Python generator functions like range(). You may not use any imports beyond the ones included in the assignment source code.

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!