You are viewing a single comment's thread. Return to all comments →
Python
def count_ops(arr, result_arr): arr = arr.copy() operations = 0 arr_map = {value: index for index, value in enumerate(arr)} for index, value in enumerate(arr): target_value = result_arr[index] if value != target_value: target_index = arr_map[target_value] arr[target_index] = value arr_map[value] = target_index operations += 1 return operations def lilysHomework(arr): reversed_arr = arr[::-1] sorted_arr = sorted(arr) return min(count_ops(arr, sorted_arr), count_ops(reversed_arr, sorted_arr))
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
Python