Pergunta de entrevista da empresa J.P. Morgan

Two different code solutions how would you solve that conflict?