Backtracking solution that you will be expected to provide in interviews [ACCEPTED]
The O(nlogn) solution is unreasonable for an interviewer to expect. The solution below should be more than sufficient for you to pass the interview:\n\n\nclass 
The O(nlogn) solution is unreasonable for an interviewer to expect. The solution below should be more than sufficient for you to pass the interview:\n\n```\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        // Sort in increasing order by\n        // any dimension.\n        // This is an optimization.\n        if (envelopes.length == 0) return 0;\n        Arrays.sort(envelopes, (a,b) -> { \n            if (a[0] != b[0])\n                return a[0] - b[0];\n            return a[1] - b[1];\n        });\n        \n        // We will cache hits\n        HashMap<Integer, Integer> cache = new HashMap<>();\n        return maxEnvelopes(envelopes, 0, -1, cache);\n    }\n    \n    int maxEnvelopes(int[][] envelopes, int index, int prevIndex, HashMap<Integer, Integer> cache) {\n        if (index == envelopes.length)\n            return 0;\n        \n        int included = 0;\n        // included\n        if (prevIndex == -1 || (envelopes[index][0] > envelopes[prevIndex][0] \n                               && envelopes[index][1] > envelopes[prevIndex][1])){\n            if (cache.containsKey(index)){\n                included = cache.get(index);\n            } else {\n                included = 1 + maxEnvelopes(envelopes, index + 1, index, cache);\n                // Note that hits are only cached for an index\n                // when we know that the condition that prev is\n                // less than current is satisifed\n                cache.put(index, included);\n            }\n        }\n        \n        int skipped = maxEnvelopes(envelopes, index + 1, prevIndex, cache);\n        \n        return Math.max(skipped, included);\n    }\n}\n```
[]