Highly Intutive and Using Comparator
\nclass Solution {\n\tpublic int maxEnvelopes(int[][] envelopes) {\n\t\tint n = envelopes.length;\n\t\tArrays.sort(envelopes, new Comparator<int[]>() {\n\t\t\tp
```\nclass Solution {\n\tpublic int maxEnvelopes(int[][] envelopes) {\n\t\tint n = envelopes.length;\n\t\tArrays.sort(envelopes, new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\treturn a[0] == b[0] ? b[1] - a[1] : a[0] - b[0];\n\t\t\t}\n\t\t});\n\t\tint[] height = new int[n];\n\t\tfor (int i = 0; i < n; i++)\n\t\t\theight[i] = envelopes[i][1];\n\n\t\treturn lengthOfLIS(height);\n\t}\n\n\tpublic int lengthOfLIS(int[] arr) {\n\t\tint piles = 0, n = arr.length;\n\t\tint[] top = new int[n];\n\t\tfor (int i = 0; i < n; i++) {\n\t\t\tint poker = arr[i];\n\t\t\tint left = 0, right = piles;\n\t\t\twhile (left < right) {\n\t\t\t\tint mid = (left + right) / 2;\n\t\t\t\tif (top[mid] >= poker)\n\t\t\t\t\tright = mid;\n\t\t\t\telse\n\t\t\t\t\tleft = mid + 1;\n\t\t\t}\n\t\t\tif (left == piles)\n\t\t\t\tpiles++;\n\t\t\ttop[left] = poker;\n\t\t}\n\t\treturn piles;\n\t}\n}\n```
['Java']