class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
queue<pair<int,int>> que;
pair<int,int> pr;
int l1=s1.length(),l2=s2.length(),l3=s3.length(),p1=0,p2=0;
vector<bool> vb(l2+1,false);
vector<vector<bool>> v(l1+1,vb);
if(l1+l2!=l3)return false;
if(l3==0)return true;
que.push(make_pair(0,0));
v[0][0]=true;
for(int i=0;i<l3;++i){
int len=que.size();
for(int j=0;j<len;++j){
pr=que.front();
que.pop();
p1=pr.first;
p2=pr.second;
if(p1<l1&&s1[p1]==s3[i]){
if(l1==p1+1&&l2==p2)return true;
if(p1+1<=l1&&p2<=l2&&!v[p1+1][p2]){
que.push(make_pair(p1+1,p2));
v[p1+1][p2]=true;
}
}
if(p2<l2&&s2[p2]==s3[i]){
if(l1==p1&&l2==p2+1)return true;
if(p2+1<=l2&&p1<=l1&&!v[p1][p2+1]){
que.push(make_pair(p1,p2+1));
v[p1][p2+1]=true;
}
}
}
}
return false;
}
};