Goldman Sachs Interview Question

Coding and maths related qn on hackerrank