Guessing a secret number to maximize the result

150 Views Asked by At

You are given a set $A$ (all elements are different and positive) and a set $B$ (all elements are different and positive).

Find a optimal number $x$ ( $0 < x \leqslant W$ where $W$ is a given integer ) such that following condition holds :

For example:

$A = \{3, 2, 5\}$

$B = \{1, 6, 3\}$

$A_d = \{1, 2, 3\}$ // this set we have calc. which contains all possible absolute differences of elements of $A$.

Now we are supposed to insert $x$ in $B$ such that the resultant set $B_d$ (formed by differences) have maximum number of same elements as $A_d$.

Given for this case $W=8$ so we can choose $x$ as 7 since $B_d$ set now will be $= \{3, 2, 5, 1, 4, 6\}$ which have all elements as $A_d$.

I hope someone will help me out this is really tricky I left no stones unturned but still not getting it how to do.