Probability That One Fair Die Beats Another
Company: Bytedance
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: Solve a coding interview problem about the probability that one fair die beats another when the dice may have different sizes and duplicate face values. The challenge emphasizes strict tie handling and an efficient approach that avoids comparing every possible pair of faces.
Constraints
- Both dice contain at least one face
- Face values are integers
- Inputs may be large; avoid enumerating every ordered pair
- Duplicate values represent distinct equally likely faces
Examples
Input: ([1, 2, 3], [1, 2, 3])
Expected Output: 0.3333333333333333
Explanation: Three of nine ordered outcomes satisfy A > B.
Input: ([2, 2], [1, 2])
Expected Output: 0.5
Explanation: Each 2 from A beats only the 1 face on B.
Hints
- For a fixed face value from A, count how many values in B are strictly smaller.
- Sort one die, then use binary search for each face of the other die.