[Python] 4 lines solution, explained
There is  solution, if we use similar idea of Problems 300 (Longest Increading subsequence), because we want to find the longest increasing sub-sequence.  Check
There is  solution, if we use similar idea of Problems **300** (Longest Increading subsequence), because we want to find the longest increasing sub-sequence.  Check my solution https://leetcode.com/problems/longest-increasing-subsequence/discuss/667975/Python-3-Lines-dp-with-binary-search-explained\n\nActually we can done exactly the same as in 300,\nbut when we sort we put envelopes with equal first elements [6,8], [6,7] it this opposite order\nin this way we make sure that or longest increasing subsequence works like it is and we put into our dp table the second elements. For example if we have envelopes [1,3],[3,5],[6,8],[6,7],[8,4],[9,5], we work with [3,5,8,7,4,5] and look for longest increasing sequence here.\n\n```python\nclass Solution:\n    def maxEnvelopes(self, envelopes):\n        nums = sorted(envelopes, key = lambda x: [x[0], -x[1]])    \n        dp = [10**10] * (len(nums) + 1)\n        for elem in nums: dp[bisect_left(dp, elem[1])] = elem[1]  \n        return dp.index(10**10)\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote!**
[]