2940. Find Building Where Alice and Bob Can Meet
You are given a 0-indexed array
heights
of positive integers, whereheights[i]
represents the height of theith
building.If a person is in building
i
, they can move to any other buildingj
if and only ifi < j
andheights[i] < heights[j]
.You are also given another array
queries
wherequeries[i] = [ai, bi]
. On theith
query, Alice is in buildingai
while Bob is in buildingbi
.Return an array
ans
whereans[i]
is the index of the leftmost building where Alice and Bob can meet on theith
query. If Alice and Bob cannot move to a common building on queryi
, setans[i]
to-1
.
c++
1 |
|