package leetcode;

/**
 * https://leetcode.com/problems/out-of-boundary-paths/
 */
public class Problem576 {
    public int findPaths(int m, int n, int N, int i, int j) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem576 prob = new Problem576();
        System.out.println(prob.findPaths(2, 2, 2, 0, 0)); // 6
        System.out.println(prob.findPaths(1, 3, 3, 0, 1)); // 12
    }
}

@@ -176,32 +176,144 @@
     
-// TODO%0A        return 0
+int%5B%5D%5B%5D grid = new int%5Bm%5D%5Bn%5D;%0A        Long%5B%5D%5B%5D%5B%5D memo = new Long%5Bm%5D%5Bn%5D%5BN + 1%5D;%0A        return (int) findPaths(grid, m, n, i, j, N, memo)
 ;%0A  
@@ -326,21 +326,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -340,207 +340,942 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem576 prob = new Problem576();%0A        System.out.println(prob.findPaths(2, 2, 2, 0, 0)); // 6%0A        System.out.println(prob.findPaths(1, 3, 3, 0, 1)); // 12
+long findPaths(int%5B%5D%5B%5D grid, int maxRow, int maxCol, int row, int col, int n,%0A                                  Long%5B%5D%5B%5D%5B%5D memo) %7B%0A        if (row %3C 0 %7C%7C row %3E= maxRow %7C%7C col %3C 0 %7C%7C col %3E= maxCol) %7B%0A            return 1;%0A        %7D%0A        if (n == 0) %7B%0A            return 0;%0A        %7D%0A        if (memo%5Brow%5D%5Bcol%5D%5Bn%5D != null) %7B%0A            return memo%5Brow%5D%5Bcol%5D%5Bn%5D;%0A        %7D%0A        // up%0A        long a = findPaths(grid, maxRow, maxCol, row - 1, col, n - 1, memo) %25 (1000000000 + 7);%0A        // right%0A        long b = findPaths(grid, maxRow, maxCol, row, col + 1, n - 1, memo) %25 (1000000000 + 7);%0A        // down%0A        long c = findPaths(grid, maxRow, maxCol, row + 1, col, n - 1, memo) %25 (1000000000 + 7);%0A        // left%0A        long d = findPaths(grid, maxRow, maxCol, row, col - 1, n - 1, memo) %25 (1000000000 + 7);%0A        long total = (a + b + c + d) %25 (1000000000 + 7);%0A        memo%5Brow%5D%5Bcol%5D%5Bn%5D = total;%0A        return total;
 %0A   

Solve problem 576