public int helper(int[][] dp, int[] vals, int i, int j) {
        if (j >= vals.length)
            return 0;
        if (i > j)
            return 0;
        if (i == j) {
            dp[i][j] = vals[i];
            return dp[i][j];
        }
        // memorized
        if (dp[i][j] > 0)
            return dp[i][j];
        dp[i][j] = Math.max(vals[i] + Math.min(helper(dp, vals, i + 2, j), helper(dp, vals, i + 1, j - 1)), vals[j] + Math.min(helper(dp, vals, i + 1, j - 1), helper(dp, vals, i, j - 2)));
        return dp[i][j];
    }