Trains the technique from
LeetCode 2054Two Best Non-Overlapping EventsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A recording studio has a list of booking requests. Request i is given as events[i] = [startDay_i, endDay_i, fee_i]: it occupies the studio from startDay_i to endDay_i inclusive and pays fee_i.
The studio will accept at most two requests. Two accepted requests may not share a day, so one of them has to close strictly before the other opens: if a request closes on day d, the other one may open on day d + 1 at the earliest. Accepting a single request is allowed, and so is accepting none.
Return the largest total fee the studio can collect.
Example 1
The request paying 90 runs from day 3 to day 8, which shares days with both of the others, so it is accepted on its own and the studio collects 90.
Example 2
Both requests want day 3, so only one can be accepted, and the better fee is 20.
Example 3
The first closes on day 3 and the second opens on day 4, so both fit and the studio collects 30.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_two_events(events: list[list[int]]) -> int:public int maxTwoEvents(int[][] events)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.