using namespace std;
if(front[i]==bob[j] || rear[i]==bob[j])
Your code will give wrong answer for test case such as
Here there is no ‘o’, still count will increase because you are using or operator.
Try to solve this question by counting each ‘b’ and ‘o’ individually.
You can also go for all possible cases as there are only 8 case.