Choose Valuable Events with an Attendance Limit

Quick Overview

Choose Valuable Events with an Attendance Limit. Each event in events is [startDay,endDay,value]. Attending earns its value but occupies every day from startDay through endDay, inclusive.

Choose Valuable Events with an Attendance Limit

Company: Groww

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Each event in `events` is `[startDay,endDay,value]`. Attending earns its value but occupies every day from startDay through endDay, inclusive. Attend at most `k` events without overlap and return the greatest total value. ```cpp class Solution { public: int maxValue(vector<vector<int>>& events, int k); }; ``` ### Examples **Example 1:** ```text events = [[1,3,5],[3,4,9],[5,6,4]], k = 2 Output: 13 Explanation: Attend [3,4,9] and [5,6,4]; events sharing day 3 cannot both be attended. ``` **Example 2:** ```text events = [[2,2,7],[4,4,6],[6,6,3]], k = 1 Output: 7 Explanation: The attendance limit allows only the highest-valued event. ``` ### Constraints - `1 <= k <= events.length`. - `1 <= k * events.length <= 10^6`. - `1 <= startDay <= endDay <= 10^9`. - `1 <= value <= 10^6`. ### Clarifying Questions Attendance is optional up to k, and every chosen event must be attended in full. A next event must start strictly after the preceding end day. ```hint Inspect the structure How do inclusive dates affect two events whose end and start days are equal? ``` ### Reasoning checkpoints - Respect inclusive event dates and the at-most-`k` attendance limit. - Prove maximum total value while retaining the stated endpoint and equal-date semantics. ### Optional extensions How would the recurrence change if an end day and next start day were allowed to coincide?

Overview: Choose Valuable Events with an Attendance Limit. Each event in events is [startDay,endDay,value]. Attending earns its value but occupies every day from startDay through endDay, inclusive.

Groww logo
Groww
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Each event in events is [startDay,endDay,value]. Attending earns its value but occupies every day from startDay through endDay, inclusive. Attend at most k events without overlap and return the greatest total value.

class Solution {
public:
    int maxValue(vector<vector<int>>& events, int k);
};

Examples

Example 1:

events = [[1,3,5],[3,4,9],[5,6,4]], k = 2
Output: 13
Explanation: Attend [3,4,9] and [5,6,4]; events sharing day 3 cannot both be attended.

Example 2:

events = [[2,2,7],[4,4,6],[6,6,3]], k = 1
Output: 7
Explanation: The attendance limit allows only the highest-valued event.

Constraints

  • 1 <= k <= events.length .
  • 1 <= k * events.length <= 10^6 .
  • 1 <= startDay <= endDay <= 10^9 .
  • 1 <= value <= 10^6 .

Clarifying Questions Guidance

Attendance is optional up to k, and every chosen event must be attended in full. A next event must start strictly after the preceding end day.

Reasoning checkpoints

  • Respect inclusive event dates and the at-most- k attendance limit.
  • Prove maximum total value while retaining the stated endpoint and equal-date semantics.

Optional extensions

How would the recurrence change if an end day and next start day were allowed to coincide?