Java short and crisp | DP with comments
\nclass Solution {\n    public int maxCoins(int[] nums) {\n        int n = nums.length;\n        if(n==0) return 0;\n        if(n==1) return nums[0];\n        \
```\nclass Solution {\n    public int maxCoins(int[] nums) {\n        int n = nums.length;\n        if(n==0) return 0;\n        if(n==1) return nums[0];\n        \n        int[][] memo = new int[n][n];\n        \n        //memo[i][j] = maximum coins obtained to brust ballons from index i to j in nums.\n        for(int len=1;len<=n;len++){\n            for(int st=0,end=st+len-1;end<n;st++,end++){\n                //Lets find maximum coins if kth balloon is bursted last\n                for(int k=st;k<=end;k++){\n                    //Kth balloon will be burst last only if,\n                    //Balloons from st to k-1 & k+1 to end are bursted before kth balloon\n                    int cost= ((k==st)?0:memo[st][k-1])+ ((k==end)?0:memo[k+1][end]);\n                    //As Kth balloon is burst last, start-1 & end+1 will be its adjacent balloons\n                    cost+=((st==0)?1:nums[st-1])*nums[k]*((end==n-1)?1:nums[end+1]);\n                    //Store maximum coins \n                    memo[st][end]=Math.max(memo[st][end],cost);\n                }\n            }\n        }\n        return memo[0][n-1];\n    }\n}\n```
[]