{"size": 902, "ext": "js", "max_stars_repo_path": "leetcodeProblems/javascript/minPathSum.js", "max_stars_repo_name": "adrianme213/codingInterviewPracticeQuestions", "max_stars_repo_stars_event_min_datetime": "2021-07-12T10:08:59.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-12T10:08:59.000Z", "max_issues_repo_path": "leetcodeProblems/javascript/minPathSum.js", "max_issues_repo_name": "adrianme213/codingInterviewPracticeQuestions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "leetcodeProblems/javascript/minPathSum.js", "max_forks_repo_name": "adrianme213/codingInterviewPracticeQuestions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.1034482759, "max_line_length": 83, "alphanum_fraction": 0.5354767184}
var minPathSum = function(grid) {
    var mySolution = [];
    // initialize array
    for (let ii = 0; ii < grid.length; ii++) {
    	mySolution.push([]);
    }

    // initialize first row
    mySolution[0][0] = grid[0][0];
    for (let ii = 1; ii < grid[0].length; ii++) {
    	// top row
    	mySolution[0][ii] = mySolution[0][ii-1] + grid[0][ii];
    }
    for (let ii = 1; ii < grid.length; ii++) {
        // left column
        mySolution[ii][0] = mySolution[ii-1][0] + grid[ii][0];
    }

    // start at grid[1][1] and add top or left minimum value until reach the end.
    for (let ii = 1; ii < grid[0].length; ii++) {
        for (let jj = 1; jj < grid.length; jj++) {
            var theMinOfTwo = Math.min(mySolution[jj-1][ii], mySolution[jj][ii-1]);
            mySolution[jj][ii] = theMinOfTwo + grid[jj][ii];
        }
    }

    return mySolution[grid.length-1][grid[0].length-1];
};
