How do i pass array b1 in the function dfs, b1 is a 2D integer array used to track whether the node was visited. Sorry for the poor code readability. i want to pass it by reference as it needs to be modified by the function called recursively.Currently getting this error.
Line 33: Char 94: error: 'b1' declared as array of references of type 'int &'
void dfs(int i,int j,vector<vector<char>>& board,string word,int k,bool& yellow,int& b1[][]){
^
1 error generated.
class Solution {
public:
bool exist(vector<vector<char>>& board, string word) {
int m = board.size();
int n = board[0].size();
int b1[m][n];
list<pair<int,int>> mp;
bool yellow=false;
for(int i=0;i<board.size();i++){
for(int j=0;j<board[0].size();j++){
if(board[i][j]==word[0]){
mp.push_front({i,j});
}
}
}
for(auto itr=mp.begin();itr!=mp.end();itr++){
int i=itr->first;
int j=itr->second;
dfs(i,j,board,word,0,yellow,b1);
if(yellow==true){
return yellow;
}
memset(b1,0,sizeof(b1));
}
return yellow;
}
void dfs(int i,int j,vector<vector<char>>& board,string word,int k,bool& yellow,int& b1[][]){
int m = board.size()-1;
int n = board[0].size()-1;
b1[i][j]=1;
if(k==word.size()-1){
yellow=true;
}
if(i+1<=m && board[i+1][j]==word[k+1] &&b1[i+1][j]==0){
dfs(i+1,j,board,word,k+1,yellow,b1);
}
if(i-1>=0 && board[i-1][j]==word[k+1] &&b1[i-1][j]==0){
dfs(i-1,j,board,word,k+1,yellow,b1);
}
if(j+1<=n && board[i][j+1]==word[k+1]&& b1[i][j+1]==0){
dfs(i,j+1,board,word,k+1,yellow,b1);
}
if(j-1>=0 && board[i][j-1]==word[k+1] && b1[i][j-1]==0){
dfs(i,j-1,board,word,k+1,yellow,b1);
}
}
};