Goldman Sachs interview question

Coding and maths related qn on hackerrank