Phenom interview question

related to designing an algorithm for the use case