Goldman Sachs interview question

2 Programming Questions of Medium Level