Log Date

Welcome to techInterview, a site for technical interview questions, brain teasers, puzzles, quizzles (whatever the heck those are) and other things that make you think!

1. Text post

### Salaries

Three coworkers would like to know their average salary. how can they do it, without disclosing their own salaries?

### Solution

How about: Person A writes a number that is her salary plus a random amount (AS + AR) and hands it to B, without showing C. B then adds his salary plus a random amount (BS + BR) and passes to C (at each step, they write on a new paper and don’t show the 3rd person). C adds CS + CR and passes to A. Now A subtracts her random number (AR), passes to B. B and C each subtract their random number and pass. After C is done, he shows the result and they divide by 3.

As has been noted already, there’s no way to liar-proof the scheme.

It’s also worth noting that once they know the average, any of the three knows the sum of the other 2 salaries.

1. techinterview posted this

Notes: 2 notes