Skip to content

Practice Probability of a Two Boxes Having The Same Number of Distinct Balls

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1467
LeetCode Problem

Probability of a Two Boxes Having The Same Number of Distinct Balls

Problem Statement

Given 2n balls of k distinct colors. You will be given an integer array balls of size k where balls[i] is the number of balls of color i. All the balls will be shuffled uniformly at random, then we will distribute the first n balls to the first box and the remaining n balls to the other box (Please read the explanation of the second example carefully). Please note that the two boxes are considered different. For example, if we have two balls of colors a and b, and two boxes [] and (), then the distribution [a] (b) is considered different than the distribution [b] (a) (Please read the explanation of the first example carefully). Return the probability that the two boxes have the same number of distinct balls. Answers within 10^-5 of the actual value will be accepted as correct.

Source: Probability of a Two Boxes Having The Same Number of Distinct Balls on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
balls = [1,1]
Output
1.00000

# Example 2

Input
balls = [2,1,1]
Output
0.66667

# Example 3

Input
balls = [1,2,1,2]
Output
0.60000

Constraints

1 <= balls.length <= 8
1 <= balls[i] <= 6
sum(balls) is even.

Related LeetCode Problems

Practice more problems similar to Probability of a Two Boxes Having The Same Number of Distinct Balls.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.