Self understandable solution


#1

~…
int Solution::knight(int A, int B, int C, int D, int E, int F) {
using pi=pair<int,int>;
–C;–D;–E;–F;
int dx[]={1,-1,2,-2,1,-1,2,-2};
int dy[]={2,2,1,1,-2,-2,-1,-1};
vector<vector> vis(A,vector(B,false));
vector<vector> dis(A,vector(B,-1));
queue q;
q.push({C,D});
dis[C][D]=0;
vis[C][D]=true;

while(!q.empty()){
    pi v = q.front();
    q.pop();
    for(int i=0;i<8;i++){
        int x = v.first+dx[i];
        int y = v.second+dy[i];
        if(x<0 || x>=A || y<0 || y>=B) 
            continue;
        if(!vis[x][y]){
            q.push({x,y});
            vis[x][y]=true;
            dis[x][y]=dis[v.first][v.second]+1;
        }
    }
}
return dis[E][F];

}