Array: next greater element in less than O(n2)