Please solve this question in Java
140
Feb 20, 2022

You are give a circular array A containing N integers. You can perform the following operation on this array any number of times.
For each i, replace A[i] by A[i-1], A[i] or A[i+1] i.e you can keep the current element or replace it by an adjacent element. Note that due to circularity of the array adjacent elements exist even for the first and last element. A[i-1] for i=0 is the last element.
Determine the minimum number of steps need to make all the elements of the array equal.
sample test cases:
input a={2,2,1,1}
output=1
input a={1,1,1}
output=0
input a={1,7,2,4,4,5,6}
output=3

Comments (2)