segments, where segments[i] = [start, end]. Segments that overlap or touch at an endpoint form one solid block: for example, [1, 3], [3, 6] and [2, 2] together cover [1, 6] with no gaps. But [1, 2] and [3, 4] are two separate blocks, because the stretch between 2 and 3 is not covered.
You must add exactly one new segment [a, b] whose length b − a is at most max_len. Return the smallest number of solid blocks you can end up with.segments=[[2, 4], [7, 9], [10, 12], [20, 25]], max_len=3 → 3
Add [4, 7]: [2, 4], [4, 7] and [7, 9] form one block. [10, 12] and [20, 25] remain apart, so there are 3 blocks.
segments=[[1, 5], [3, 8]], max_len=2 → 1
The segments already form a single block [1, 8]; the new one can go inside it.
segments=[[1, 1], [5, 5], [9, 9]], max_len=8 → 1
max_len ≤ 10⁹segments=[[2, 4], [7, 9], [10, 12], [20, 25]], max_len=3
3
Run checks the first 3 tests in your browser. Submit checks all 133 tests on the server, hidden ones included.