Practice Find Building Where Alice and Bob Can Meet
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find Building Where Alice and Bob Can Meet
Problem Statement
You are given a 0-indexed array heights of positive integers, where heights[i] represents the height of the ith building. If a person is in building i, they can move to any other building j if and only if i < j and heights[i] < heights[j]. You are also given another array queries where queries[i] = [ai, bi]. On the ith query, Alice is in building ai while Bob is in building bi. Return an array ans where ans[i] is the index of the leftmost building where Alice and Bob can meet on the ith query. If Alice and Bob cannot move to a common building on query i, set ans[i] to -1.
Source: Find Building Where Alice and Bob Can Meet on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4],[3,4],[2,2]]
[2,5,-1,5,2]
# Example 2
heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[5,2],[3,0],[1,6]]
[7,6,-1,4,6]
Constraints
Related LeetCode Problems
Practice more problems similar to Find Building Where Alice and Bob Can Meet.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.