Java DP solution with comments for explanation
java\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        // sort the envelopes in ascending order based on width\n        Arrays.sort(e
```java\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        // sort the envelopes in ascending order based on width\n        Arrays.sort(envelopes, (a, b) -> a[0] - b[0]); \n        \n         // keep track of max envelopes could be Russian doll for each envelop.\n        int[] dp = new int[envelopes.length];\n        Arrays.fill(dp, 1);\n        \n        int max = 1;\n        \n        // i is the current envelop index\n        // j is the previous envelop index before i\n        for(int i = 0; i < envelopes.length; i++){\n            for(int j = 0; j < i; j++){\n                // compare the width and height of the current envelop with all the previous ones.\n                if(envelopes[j][0] < envelopes[i][0] &&\n                   envelopes[j][1] < envelopes[i][1])\n                {\n                    // update the max number of envelopes the current envelop could be Russian doll\n                    dp[i] = Math.max(dp[i], dp[j] + 1);\n                }\n            }\n            \n            max = Math.max(dp[i], max);\n        }\n        \n        return max;   \n    }\n}\n```
[]