PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/LinkedIn

Generate uniform 0–6 from biased coin

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of randomized algorithms, probability theory, and techniques for extracting uniform randomness from a biased source.

  • medium
  • LinkedIn
  • Coding & Algorithms
  • Machine Learning Engineer

Generate uniform 0–6 from biased coin

Company: LinkedIn

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a function: - `int getRandom01Biased()` returns `0` with probability `p` and `1` with probability `1-p`, where `p` is unknown and may be any value in `(0,1)`. Design and implement: - `int getRandom06Uniform()` that returns an integer in `[0,6]` with *exactly uniform* probability `1/7`. Constraints/notes: - You may call `getRandom01Biased()` multiple times. - The algorithm must be correct for any `p` in `(0,1)`. - Discuss expected number of calls (at least at a high level).

Quick Answer: This question evaluates understanding of randomized algorithms, probability theory, and techniques for extracting uniform randomness from a biased source.

Related Interview Questions

  • Count Trips From Vehicle Logs - LinkedIn (easy)
  • Design O(1) Randomized Multiset - LinkedIn (easy)
  • Process Mutable Matrix Sum Queries - LinkedIn (medium)
  • Design a Randomized Multiset - LinkedIn (medium)
  • Can You Place N Objects? - LinkedIn (medium)
LinkedIn logo
LinkedIn
Feb 18, 2026, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
12
0

You are given a function:

  • int getRandom01Biased() returns 0 with probability p and 1 with probability 1-p , where p is unknown and may be any value in (0,1) .

Design and implement:

  • int getRandom06Uniform() that returns an integer in [0,6] with exactly uniform probability 1/7 .

Constraints/notes:

  • You may call getRandom01Biased() multiple times.
  • The algorithm must be correct for any p in (0,1) .
  • Discuss expected number of calls (at least at a high level).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More LinkedIn•More Machine Learning Engineer•LinkedIn Machine Learning Engineer•LinkedIn Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

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

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.