simple DP recursive solution easy to understand (1D dp)
\nps:- you can make it more faster by sorting the array of envelopes\n\n\nclass Solution {\n    static int n;\n    static int dp[];\n    public int maxEnvelopes
\nps:- you can make it more faster by sorting the array of envelopes\n\n```\nclass Solution {\n    static int n;\n    static int dp[];\n    public int maxEnvelopes(int[][] a) {\n        n=a.length;\n        dp=new int[n+1];\n        Arrays.fill(dp,-1);\n        return dfs(a,n);        \n    }\n    \n    private static int dfs(int a[][],int prev){\n        if(dp[prev]!=-1) return dp[prev];\n        \n        int x=0,y=0;\n        if(prev!=n) {\n           x=a[prev][0];\n           y=a[prev][1];\n        }\n        int ans=0;\n        for(int i=0;i<n;i++){\n            if(a[i][0]>x && a[i][1]>y){\n                ans=Math.max(ans,1+dfs(a,i));\n            }\n        }\n        return dp[prev]=ans;\n     }\n}\n```
[]