PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Bytedance
  • Coding & Algorithms
  • Data Scientist

Probability That One Fair Die Beats Another

Company: Bytedance

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Probability That One Fair Die Beats Another Two fair dice, `A` and `B`, are represented by integer arrays. Each array element is one physical face, so duplicate values are allowed and count as distinct, equally likely outcomes. The dice may have different numbers of faces. Implement: ```python def solution(a: list[int], b: list[int]) -> float: ``` Return the probability, as a floating-point value, that a single roll of `A` is strictly greater than a single roll of `B`. Ties do not count. Examples: - `a = [1, 2, 3]`, `b = [1, 2, 3]` returns `3 / 9`. - `a = [2, 2]`, `b = [1, 2]` returns `2 / 4`. Assumptions: - Both arrays are non-empty. - Face values are integers. - Inputs may be large. - Your solution should avoid enumerating all `len(a) * len(b)` outcome pairs.

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.

Given two non-empty integer arrays representing equally likely die faces (duplicates count as distinct faces), return the probability that a roll from A is strictly greater than a roll from B.

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

  1. For a fixed face value from A, count how many values in B are strictly smaller.
  2. Sort one die, then use binary search for each face of the other die.
Last updated: Jul 9, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Merge Overlapping Intervals - Bytedance (easy)
  • Remove Duplicate Letters Lexicographically - Bytedance (medium)
  • Elements Occurring More Than n/3 Times in a Sorted Array - Bytedance (medium)
  • Least Frequently Used (LFU) Cache - Bytedance (hard)
  • Course Schedule Feasibility - Bytedance (hard)