Interview Question
Financial Software DevelopersHow is it (m+1)!/(m+1-n)! ? I think it is (m+1)!/(m-1-n)! for the number of passengers to be different on each bus. What do you say?
If you plug the numbers in you'll see that your equation won't work for when there are two buses with max 1 passenger. You multiply m+1 with m, m-1, m-2, etc and do this n steps. M+1-n factorial is to cancel out the remaining terms in m+1! after nth step.
This is what I think:
1 - P (all the buses having distinct numbers of passengers)
Which boils down to:
1 - m * (m - 1) * ... * (m - (n - 1))
(you can derive this with principle of counting)
Which is:
1 - m! / (m - n)!
Now, an important assumption here is that
m > n
otherwise the answer is just
1
, because no matter how you allocate passengers to buses, at least two of the buses will have equal passengers.
Please correct me if I'm wrong.
This is equal to 1-(probability that they all carry different number of passengers). That probability in paranthesis is equal to (m+1)!/((m+1-n)! * (m+1)^n). This is given that (m+1) >= n. If (m+1) < n, then the probability is 1.
- barcod April 09, 2011- m+1 because maximum m passengers mean m+1 different possiblities (a bus could carry 0 passengers).
- The first bus has (m+1) possibilities in terms of number of passengers. The second has m+1, the third has m+1 and so on. Total number of orderings possible is (m+1) ^ n.
- For the number of passengers to be different in each bus, first bus has m+1 possibilities, second has m, third has m-1 nd so on. For n buses, this is equal to (m+1)!/(m+1-n)!. Dividing this by (m+1)/n gives the possibility. Subtract this number from one to find at least two buses with the same amount of passengers.