Maximum Length of Pair Chain

Problem Id: 646 Difficulty: Medium


Intuition

Solution


class Solution:
    def findLongestChain(self, pairs: List[List[int]]) -> int:
        pairs.sort()
        ans = 1
        last = pairs[0][1]
        for start, end in pairs:
            if start > last:
                ans += 1
                last = end
            else:
                last = min(last, end)
        return ans