Skip to content

1751. Maximum Number of Events That Can Be Attended II #1902

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

You must be logged in to vote

We need to maximize the sum of values obtained by attending at most k non-overlapping events. Each event has a start day, end day, and a value. The key challenge is to select events such that no two events overlap, and the sum of their values is maximized while attending at most k events.

Approach

  1. Sort Events by End Day: Sorting events by their end day helps in efficiently finding non-overlapping events. This is because, for any event, the next event that starts after the current event ends can be found using binary search.
  2. Precompute Previous Indices: For each event, precompute the index of the last event that ends before the start of the current event. This allows quick lookup during d…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Jul 8, 2025
Maintainer Author

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

topugit Jul 8, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 8, 2025
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