Skip to content

2940. Find Building Where Alice and Bob Can Meet #986

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

The problem requires determining the leftmost building where Alice and Bob can meet given their starting buildings and movement rules. Each query involves finding a meeting point based on building heights. This is challenging due to the constraints on movement and the need for efficient computation.

Key Points

  1. Alice and Bob can move to another building if its height is strictly greater than the current building.
  2. For each query, find the leftmost valid meeting point, or return -1 if no such building exists.
  3. The constraints demand a solution better than a naive O(n²) approach.

Approach

  1. Observations:

    • If a == b, Alice and Bob are already at the same building.
    • If heights[a] < heights[b], …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Dec 22, 2024
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 22, 2024
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants