Answer queries about the leftmost building where two people can meet given building heights and movement rules.
You are given an array of building heights. For each query involving Alice and Bob, determine the leftmost building index they can both reach under the problem's movement rules, or report that no meeting building exists.
A meeting building must be reachable by both people according to the rules implied by the query. When multiple buildings satisfy the condition, return the one with the smallest index.
This is an array-query problem that typically requires preprocessing the heights and answering each query efficiently.
heights representing the height of each building.The exact input encoding may vary by platform; the task is to process every query independently using the given building heights.
-1.1 <= heights.length.Exact official limits are not provided in the source metadata.
Example 1
Input
heights = [6,4,8,5,2,7], queries = [[0,1],[0,3],[2,4]]
Output
[2,5,5]
Explanation
For the first query, building 2 is the leftmost building both can reach. For the second and third queries, building 5 is the first valid meeting point.
Example 2
Input
heights = [5,3,8,2,6,1,4,6], queries = [[0,7],[3,5],[1,2]]
Output
[7,6,2]
Explanation
Each query asks for the leftmost index that satisfies the reachability condition for both people. The answer is the smallest valid index for each pair.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.