Quick revision

bs

when problem is related to finding ≥

When the problem asks to find the first index where value target → use:

bisect.bisect_left(arr, target)

else we use bisect_right for but have to add a -1

Goal Expression
First index where arr[i] ≥ x bisect_left(arr, x)
Last index where arr[i] < x bisect_left(arr, x) - 1
First index where arr[i] > x bisect_right(arr, x)
Last index where arr[i] ≤ x bisect_right(arr, x) - 1

2d

cache = [
    [
        [-1] * (N+1) # k
        for _ in range(N) # j
    ] for _ in range(N) # i
]

For 1D lists:

For 2D lists: