Flatiron Health Interview Question

Design an algorithm to solve this problem.