https://leetcode.com/problems/russian-doll-envelopes

class Solution:
    def maxEnvelopes(self, envelopes: List[List[int]]) -> int:
 
        if not envelopes: return 0
 
        envelopes.sort(key=lambda x: (x[0], -x[1]))
 
        tails = list()
 
        for _, num in envelopes:
            index = bisect.bisect_left(tails, num)
            if index == len(tails):
                tails.append(num)
            else:
                tails[index] = num
        return len(tails)