Fidelity Investments Interview Question

Basic hackerrank