Given two list of n positive elements. 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 make each element of first list equal to corresponding element in second list ? Write $-1$ if it is not possible.
For example, $n=3$ and list first $3 \ 2 \ 2$. Second list is $4 \ 5 \ 3$. We need $5$ such transformation as $$3 \ 2 \ 2 \to 2 \ 3 \ 3 \to 3 \ 4 \ 2 \to 2 \ 5 \ 3 \to 3 \ 4 \ 4 \to 4 \ 5 \ 3$$ Some thoughts:
Constraints, $1\le n \le50, ,1 \le \text{list elemensts} \le 50$. 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?
In your question you do not mention that the one element that is not incremented is decremented, but since this is clear from your example, I will assume that this indeed is your intention.
Assume your first list is $a_1,\ldots,a_n$, your second list is $b_1,\ldots,b_n$.
Let $a=\sum a_i$ and $b=\sum b_i$. Each step adds $n-2$ to the total sum, so a first requirement is that $n-2\mid b-a$. Let $p=\frac{b-a}{n-2}$. This is the number of operations we will need.
Now we note that after each operation the parity of each number swaps, so a second requirement (now we know the number of operations) is that for each $i$ the parity of $b_i-a_i$ is equal to the parity of $p$.
For one operation we will call the number that gets decremented the 'special' number. Note that the sequence in which you perform the operations is irrelevant. Let $p_i$ be the number of times the special number is at the $i-th$ position.
Since every operation has exactly one special number we have $\sum p_i=p$. The number at position $i$ will be the special number $p_i$ times. The other $p-p_i$ times it is not the special number, so we have $b_i=a_i-p_i+(p-p_i)$ or $p_i=\frac{a_i-b_i+p}{2}$. Our third (and last) restriction is that all $p_i$ are not negative. Note that the parity restriction already makes sure that they are really integers.
And this finishes our "algorithm".
I will demonstrate it on your own example:
$n=3$ and $a_1=3,a_2=2,a_3=2,b_1=4,b_2=5,b_3=3$.
So $a=\sum a_i=7$ and $b=\sum b_i=12$.
Our first requirement that $n-2\mid b-a$ is fulfilled and $p=\frac{b-a}{n-2}=5$.
Now $p_1=\frac{a_1-b_1+p}{2}=2$, so the first number must be special twice. Ditto we find $p_2=1$ and $p_3=2$.
So first we take the first element special twice, giving $322\rightarrow233\rightarrow144$.
Then we take the second element special, giving $144\rightarrow235$.
Finally we take the third element special, giving $235\rightarrow344\rightarrow453$.
In a nutshell: compute the $p_i$ while checking the restrictions. The list of $p_i$'s is your answer (provided there is a solution). This can be done in linear time, so even lists of a million entries will be done in a heartbeat.