Goldman Sachs interview question

2 Coding question of easy-medium level