Interview questions · Upstart
Implement decay simulation and trailing-zero counting
This Coding & Algorithms question for a Data Scientist role evaluates stochastic simulation and probability modeling for radioactive decay alongside combinatorics and number-theoretic reasoning for factorial trailing-zero computation, requiring implementation-level algorithmic thinking in Python.
Implement the following in Python:
-
Radioactive decay simulation: Half-life is 1 day. Write a simulation function that takes:
- input: integer m (number of days), integer n (number of atoms)
- process: simulate independent decay over time (you may model survival each day with probability 0.5, or equivalently sample each atom’s decay time)
- output: the final state of each particle (e.g., a boolean list/array of length n indicating survived/decayed after m days) and/or the number of survivors. Also discuss runtime and how you would validate correctness against the analytic Binomial(n, 0.5^m) result.
-
Factorial and trailing zeros:
- (a) Implement a factorial function in Python (mention multiple approaches).
- (b) Given an integer n, compute the number of trailing zeros in n! efficiently (better than computing n! explicitly).
Community answers
Nothing here yet.
Join in on CSWork →