C++ | LIS Based | (N * logN) | With Explanation
We have to find the envelopes with fit inside each other. It is very intuitive to think that the envelopes which fit inside each other would have dimensions in 
We have to find the envelopes with fit inside each other. It is very intuitive to think that the envelopes which fit inside each other would have dimensions in ascending order. So, in the first step, we would arrange the input in increasing order by sorting them on basis of width. \n\nInput :           [[5,4],[6,4],[6,7],[2,3]]\nAfter sorting: [[2,3],[5,4],[6,4],[6,7]]\n\nAfter sorting the width, now we have to take care of the heights as well. Again, to make sure that one envelops exactly fit in another the height too has to be in increasing order. Basically now are just left with a subproblem, to find the largest increasing subsequence of height. \n\nFor the above example, we are left with finding find LIS of [3,4,4,7]. \nHere LIS would be 3 -> 4 -> 7, which gives the answer 3.\n\n**Notes:**\n1. Comparator functions have been used to handle caes when widgth are same.\n2. Please go through Leetcode 300( Longest Increasing Subsequence) in order to understand the approach used for finding LIS.\n\n\n```\nclass Solution {\npublic:\n    int maxEnvelopes(vector<vector<int>>& envelopes) {\n        sort(envelopes.begin(), envelopes.end(), [](auto a, auto b){return (a[0]==b[0])?a[1]>b[1]:a[0]<b[0];}); \n\t\t// sort in increasing order of width\n        \n        vector<vector<int>> lis;\n        auto comp=[](auto a, auto b){return (a[1]<b[1])&&(a[0]<b[0]);};\n\t\t//custom comparator for comparing lengths\n        \n        for(int i =0; i < envelopes.size(); i++){                                             // find LIS of heights \n            auto it = lower_bound(lis.begin(), lis.end(), envelopes[i], comp);\n            \n            if(it == lis.end()){\n                lis.emplace_back(envelopes[i]);\n            } else{\n                *it = envelopes[i];\n            }\n        }\n        \n        return lis.size();\n    }\n};\n```
['Binary Search', 'C', 'C++']