Goldman Sachs interview question

Stack realted question - next greater element