C++ | O(NlogN) approach | LIS | Explaination with Comments
\nclass Solution {\n    static bool cmp(vector<int>& a, vector<int>& b){\n        if(a[0]==b[0]) return a[1] > b[1];\n        return a[0] < b[0];\n    }\npublic
```\nclass Solution {\n    static bool cmp(vector<int>& a, vector<int>& b){\n        if(a[0]==b[0]) return a[1] > b[1];\n        return a[0] < b[0];\n    }\npublic:\n    int maxEnvelopes(vector<vector<int>>& env) {\n        int n = env.size();\n        \n        // sorting by height & if we encounter same height\n        // sort by descending order of width\n        sort(env.begin(), env.end(), cmp);\n        \n        // e.g. -> env => (3,8) (4,5) (2,1) (2,6) (7,8) (5,3) (5,7)\n        // sorted version => (2,6) (2,1) (3,8) (4,5) (5,7) (5,3) (7,8)\n        \n        // Now, we only need to care about width\n        // So, as of now we only need to look upon v[i][1]\n        // [ 6, 1, 8, 5, 7, 3, 8 ]\n        \n        // Now, we can only put envolop a in envolop b another if width of a is\n        // less than width of b, or we can say we need an envolop whose width\n        // is just greater than envolop a ( height we have already handled )\n        // So, we can think of lower_bound and Longest Increasing Subsequence\n        \n        // because we have sorted all envolopes of a particular height\n        // by descending order of width, one envolope will not interfare with \n        // another envolop of same height, if we apply lower_bound\n        // i.e. first elem greater than equal to itself in lis\n        \n        vector<int> lis;\n        \n        for(int i = 0;i<env.size();i++){\n            int ele = env[i][1];\n            \n            int idx = lower_bound(lis.begin(), lis.end(), ele) - lis.begin();\n            \n            if(idx >= lis.size()) lis.push_back(ele);\n            else lis[idx] = ele;\n        }\n        \n        return lis.size();\n    }\n};\n```\nPlease upvote if the concept is clear :)
['C', 'Binary Tree']