• + 0 comments

    java solution using dynamic programming

        public static int solve(int n, int m) {
            int[][] dpMatrix = new int[n+1][m+1];
            for(int i = 0; i<=n; i++){
                dpMatrix[i][0] = 0;
            }
           for(int i = 0; i<=m; i++){
                dpMatrix[0][i] = 1;
            }
        // Fill the DP table
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    dpMatrix[i][j] = (dpMatrix[i - 1][j] + dpMatrix[i][j - 1]) % MOD;
                }
            }
            return dpMatrix[n][m];
        }