The Find Building Where Alice and Bob Can Meet interview question presents an array of building heights and several queries. In each query, Alice is at building and Bob is at building . They want to move to a common building such that and the height of building is strictly greater than the heights of buildings and . You need to find the leftmost such building for each query.
This "Hard" difficulty problem is used by Google and Meta to test advanced data structure knowledge. It combines several concepts: range queries, monotonic properties, and efficient searching. It evaluation your ability to optimize multiple queries over a static array using the Monotonic Stack interview pattern or a Segment Tree.
This problem is best solved using Offline Query Processing and a Monotonic Stack (or a Segment Tree/Binary Indexed Tree).
Heights: [1, 2, 1, 2, 3]. Query: Alice at 0 (h=1), Bob at 2 (h=1).
When you have many queries about "the first element to the right satisfying condition X," think about Monotonic Stacks or Segment Trees. If you can sort the queries, the "Offline" approach often simplifies the logic significantly.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Find the Number of Subarrays Where Boundary Elements Are Maximum | Hard | Solve | |
| Block Placement Queries | Hard | Solve | |
| Binary Searchable Numbers in an Unsorted Array | Medium | Solve | |
| Car Fleet II | Hard | Solve | |
| Maximum Balanced Subsequence Sum | Hard | Solve |