PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to implement Monte Carlo simulations and validate analytical probability results, testing skills in stochastic processes, numerical estimation, and programming within the Coding & Algorithms domain for data scientist roles.

  • Medium
  • Upstart
  • Coding & Algorithms
  • Data Scientist

Simulate Radioactive Decay to Validate Analytical Solution

Company: Upstart

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Scenario Same radioactive-decay problem, but now validate the analytical answer via simulation during the interview. ##### Question Share screen and write runnable code (any language) that Monte-Carlo simulates the decay of 100 particles, repeats many trials, and estimates the survival probability computed above. ##### Hints Generate exponential or Bernoulli survival, loop many trials, collect frequencies, compare to theoretical value.

Quick Answer: This question evaluates a candidate's ability to implement Monte Carlo simulations and validate analytical probability results, testing skills in stochastic processes, numerical estimation, and programming within the Coding & Algorithms domain for data scientist roles.

A classic interview follow-up to the radioactive-decay problem asks you to Monte-Carlo simulate the decay of N particles and compare the empirical survival frequency to the analytical answer. The quantity the simulation converges to is deterministic, so implement that analytical target directly. For a single radioactive particle with decay rate (lambda) `decay_rate`, the probability it has NOT decayed by time `t` is `exp(-decay_rate * t)`. For `num_particles` independent identical particles, the expected number still alive at time `t` is `num_particles * exp(-decay_rate * t)`. Write a function `survivalEstimate(decay_rate, time, num_particles)` that returns a list `[survival_prob, expected_survivors]` where: - `survival_prob` is `exp(-decay_rate * time)` rounded to 6 decimal places, - `expected_survivors` is `num_particles * survival_prob` rounded to 4 decimal places. This is exactly the value a long Monte-Carlo run (Bernoulli survival per particle, averaged over many trials) converges to. Robustness: treat a negative `decay_rate` or negative `time` as no decay (survival probability 1.0), and treat a non-positive `num_particles` as 0 particles (0 expected survivors). Examples: - `survivalEstimate(0.5, 2.0, 100)` -> `[0.367879, 36.7879]` (since exp(-1.0) ~= 0.3678794). - `survivalEstimate(0.0, 5.0, 100)` -> `[1.0, 100.0]` (no decay). - `survivalEstimate(0.693147, 1.0, 80)` -> `[0.5, 40.0]` (one half-life: exp(-ln2) = 0.5).

Constraints

  • 0.0 <= decay_rate <= 100.0 (negative values are treated as 0)
  • 0.0 <= time <= 1e4 (negative values are treated as 0)
  • 0 <= num_particles <= 1e9 (negative values are treated as 0)
  • survival_prob is rounded to 6 decimal places
  • expected_survivors is rounded to 4 decimal places

Examples

Input: (0.0, 5.0, 100)

Expected Output: [1.0, 100.0]

Explanation: Zero decay rate: every particle survives, so survival_prob=1.0 and all 100 particles remain.

Input: (0.5, 2.0, 100)

Expected Output: [0.367879, 36.7879]

Explanation: decay_rate*time = 1.0, so survival_prob = exp(-1) ~= 0.367879; expected survivors = 100 * that ~= 36.7879.

Input: (0.1, 10.0, 100)

Expected Output: [0.367879, 36.7879]

Explanation: Same exponent (0.1*10 = 1.0) as the previous case, confirming the value depends only on the product decay_rate*time.

Input: (0.693147, 1.0, 80)

Expected Output: [0.5, 40.0]

Explanation: One half-life: decay_rate*time = ln(2), so survival_prob = exp(-ln2) = 0.5; half of 80 particles survive -> 40.0.

Input: (1.0, 0.0, 50)

Expected Output: [1.0, 50.0]

Explanation: At t=0 no decay has occurred, so survival_prob=1.0 and all 50 particles are still present.

Input: (0.5, 2.0, 0)

Expected Output: [0.367879, 0.0]

Explanation: Survival probability is still exp(-1) ~= 0.367879, but with zero particles the expected number of survivors is 0.0.

Input: (-1.0, 5.0, 100)

Expected Output: [1.0, 100.0]

Explanation: A negative decay_rate is clamped to no decay, so survival_prob=1.0 and all 100 particles survive.

Input: (2.0, 3.0, 1)

Expected Output: [0.002479, 0.0025]

Explanation: Strong decay: decay_rate*time = 6.0, survival_prob = exp(-6) ~= 0.002479; the single particle's expected survival is ~0.0025.

Hints

  1. The probability a single particle survives to time t is exp(-decay_rate * t). This is the limit a Monte-Carlo Bernoulli simulation converges to as trials grow.
  2. Multiply the per-particle survival probability by num_particles to get the expected number of survivors — no loop or random sampling is required for the analytical target.
  3. Guard the edge cases: a zero (or negative) decay_rate or time means survival probability 1.0; a half-life corresponds to decay_rate * time = ln(2), giving probability exactly 0.5.
Last updated: Jun 25, 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
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Maximum Eastbound City Visits and Parse CSV - Upstart (medium)
  • Implement Byte Formatting and Cafeteria Billing - Upstart (medium)
  • Implement Three Assessment Functions - Upstart (medium)
  • Solve Five OA Coding Tasks - Upstart (medium)
  • Solve Reported OA Coding Problems - Upstart (medium)