diff --git a/11 November Leetcode Challenge 2021/11_uniquePathsiii.cpp b/11 November Leetcode Challenge 2021/11_uniquePathsiii.cpp new file mode 100644 index 0000000..6ccfe05 --- /dev/null +++ b/11 November Leetcode Challenge 2021/11_uniquePathsiii.cpp @@ -0,0 +1,63 @@ +static int X[4] = {-1, 0, 1, 0}; +static int Y[4] = {0, -1, 0, 1}; + +class Solution { +public: + + int countPaths(vector>& grid, int x, int y, int empty, const int& m, const int& n) { + + /* + for(int i=0; i " << empty << endl << endl; + */ + + // If we reach end cell and + // All empty cells are visited, then return 1 + // Else return 0 + if(grid[x][y] == 2) { + return (empty == 0); + } + + int count = 0; // Count of possible paths from current cell {x,y} + grid[x][y] = -1; // Visit + + // Check for all valid directions + for(int k=0; k<4; k++) { + // Possible adjacent coordinates + int i = x + X[k]; + int j = y + Y[k]; + + // Valid Moves + if(i>=0 && j>=0 && i>& grid) { + + int m = grid.size(), n = grid[0].size(), empty = 1; + + pair start; + + for(int i=0; i