Pergunta de entrevista da empresa TuSimple

Two questions. One is finding the next greater element. Another is a general DFS question.