Goldman Sachs interview question

A coding question of leetcode medium difficulty