Imagine you're a statistician at a game show where contestants must predict probability outcomes! You have 2n balls of k distinct colors, and you need to calculate the probability that two boxes end up with the same number of distinct colors after a random distribution.
Given an integer array balls of size k where balls[i] represents the number of balls of color i, all balls are shuffled uniformly at random. Then, the first n balls go to Box 1 and the remaining n balls go to Box 2.
Important: The two boxes are considered different. For example, with balls of colors 'a' and 'b', the distribution [a] (b) is different from [b] (a).
Goal: Return the probability that both boxes have the same number of distinct ball colors. Your answer should be accurate within 10-5 of the actual value.
Input & Output
Visualization
Time & Space Complexity
For each color, we try 0 to balls[i] in first box, but pruning reduces actual complexity significantly
Recursive call stack depth equals number of colors
Constraints
- 1 โค balls.length โค 8
- 1 โค balls[i] โค 6
- 2 * n == sum(balls) where n is the number of balls per box
- Answers within 10-5 of actual value are accepted