Amazon Interview Question
SDE-2sCountry: India
Interview Type: Written Test
int match(int * a, int m, int * b, int n)
{
if(m == 0 || n == 0)
return -1;
int flag = 0, highest = -1;
for (int i=0; i < m; i++)
{
int k = 0;
int j = (n-1);
while(1)
{
if(k <= i && j>=(n-1-i))
{
if(a[k] != b[j])
{
flag = 1;
break;
}
} else {
break;
}
k = k + 1;
j = j - 1;
}
if(flag != 1)
highest = i;
}
return highest;
}
Could you please rephrase the question in a more understandable way. Thanks!
- Dilbert Einstein May 11, 2013