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

Last Updated : 13 Mar, 2024

Improve

Improve

Like Article

Like

Save

Share

Report

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

Answer: Follow these steps

Step 1) X adds a Random Number and his salary and tells the sum to Y.

Step 2) Y also adds a Random Number and his salary to the sum told by X and tells new sum to Z.

Step 3) Z also adds a Random Number and his salary to the sum told by Y and tells new sum to X.

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

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

Step 6) Z subtracts its random number from the sum told by Y and announces the new number. The new number is now the sum of three salaries and the average can be calculated by dividing the sum by 3. Finally, nobody knows the salary of others, but all know average.

This can be extended to more than 3 employees also.

We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy

Improvement

Please go through our recently updated Improvement Guidelines before submitting any improvements.

This article is being improved by another user right now. You can suggest the changes for now and it will be under the article's discussion tab.

You will be notified via email once the article is available for improvement.
Thank you for your valuable feedback!

Please go through our recently updated Improvement Guidelines before submitting any improvements.

Suggest Changes

Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.

Create Improvement

Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.