Compute bus-on-time and dice-sum probabilities
Company: Sig
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: HR Screen
Quick Answer: This question evaluates understanding of probability concepts including a continuous uniform waiting-time model for bus arrivals and discrete outcome counting for the sum of two dice, testing probabilistic reasoning, uniform distributions, and basic combinatorics.
Part 1: Bus Arrival Before the Movie
Constraints
- 1 <= I <= 10^9
- 0 <= R <= 10^9
- 0 <= L <= 10^9
- All inputs are integers
Examples
Input: (10, 25, 30)
Expected Output: "1/2"
Explanation: The person must have W <= 5. Since W is uniform over a 10-minute interval, the probability is 5/10 = 1/2.
Input: (10, 25, 25)
Expected Output: "0"
Explanation: The person would need W <= 0, but waiting time is always positive, so the probability is 0.
Input: (10, 25, 40)
Expected Output: "1"
Explanation: The person can wait as long as 15 minutes, but the maximum wait is only 10 minutes, so they are always on time.
Input: (10, 25, 28)
Expected Output: "3/10"
Explanation: The person must have W <= 3, so the probability is 3/10.
Input: (7, 3, 10)
Expected Output: "1"
Explanation: The allowed wait is exactly 7 minutes, which matches the entire bus interval, so every arrival works.
Hints
- Let W be the waiting time for the next bus. The person is on time exactly when W + R <= L.
- Because arrival is uniform within one interval, W is uniform over one full bus interval. The answer is a clamped fraction based on how much waiting time is allowed.
Part 2: Probability of a Two-Dice Sum
Constraints
- 2 <= S <= 12
- The dice are standard fair six-sided dice with faces 1 through 6
Examples
Input: (2,)
Expected Output: "1/36"
Explanation: Only (1, 1) gives a sum of 2.
Input: (7,)
Expected Output: "1/6"
Explanation: There are 6 outcomes that sum to 7: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1). So the probability is 6/36 = 1/6.
Input: (12,)
Expected Output: "1/36"
Explanation: Only (6, 6) gives a sum of 12.
Input: (9,)
Expected Output: "1/9"
Explanation: There are 4 outcomes that sum to 9, so the probability is 4/36 = 1/9.
Input: (6,)
Expected Output: "5/36"
Explanation: There are 5 outcomes that sum to 6: (1,5), (2,4), (3,3), (4,2), (5,1).
Hints
- Count ordered pairs (d1, d2) out of the 36 equally likely outcomes.
- The number of ways grows from sum 2 up to sum 7, then decreases symmetrically.