Question d’entretien chez Square

Given the provided problem, write out a way to solve it using code.