Amazon Online Assessment 2021 (OA) - Investment Max Value

Complexity of above solution is O(k*log k) (it’s independent of n).
More straightforward solution, that does not require priority queue:

from typing import List

def max_value(n: int, rounds: List[List[int]]) -> int:
    events = sorted([(i, v) for l, r, c in rounds for i, v in [(l, c), (r, -c)]], key=lambda x:x[0])
    mx = cur_v = 0
    for _, v in events:
        cur_v += v
        mx = max(mx, cur_v)
    return mx