LeetCode
Next Greater Element III
Click
here
for an explanation.