Puzzle 26 | (Know Average Salary without Disclosing Individual Salaries)

Three Employees want to know average of their salaries. They are not allowed to share their individual salaries.








Answer:
1) X adds a random number to his salary and tells the sum to Y.

2) Y also adds a random number to sum told by X and tells new sum to Z.

3) Z also adds a random number to sum told by Y and tells new sum to X.



4) X subtracts its random number from sum told by Z and tells the new number to Y.

5) Y subtracts its random number from sum told by X and tells the new number to Z.

6) Z subtracts its random number from sum told by Y and announces the new number.

The new number is now sum of three salaries and average can be calculated by dividing the sum by 3.

Finally, nobody knows salary of others, but all know average.

This can be extended to more than 3 employees also.

This article is contributed by Shivam. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


7


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.