Leetcode 2940. Find Building Where Alice and Bob Can Meet
For each query (a,b) return the leftmost index j > max(a,b) such that heights[j] > heights[a] and heights[j] > heights[b], or -1 if no such building exists. The core challenge is answering many "first element to the right exceeding a given threshold" queries efficiently, typically via next-greater/monotonic-stack preprocessing and jump pointers (binary lifting).
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Your account is free and you can post anonymously if you choose.