J.P. Morgan interview question

Two different code solutions how would you solve that conflict?