• + 0 comments

    JS Solution passes all test cases

    /*
     * Complete the 'solve' function below.
     *
     * The function is expected to return an INTEGER.
     * The function accepts following parameters:
     *  1. INTEGER n
     *  2. INTEGER m
     */
    const MOD = 1E9 + 7;
    function solve(n, m) {
        // define the matrix
        const memo = new Array(n+1).fill(null).map(el => new Array(m+1).fill(1));
        
        // now the grid
        for(let i = 1; i <= n; i++) {
            for (let j = 1; j <= m; j++) {
                memo[i][j] = (memo[i][j-1] + memo[i-1][j]) % MOD;
            }
        }
        // this is our answer
        return memo[n][m]
    }