Pergunta de entrevista da empresa Goldman Sachs

Stack realted question - next greater element