Question: please help fix my code i cant get it to run correctly. ill lleave the code and error below # - - - - -

please help fix my code i cant get it to run correctly. ill lleave the code and error below # ------------------- PROBLEM 5- SA_RANGE ----------------------------------
def sa_range(start: int, end: int)-> StaticArray:
"""
Function that receives the two integers start and end and returns StaticArray
containing all consecutive integers start and end 0(N) complexity
"""
arr = StaticArray(end - start +1)
for i, j in enumerate(range(start, end +1)):
arr.set(i, j)
return arr
# ------------------- PROBLEM 6- IS_SORTED --------------------------------
def is_sorted(arr: StaticArray)-> int:
"""
Function receives StaticArray and returns integer returns array that describes
if array is sorted: 1 if ascending, -1 descending and 0 otherwise
"""
ascending = True
descending = True
for i in range(1, arr.length()):
if arr.get(i) arr.get(i -1):
ascending = False
if arr.get(i)> arr.get(i -1):
descending = False
if not ascending and not descending:
return 0
return 1 if ascending else -1
# ------------------ PROBLEM 8- REMOVE_DUPLICATES -------------------------
def remove_duplicates(arr: StaticArray)-> StaticArray:
"""
Function receives a StaticArray already sorted, non-descending or non-ascending
Returns a new static array with all duplicate values removed
"""
unique = StaticArray(1)
unique.set(0, arr.get(0))
for i in range(1, arr.length()):
if arr.get(i)!= arr.get(i-1):
unique.set(unique.length(), arr.get(i))
return unique
# ------------------- PROBLEM 9- COUNT_SORT --------------------------------
def count_sort(arr: StaticArray)-> StaticArray:
"""
Function receives a StaticArray and returns a new StaticArray with same content
sorted in non-ascending order using count sort algorithm
"""
max_value = arr.get(0)
for i in range(1, arr.length()):
if arr.get(i)> max_value:
max_value = arr.get(i)
count =[0]*(max_value +1)
for i in range(arr.length()):
count[arr.get(i)]+=1
for i in range(1, max_value +1):
count[i]+= count[i-1]
sorted_array = StaticArray(arr.length())
for i in range(arr.length()-1,-1,-1):
sorted_array.set(count[arr.get(i)]-1, arr.get(i))
count[arr.get(i)]-=1
return sorted_array
 please help fix my code i cant get it to run

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!