LinkedIn interview question
Roll a die whose faces have given probabilities
- Company:
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- November 18, 2026
Problem
You are given the probability of each face of a die. Implement a function that rolls the die: each call returns one face, and over many calls each face appears with its given probability.
In this version the input is a list probs, where probs[i] is the probability of face i + 1, and roll() returns a face number. The interviewer followed up with corner cases; which inputs count as invalid is something to agree on.
Example 1
Input: probs = [0.5, 0.25, 0.25]; roll() called many times
Output: face 1 about 50% of the time, faces 2 and 3 about 25% each
Face 1 owns the first half of the [0, 1) range, faces 2 and 3 a quarter each.
Example 2
Input: probs = [0.5, 0.0, 0.5]
Output: face 2 is never returned
A face with probability 0 owns an empty part of the range.
Constraints
- Not stated; ask the interviewer.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern