Flatiron Health Interview Question

How would you approach this problem using R?