Simulate Radioactive Decay to Validate Analytical Solution
Company: Upstart
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
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.
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
- 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.
- 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.
- 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.