FACEBOOK ENGINEERING PUZZLE QUESTION WITH ITS SOLUTION
QUES:
YOU ARE GIVEN A STRING AND A VECTOR OF STRING YOU HAVE TO FIND THE POSITION IN A STRING FROM WHICH ALL THE ELEMENTS OF VECTOR STRING IS THERE..
FOR EG:
"srfhdbeabhjyeabcdkilop"
{"a" , "b" , "c" , "d" , "e" }
RETURN : 12
1
AS IN STRING THE STARTING POSITION OF THE ELEMENTS OF VECTOR IS 12
SOLUTION:
#include<iostream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<list>
#include<iterator>
#include<string>
#define vs vector<string>
#define vi vector<int>
#define pb push_back
#include<map>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<cctype>
using namespace std;
class facebook
{
public:
int pos(vs a , string b)
{
int position = 0 , position1 = 0 , count = 0 ;
for(int i= 0 ; i <a.size() ; i++)
{
position = 0;
while(position != string::npos)
{
position = b.find(a[i],position+1);
count = 1;
if(position != string::npos)
for(int j = 0 ; j < a.size() ; j++)
{
if( i != j)
{
position1 = b.find(a[j],position+1);
if(position1 != string::npos && (position1 <(position+a.size())))
{
count++;
}
}
}
if(count == a.size())
return position;
}
}
return 0;
}
};
int main()
{
facebook p;
string s = "pokoblpmanksecbda";
vs a;
a.pb("a");
a.pb("b");
a.pb("c");
a.pb("d");
a.pb("e");
int c = p.pos(a,s);
cout<<c<<endl;
cin.get();
return 0;
}
BY: SAURABH BHATIA (GNDU RC , JAL )
YOU ARE GIVEN A STRING AND A VECTOR OF STRING YOU HAVE TO FIND THE POSITION IN A STRING FROM WHICH ALL THE ELEMENTS OF VECTOR STRING IS THERE..
FOR EG:
"srfhdbeabhjyeabcdkilop"
{"a" , "b" , "c" , "d" , "e" }
RETURN : 12
1
AS IN STRING THE STARTING POSITION OF THE ELEMENTS OF VECTOR IS 12
SOLUTION:
#include<iostream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<list>
#include<iterator>
#include<string>
#define vs vector<string>
#define vi vector<int>
#define pb push_back
#include<map>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<cctype>
using namespace std;
class facebook
{
public:
int pos(vs a , string b)
{
int position = 0 , position1 = 0 , count = 0 ;
for(int i= 0 ; i <a.size() ; i++)
{
position = 0;
while(position != string::npos)
{
position = b.find(a[i],position+1);
count = 1;
if(position != string::npos)
for(int j = 0 ; j < a.size() ; j++)
{
if( i != j)
{
position1 = b.find(a[j],position+1);
if(position1 != string::npos && (position1 <(position+a.size())))
{
count++;
}
}
}
if(count == a.size())
return position;
}
}
return 0;
}
};
int main()
{
facebook p;
string s = "pokoblpmanksecbda";
vs a;
a.pb("a");
a.pb("b");
a.pb("c");
a.pb("d");
a.pb("e");
int c = p.pos(a,s);
cout<<c<<endl;
cin.get();
return 0;
}
BY: SAURABH BHATIA (GNDU RC , JAL )