Question: This is my code so far but I am getting error: def remove _ duplicates ( arr: StaticArray ) - > StaticArray: if arr.length (

This is my code so far but I am getting error: def remove_duplicates(arr: StaticArray)-> StaticArray:
if arr.length()==1:
return arr
result_size =1
current_value = arr.get(0)
for i in range(1, arr.length()):
if arr.get(i)!= current_value:
# If the current element is different from the previous one, add it to the result array
arr.set(result_size, arr.get(i))
result_size +=1
current_value = arr.get(i)
# Create a new StaticArray with the unique elements
result_arr = StaticArray(result_size)
for i in range(result_size):
result_arr.set(i, arr.get(i))
return result_arr This is the error: "8- Remove Duplicates - Test 1(0/5)
Description : This is the same test as in PDF Example 1
Input : STAT_ARR Size: 3[1,1,2]
Expected : STAT_ARR Size: 2[1,2]
Student : STAT_ARR Size: 2[1,2]
ERROR: Original array was modified
Modified Input: STAT_ARR Size: 3[1,2,2]
Test Failed: False is not true
8- Remove Duplicates - Test 2(0/5)
Description : Testing with an array of random values
Input : STAT_ARR Size: 13[719,410,408,291,291,291,291,158,158,158,-24,-381,-885]
Expected : STAT_ARR Size: 8[719,410,408,291,158,-24,-381,-885]
Student : STAT_ARR Size: 8[719,410,408,291,158,-24,-381,-885]
ERROR: Original array was modified
Modified Input: STAT_ARR Size: 13[719,410,408,291,158,-24,-381,-885,158,158,-24,-381,-885]" Please Help!!!

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!