Question d’entretien chez BlackBelt Technology

How would you solve this problem with an algorithm? Can we make it more efficient?