PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates understanding of probability and expected value, modeling of state-based stochastic processes (Markov chains), and the ability to represent state transitions for computing hitting times in an algorithmic context.

  • hard
  • Qube
  • Coding & Algorithms
  • Software Engineer

Compute expected days until no whole pills

Company: Qube

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

A bottle initially contains **H half-pills** and **W whole pills**. Each day: 1. You randomly select **one pill uniformly** from the bottle. 2. If it is a **half-pill**, you consume it entirely (it is removed). 3. If it is a **whole pill**, you consume **half** and put the **remaining half** back into the bottle. (So selecting a whole pill decreases the number of whole pills by 1 and increases the number of half-pills by 1.) You always consume exactly **half a pill per day**. Task: **Compute the expected number of days until the bottle contains no whole pills** (i.e., only half-pills remain). ### Input - Two integers `H` and `W`. ### Output - A floating-point number: the expected number of days until `W = 0`. ### Example instance - `H = 25`, `W = 25`. ### Constraints (for your implementation) - You may assume `0 ≤ H, W ≤ 200` (or similar), and you should output the expectation with reasonable precision (e.g., `1e-6`).

Quick Answer: This question evaluates understanding of probability and expected value, modeling of state-based stochastic processes (Markov chains), and the ability to represent state transitions for computing hitting times in an algorithmic context.

Return expected days until W whole pills reaches zero under uniform random selection.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (0, 1)

Expected Output: 1.0

Explanation: One whole pill must be selected once.

Input: (1, 1)

Expected Output: 1.5

Explanation: May pick half first or whole first.

Input: (25, 25)

Expected Output: 70.222503

Explanation: Prompt-sized example.

Hints

  1. Choose a representation that makes the requested operation direct.
  2. Handle empty inputs and boundary cases first.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

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

Product

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

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.