79282520

Date: 2024-12-15 14:34:05
Score: 2
Natty:
Report link

is there any way to solve this without using 3d array? "import java.util.Arrays;

public class Number_of_paths_in_a_matrix_with_k_coins {

public static long MOD = 1000000007;

public long numberOfPath(int n, int k, int [][]arr) {
    // code here
    long dp[][] = new long[n][n];

    for (long rows[] : dp){
        Arrays.fill(rows,-1);
    }

    return MemoUtil(k,n-1,n-1,arr,dp);
}

public static long MemoUtil(int k, int i, int j,int arr[][], long dp[][]){

    if(i == 0 && j == 0 )  return k == arr[0][0] ? 1 : 0L;

    if (i < 0 || j < 0 || k < 0) return 0;

    if (dp[i][j] != -1) return dp[i][j];

    long left = i > 0 && k > 0 ? MemoUtil(k - arr[i][j], i -1, j, arr,dp) %MOD : 0L;

    long right = j > 0 && k > 0 ? MemoUtil(k- arr[i][j], i, j-1, arr, dp) % MOD : 0L;

    return dp[i][j] =  (left + right) %MOD;

}

} " i tried this but this is wrong

Reasons:
  • Blacklisted phrase (1): is there any
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): is there any
  • Low reputation (1):
Posted by: piyush waghela