# How to find out the average salary?

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.

## 2 Answers

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$.

• 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. :-) Feb 22 '17 at 19:41
• 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.
– 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.