I heard that this one was given problem in some job interview. Is this possible to do?

Three people wants to know what is their average salary but they don't want to tell their salary to others. How can they find out the average?

I couldn't think how to solve the problem.


The usual trick is to pass a running total around:

First person passes the total of $S_1+R_1$ to person two where $S_1$ is her salary and $R_1$ is a random number known only to her. Person two then adds $S_2+R_2$ and passes $S_1+S_2+R_1+R_2$ to person three and person three adds $S_3+R_3$ and passes the total $S_1+S_2+S_3+R_1+R_2+R_3$ back to person one Now, person one subtracts $R_1$ and passes the result to person two who subtracts $R_2$ and passes the result to person three who subtracts $R_3$. What's left is $S_1+S_2+S_3$.

  • 3
    $\begingroup$ Then when they take the average, they all say "Well, that's more than mine" and have to do it again, this time lying more. :-) $\endgroup$
    – Joffan
    Feb 22 '17 at 19:41
  • $\begingroup$ Nice. I was going to post an answer around the same time you did except mine was to use a spreadsheet program with 4 tabs, where the employees enter their salaries on one tab at a time and the 4th tab keeps a running average. Then I was going to post this comment right after that until my net connection dropped, freezing my PC. I hate interview questions like this. And technology. $\endgroup$
    – user307169
    Feb 22 '17 at 20:05

Call the salaries $X_1,X_2,X_3$. The first person generates a random number $R_1$ and tells the number $X_1+R_1$ to person two. Now, person two then does the same thing. Therefore, person three recieves the number $(X_1+R_1)+(X_2+R_2)$ Person three does the same thing and passes the result back to person one. Then they subtract out the random numbers that only they knew and divide by 3.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.