Think of Bfs ,,only don't go for dfs,,,


#1

Since we are required to find min steps,bfs will will give the solution,dfs is used when are required to find all possible path,

???one more point think greedy just push ONLY ONE highest no. we can jump without any ladder or snake u can reach,and also all posible snake and ladder

int Solution::snakeLadder(vector<vector > &A, vector<vector > &B) {
vector<vector> ludo;
ludo.clear();
ludo.resize(10,vector(10));
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
ludo[i][j]=i*10+j+1;
}
}

    for(int i=0;i<A.size();i++){
    int x=(A[i][0]-1)/10;
    int y=(A[i][0]-1)%10;
        ludo[x][y]=A[i][1];
    }
    for(int i=0;i<B.size();i++){
    int x=(B[i][0]-1)/10;
    int y=(B[i][0]-1)%10;
    ludo[x][y]=B[i][1];
    }
    queue<int> q;
    q.push(1);
    int level=0;
    
    while(!q.empty()){
        int c_size=q.size();
        for(int k=0;k<c_size;k++){
             int u =q.front();
                  q.pop();
                  if(u==100)return level;
                   bool flag=false; 
            for(int i=6;i>=1;i--){
               int x_n=(u+i-1)/10;
                int y_n=(u+i-1)%10;
               if(x_n<10&&y_n<10&&ludo[x_n][y_n]!=-1){
                   
                 if(ludo[x_n][y_n]!=u+i){q.push(ludo[x_n][y_n]);}
                 else if(!flag){
                     flag=true;
                        q.push(u+i);
                        
                    }
                    ludo[x_n][y_n]=-1;
                    
                     }
                       
         }
            
        }
        ++level;
    }
    
    
    return -1;
}