in this problem there give two strings let take two strings names as 's' and 't' there is chess board the string s is a one box number of the chess board and the t is anther box number in same chess board the color of both string s&t is same we need to return true other wise return false
input: s="a1" and t="c3"
output: true
explanation: a1(black color) c3(black color)
input 2: s="a1" and t="h3"
output: false
explanation: a1(black color) h3(while color)
in this we
class Solution {
public:
bool checkTwoChessboards(string s,string t) {
int n=s.size();
int m=s[1]-'0';
int k=t[1]-'0';
int dif=t[0]-s[0]-1;
if(dif%2!=0){
if(k%2!=0&&m%2!=0){
return true;
}
if(k%2==0&&m%2==0){
return true;
}
}
else{
if(dif%2==0){
if(m%2!=0&&k%2==0){
return true;
}
if(m%2==0&&k%2!=0){
return true;
}
}
}
return false;
}
};
0 Comments