Skip to content

2054. Two Best Non-Overlapping Events #928

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

You must be logged in to vote

We can use the following approach:

Approach

  1. Sort Events by End Time:

    • Sorting helps us efficiently find non-overlapping events using binary search.
  2. Binary Search for Non-Overlapping Events:

    • Use binary search to find the latest event that ends before the current event's start time. This ensures non-overlapping.
  3. Dynamic Programming with Max Tracking:

    • While iterating through the sorted events, maintain the maximum value of events up to the current one. This allows us to quickly compute the maximum sum of two events.
  4. Iterate and Calculate the Maximum Sum:

    • For each event, calculate the possible sum using:
      • Only the current event.
      • The current event combined with the best non-overl…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Dec 8, 2024
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Dec 8, 2024
Maintainer Author

Answer selected by basharul-siddike
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 medium Difficulty
2 participants