Problem
Each pair is [left, right] with left < right. Pair [c, d] can follow pair [a, b] when b < c, strictly. Build the longest chain of pairs where each one follows the previous. You may pick pairs in any order and skip any you like. Return the chain's length.
Example 1
- Input
- [[1, 2], [2, 3], [3, 4]]
- Output
- 2
- Why
- [1, 2] then [3, 4]
Example 2
- Input
- [[1, 2], [7, 8], [4, 5]]
- Output
- 3
- Why
- [1, 2] then [4, 5] then [7, 8]
Constraints
1 <= pairs.length <= 1000-1000 <= left < right <= 1000