Python O(nlogn) O(n) solution, beats 97%, with explanation
class Solution(object):\n        def maxEnvelopes(self, envs):\n            def liss(envs):\n                def lmip(envs, tails, k):\n                    b, e
    class Solution(object):\n        def maxEnvelopes(self, envs):\n            def liss(envs):\n                def lmip(envs, tails, k):\n                    b, e = 0, len(tails) - 1\n                    while b <= e:\n                        m = (b + e) >> 1\n                        if envs[tails[m]][1] >= k[1]:\n                            e = m - 1\n                        else:\n                            b = m + 1\n                    return b\n                \n                tails = []\n                for i, env in enumerate(envs):\n                    idx = lmip(envs, tails, env)\n                    if idx >= len(tails):\n                        tails.append(i)\n                    else:\n                        tails[idx] = i\n                return len(tails)\n            \n            \n            def f(x, y):\n                return -1 if (x[0] < y[0] or x[0] == y[0] and x[1] > y[1]) else 1\n                \n            envs.sort(cmp=f)\n            return liss(envs)\n\n    # Runtime: 100ms\n\nThe idea is to order the envelopes and then calculate the longest increasing subsequence (LISS). We first sort the envelopes by width, and we also make sure that when the width is the same, the envelope with greater height comes first. Why? This makes sure that when we calculate the LISS, we don't have a case such as [3, 4] [3, 5] (we could increase the LISS but this would be wrong as the width is the same. It can't happen when [3, 5] comes first in the ordering).\n\nWe could calculate the LISS using the standard DP algorithm (quadratic runtime), but we can just use the tails array method with a twist: we store the index of the tail, and we do leftmost insertion point as usual to find the right index in `nlogn` time. Why not rightmost? Think about the case [1, 1], [1, 1], [1, 1].
['Binary Tree', 'Python']