You have a total of 2n balls classified into k different colors. The array balls of length k specifies how many balls exist for each color. All balls are mixed randomly and from this shuffled arrangement, the first n balls are placed into Box 1 and the remaining n balls into Box 2.
The two boxes are considered distinct, meaning different ball placements into the boxes count as different outcomes.
Your task is to compute the probability that both Box 1 and Box 2 contain the same number of unique colors after the distribution. A result within 1e-5 of the actual probability will be accepted.
Input: balls = [2,2]
Output: 0.50000
Explanation:
Total balls: [A, A, B, B] Possible valid random assignments give half cases where both boxes have equal distinct colors. Probability = 1/2 = 0.5
Input: balls = [1,3]
Output: 1.00000
Explanation:
Box 1 must take 1 ball of the only 1-color group or from the 3-color group, but both boxes will always have exactly 1 distinct color. Probability = 1
Input: balls = [3,1,1]
Output: 0.42857
Explanation:
Shuffles create different patterns, some produce equal unique color counts and others don't. Final Probability ≈ 0.42857
Accepted:
Submission: