Average salary of n people in the room

Question: How can n people know the average of their salaries without disclosing their own salaries to each other? Solution: Let’s say salaries of n people (P1, P2, P3…..Pn) are S1, S2, S3…..Sn respectively. To know the average of the salary i.e. (S1 + S2 + S3 + ….. + Sn) / n, they will follow the following steps - P1 adds a random amount, say R1 to his own salary and gives that to P2 (P2 won’t be able to know P1’s salary as he has added a random amount known to him only). [Read More]

Given a number 123456789, two opearators + and *, value k , find all the such expressions that evaluates to the given value k

Problem  Given a number 123456789 and two opearators + and *. You can use this two operators as many times u want. But you cant change the sequence of the number given there. The evaluated value is 2097. e.g. 1+2+345*6+7+8+9=2097 You have to find all the such expressions that evaluates and value is equal to the given value. You can use concatenation of numbers like 345 is concatenated there. [Read More]

Median of 2 sorted arrays of equal size n

Question  There are 2 sorted arrays A and B. Write an algorithm to find the median of the array obtained after merging the above 2 arrays(i.e. array of length 2n). The complexity should be O(log(n)) Solution Before going to solution what is the median. What is Median? Median: In probability theory and statistics, a median is described as the number separating the higher half of a sample, a population, or a probability distribution, from the lower half. [Read More]