TuSimple Interview Question

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