Domanda di colloquio di J.P. Morgan

Two different code solutions how would you solve that conflict?