This Problem appeared on my Oracle OA and I don’t have any working solution or proper proof of what is the correct approach for this
You’re given an array and we need to find the minimum number of operations to make all elements equal
In one operation you can change a[i] and set it to new value
The allowed operations are:
1. arr[i] → any value in range [arr[i] + 1, arr[i] * 2]
2. arr[i] → any value in range [ceil(arr[i]/2), arr[i]-1]
You can perform either of these two types of operations any number of times (on any elements, in any order). You have to output the minimum number of operations to make all elements equal.
1 ≤ n ≤ 1e5
1 ≤ arr[i] ≤ 1e9
I tried making everything equal to the median, but it fails on this case:
9 10 12 30 1000
Converting to median takes 11 operations
but the ans is 10 (Converting every element to 16)







