My Java Solution using Sort and Longest Increasing Subsequence concept
\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        // sort as \n        // if widths are equal, sort based on the decreeasing height\
```\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        // sort as \n        // if widths are equal, sort based on the decreeasing height\n        // else carry on with width on increasing\n        Arrays.sort(envelopes, (a, b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);\n        // now just find the longest increasing subsequence of height and thats the answer\n        // it is a general dp question and that concept can be applied here\n        int length = envelopes.length;\n        int [] dp = new int [length];\n        Arrays.fill(dp, 1); // this is the minimum possible value\n        for (int i=0; i<length; i++) {\n            for (int j=0; j<i; j++) {\n                if (envelopes[i][1] > envelopes[j][1] && dp[i] < dp[j] + 1)\n                    dp[i] = dp[j] + 1;\n            }\n        }\n        int max = Integer.MIN_VALUE;\n        for (int number : dp) {\n            max = Math.max(number, max);\n        }\n        return max;\n    }\n}\n```\n\n```\n// since we sorted we can also use binary search concept for LIS\n        int result = 0;\n        for (int [] e : envelopes) {\n            int index = Arrays.binarySearch(dp, 0, result, e[1]);\n            if (index < 0) {\n                index = -(index + 1);\n            }\n            dp[index] = e[1];\n            if (index == result)\n                result += 1;\n        }\n        return result;\n```
['Sorting', 'Binary Tree', 'Java']