#3414

Maximum Score of Non-overlapping Intervals

international master · 1960 · lc hard +32 · 31.1% accepted · 56 likes · top 9%

Description

You are given a 2D integer array intervals, where intervals[i] = [li, ri, weighti]. Interval i spans positions li to ri and has weight weighti. Select up to 4 non-overlapping intervals to maximize their total weight.

Return the lexicographically smallest array of at most 4 indices achieving the maximum score.

Two intervals are non-overlapping only if they share no points; intervals sharing an endpoint are considered overlapping.

Code

1
2
3