22 lines
690 B
Python
22 lines
690 B
Python
# HumanEval/73
|
|
# Loki Mode Multi-Agent Solution
|
|
# Attempts: 1
|
|
# Passed: True
|
|
|
|
def smallest_change(arr):
|
|
"""
|
|
Given an array arr of integers, find the minimum number of elements that
|
|
need to be changed to make the array palindromic. A palindromic array is an array that
|
|
is read the same backwards and forwards. In one change, you can change one element to any other element.
|
|
|
|
For example:
|
|
smallest_change([1,2,3,5,4,7,9,6]) == 4
|
|
smallest_change([1, 2, 3, 4, 3, 2, 2]) == 1
|
|
smallest_change([1, 2, 3, 2, 1]) == 0
|
|
"""
|
|
n = len(arr)
|
|
changes = 0
|
|
for i in range(n // 2):
|
|
if arr[i] != arr[n - 1 - i]:
|
|
changes += 1
|
|
return changes |