Anthropic interview question
Simulate a fair coin using a biased coin
- Company:
- Anthropic
- Type:
- Coding
- Difficulty:
- Easy
- Reported:
- November 16, 2026
Problem
You have a function unfair() that simulates a biased coin: it returns heads (True) with some fixed but unknown probability and tails (False) otherwise. Use it to implement fair_coin(), which returns heads and tails with equal probability.
The interviewer described the intended method: toss the biased coin twice; heads then tails counts as heads, tails then heads counts as tails; if the two tosses match, toss twice again.
Example 1
Input: unfair() produces H, H, T, T, H, T
Output: True
The first two pairs match and are discarded; the third pair is heads then tails, so the result is heads.
Example 2
Input: unfair() produces T, H
Output: False
Tails then heads counts as tails.
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