Most Fairs Visited
Each item of fairs is [first, last]: that fair is open on every day from first to last, both included. You can visit at most one fair per day, on any day it is open, and visiting the same fair twice does not count.
Return the largest number of fairs you can visit. The largest number is unique, so no tie rule is needed. Return 0 for an empty list.
Example 1
fairs [[1,2],[2,3],[3,4]]
returns 3
Day 1 for [1, 2], day 2 for [2, 3], day 3 for [3, 4].
Example 2
fairs [[1,2],[2,3],[3,4],[1,2]]
returns 4
Both copies of [1, 2] can be visited, one on day 1 and one on day 2, but then [2, 3] has to wait for day 3 and [3, 4] for day 4.
Constraints
0 <= len(fairs) <= 1001 <= first <= last <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.