Mark As Completed Discussion

Step 3 After iterating through all the other elements, push the next variable onto the stack.

Conclusion

Step 4 When the loop in step 2 is done, pop all the elements from stack and set -1 as the next greater element for them.