Phenom Interview Question

related to designing an algorithm for the use case