Pregunta de entrevista de J.P. Morgan

Two different code solutions how would you solve that conflict?