Easy to Understand Java Code || Aditya Verma Approach || LPS
Complexity\n- Time complexity:\nO(mn)\n- Space complexity:\nO(mn)\n# Code\n\nclass Solution {\n    public int minInsertions(String s) {\n        StringBuilder s
# Complexity\n- Time complexity:\nO(m*n)\n- Space complexity:\nO(m*n)\n# Code\n```\nclass Solution {\n    public int minInsertions(String s) {\n        StringBuilder s2 = new StringBuilder(s);\n        s2.reverse();\n \n        int m = s.length();\n        int n = s2.length();\n\n        int[][] t = new int[m+1][n+1];\n        \n        // Construct the LCS table\n        for(int i=1; i<=m; i++){\n            for(int j=1; j<=n; j++){\n                if(s.charAt(i-1) == s2.charAt(j-1)){\n                    t[i][j] = t[i-1][j-1]+1;\n                }\n                else{\n                    t[i][j] = Math.max(t[i-1][j], t[i][j-1]);\n                }\n            }\n        }\n\n        return m - t[m][n];\n    }\n}\n```\n![upvote.jpeg](https://assets.leetcode.com/users/images/e3394f61-a18d-4cd9-93a9-6f69a3045980_1708405567.7207563.jpeg)\n
['Java']