Given a list of $n$ positive elements (including $0$). We are allowed to perform only one transformation which is to increment each element of the list except one. What are the minimum number of transformation required to equalize this list?
For example, $n = 3$ and the list being $1,2,3$. We need $3$ such transformation as $2,3,3 \to 3,3,4 \to 4,4,4$
For $n = 4$ and the list being $1,3,2,4$ the minimum number of transformation required is $6$
I implemented something like breadth first search to solve this one but due to it's unique nature the graph is growing large very fast making my solution taking too much time even for $n = 6$.
Which is the best approach to solve this?