Python LIS based approach
The prerequisite for this problem is to understand and solve Longest Increasing Subsequence. So if you are familiar with LIS and have solved it, the difficulty 
The prerequisite for this problem is to understand and solve [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/). So if you are familiar with LIS and have solved it, the difficulty of this problem is reduced.\n\nNow, before we can start implementing LIS for this problem, we need to determine the sort order of the input `envelopes`.  You can read this post which explains how the sort order is determined ->  [Explanation on which sort order to choose](https://leetcode.com/problems/russian-doll-envelopes/discuss/2071477/Best-Explanation-with-Pictures)\n\n**Time - O(nlogn)** - Time required for sorting and performing LIS\n**Space - O(n)** - space required for `res`.\n\n```\nclass Solution:\n    def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n        envelopes.sort(key=lambda x: (x[0], -x[1]))\n        \n        res = []\t\t\n\t\t# Perform LIS\n        for _, h in envelopes:\n            l,r=0,len(res)-1\n\t\t\t# find the insertion point in the Sort order\n            while l <= r:\n                mid=(l+r)>>1\n                if res[mid]>=h:\n                    r=mid-1\n                else:\n                    l=mid+1        \n            idx = l\n            if idx == len(res):\n                res.append(h)\n            else:\n                res[idx]=h\n        return len(res)\n                                               \n```\n\nWe can make the above code more concise by using a python library `bisect_left` to locate the insertion point in the sort order. \n\n```\nclass Solution:\n    def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n        envelopes.sort(key=lambda x: (x[0], -x[1]))        \n        res = []\n        for _, h in envelopes:\n            idx = bisect_left(res, h)\n            if idx == len(res):\n                res.append(h)\n            else:\n                res[idx]=h\n        return len(res)                                                                                              \n```\n\n---\n\n***Please upvote if you find it useful***
['Python', 'Python3']