You have two arrays and where is a subset of . For each element in , find its next greater element in . Return if there is none.
This problem has a twist: you need to find next greater elements in , then look up the answers for elements in . Use a monotonic stack on , store results in a hash map, then query for elements.