Goldman Sachs interview question

2 hard level DSA questions