Goldman Sachs interview question

Coding related to maths