Maximum Event Value with an Attendance Limit
Updated
Problem statement
Each row of events is [startDay, endDay, value]. Attending that event earns its value and occupies every integer day from startDay through endDay, inclusive. An event must be attended for its entire interval or skipped entirely.
Select at most k distinct events so that no two selected events overlap. Return the maximum sum of their values. Event order in the input is arbitrary; do not choose based on row order.
Because both endpoints are occupied, an event beginning on the day another selected event ends conflicts with it. A later selected event must start strictly after the earlier event ends. Duplicate rows represent different events, but their overlapping intervals still prevent attending them together.
Choosing no events is allowed. Return 0 when there are no events or when k is zero. Return only the maximum total value, not a chosen schedule.
Function
maxEventValue(events: int[][], k: int) → intExamples
Example 1
events = [[1,2,4],[3,4,3],[2,3,10]]k = 2return = 10The value-10 event overlaps both other events. Taking it alone beats their compatible total of 7; the limit is an upper bound, not a required count.
Example 2
events = [[1,1,5],[2,2,6],[3,3,7]]k = 2return = 13Only two events may be chosen. Select the one-day events on days 2 and 3 for a total of 6 + 7 = 13.
Example 3
events = [[1,2,7],[2,3,8]]k = 2return = 8Both events occupy day 2, so they cannot be attended together even though one starts on the other's ending day.
Constraints
0 <= events.length <= 200.0 <= k <= events.length.- Each row has exactly three integers, with
1 <= startDay <= endDay <= 10^9and1 <= value <= 10^6. - Input rows may be unsorted and may repeat. Days have no separate location, travel or resource restrictions.
- The answer is at most
200000000and fits a signed 32-bit integer.
More Snowflake Phone Screen questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
- Greedy Person-Cake Matching DistancePHONE SCREEN · Seen Nov 2026
- Tree Height After Child PromotionPHONE SCREEN · Seen Oct 2026
- Minimum StackPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Maximum Profit in Job SchedulingAmazon · PHONE SCREEN
- Query Weekly Store Opening HoursApple · PHONE SCREENApple interview questions
- Batch Point-in-Range QueriesGoogle · PHONE SCREENGoogle interview questions
- Classify Heap Addresses from a Memory SnapshotSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Unexplained Sightings Outside Flight IntervalsMobileCoin · PHONE SCREEN
- Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
- Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions
- Closed Interval Overlap QueriesNetflix · ONSITE INTERVIEWNetflix interview questions
- Maximum Team SizeExpedia · OAExpedia interview questions
- Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions