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.

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.

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.

Loading coding console...