Java - Easiest Solution [both approaches ]
Hi Family,\n\nI put the proper commen in the code Please have a look and if you liked the code Please upvote.\n\n\n// Top To Bottom\n\n\nclass Solution {\n    i
Hi Family,\n\nI put the proper commen in the code Please have a look and if you liked the code Please upvote.\n\n\n// Top To Bottom\n```\n\nclass Solution {\n    int dp[][];\n    public int minScoreTriangulation(int[] values) {\n        int n = values.length;\n        dp = new int[n][n];\n        for (int i=0;i<n;i++) Arrays.fill(dp[i],-1);\n        // call the function with i = 1, j = n-1\n        // because every time we have to take the ar[i-1] that\'s why we are starting from i = 1\n        return helper_min_score(1,n-1,values);\n    }\n    \n    private int helper_min_score(int i,int j,int values[]){\n        if (i == j) return 0;\n        \n        if (dp[i][j] != -1) return dp[i][j];\n        \n        int mini = Integer.MAX_VALUE;\n        // do partition\n    \n        for (int k=i;k<=j-1;k++){\n            int steps = values[i-1] * values[k] * values[j]\n                + helper_min_score(i,k,values)// partition 1\n                + helper_min_score(k+1,j,values); // partition 2\n            mini = Math.min(steps,mini);\n        }\n        \n        return dp[i][j] = mini;\n    }\n}\n\n```\n\n**Bottom To Top**\n```\n\npublic int minScoreTriangulation(int[] values) {\n        \n        int n = values.length;\n        int dp[][] = new int[n][n];\n        \n        // no need to initialize the dp for base case. because all the values are already 0 in dp initially\n        \n        for (int i=n-1;i>=1;i--){\n            for (int j=i+1;j<n;j++){\n                int mini = Integer.MAX_VALUE;\n                // for partition\n                for (int k=i;k<=j-1;k++){\n                    int steps = values[i-1] * values[k] * values[j] + dp[i][k] + dp[k+1][j];\n                    mini = Math.min(mini,steps);\n                }\n                dp[i][j] = mini;\n            }\n        }\n        return dp[1][n-1];\n        \n    }\n\n```\n\nThanks!!!
['Dynamic Programming', 'Memoization', 'Java']