Find the Next Greater Element

Given an array, find the next greater element for each element using a stack.

Input