Question d’entretien chez Goldman Sachs

Solve this problem: hackerrank tests