IMC Trading interview question

Solve a problem on hackerrank