Maximum Length of Pair Chain
MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.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.
[[1, 2], [2, 3], [3, 4]] → 2 ([1, 2] then [3, 4])
[[1, 2], [7, 8], [4, 5]] → 3 ([1, 2] then [4, 5] then [7, 8])Constraints
1 <= pairs.length <= 1000-1000 <= left < right <= 1000