JAVA SOLUTION | 10 Lines
\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        Arrays.sort(envelopes, (a,b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);\n      
```\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        Arrays.sort(envelopes, (a,b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);\n        int[] dp = new int[envelopes.length];\n        int ans = 0;\n        for (int[] env : envelopes) {\n            int height = env[1];\n            int left = Arrays.binarySearch(dp, 0, ans, height);\n            if (left < 0) left = -left - 1;\n            if (left == ans) ans++;\n            dp[left] = height;\n        }\n        return ans;\n    }\n}\n```
['Dynamic Programming', 'Binary Tree', 'Java']