Sort by

recency

|

21 Discussions

|

  • + 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]
    }
    
  • + 0 comments

    JS Solution, using Dynamic Programming, 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(0));
        // first row
        for (let i=1; i<=m; i++) memo[0][i] = 1;
        // first col
        for (let i=1; i<=n; i++) memo[i][0] = 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]
    }
    
  • + 0 comments

    This passes all the test cases:

    from math import comb
    
    def solve(n, m):
        return comb(n+m, m)%(10**9 + 7)
    
  • + 0 comments

    Hi java coder: https://github.com/AmitRoy3370/HackerRank/blob/master/Merge%20List

  • + 0 comments

    BigInteger all the way