Official algorithmic problem description and constraints.
Let's call an array π beautiful if you can make all its elements the same by using the following operation an arbitrary number of times (possibly, zero):
You are given a beautiful array π1,π2,β¦,ππ. What is the minimum number of elements you have to remove from it in order for it to stop being beautiful? Swapping elements is prohibited. If it is impossible to do so, then output -1.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.