MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / helper

Function helper

CPP/array-2d/CycleDetection.cpp:6–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4vector<vector<int>> nb = {{0,1},{0,-1},{1,0},{-1,0}};
5
6bool helper(vector<vector<int>>& mat,int x,int y,int key,vector<vector<int>>& vis){
7 vis[x][y]=1;
8 bool ans=0;
9 for(int i =0; i < 4; i++){
10 int x1 = x+nb[i][0];
11 int y1 = x+nb[i][1];
12 if(x1 > -1 && x1 < mat.size() && y1 > -1 && y1 < mat[0].size() && mat[x1][y1]==key){
13 cout<<" inner loop "<<x1<<" "<<y1<<" "<<ans<<endl;
14 if( !vis[x1][y1]){
15 ans |=helper(mat,x1,y1,key,vis);
16 }
17 else if( vis[x1][y1] && (x1 != x || y1 != y)){
18 return true;
19 }
20 }
21 }
22 cout<<x<<" "<<y<<" "<<ans<<endl;
23 return ans;
24}
25
26bool solve(vector<vector<int>>& mat) {
27 vector<vector<int>> vis(mat.size(),vector<int>(mat[0].size(),0));

Callers 1

solveFunction · 0.70

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected