J.P. Morgan Interview Question

Two different code solutions how would you solve that conflict?