Amazon Interview Question

How is this way the best way