Longest Painted Stretch
Each item of strokes is [left, right] with left < right: one brush stroke paints a long fence from position left to position right. Strokes that overlap or touch (one ends exactly where the next begins) join into a single painted stretch. Return the length of the longest painted stretch, or 0 if strokes is empty. The strokes are in no particular order.
Example 1
strokes [[1,4],[2,6],[8,10]]
returns 5
[1, 4] and [2, 6] overlap and form the stretch from 1 to 6, length 5; [8, 10] is a separate stretch of length 2.
Example 2
strokes [[0,5],[5,10]]
returns 10
[0, 5] and [5, 10] touch at 5, so they form one stretch from 0 to 10.
Constraints
0 <= len(strokes) <= 1000 <= left < right <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.