Interview Questions

Find first repeated substring in a given input string. ......

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

Find first repeated substring in a given input string. ......

Q:
Microsoft Interview Question for Software Engineer in Tests about Algorithm
Find first repeated substring in a given input string.
1. The repeated strings can overlap.
2. The repeated string should not overlap.


A:
char keyMap[10][5] = {"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
void rcsv_KeyPermute(char *keyNum, char *buf, int level, int end)
{
char *keys = keyMap[ *keyNum - '0' ];
char ch;
while( (ch = *keys++) != NULL )
{
*(buf + level) = ch;
if( level != end )
{
rcsv_KeyPermute( keyNum+1, buf, level+1, end );
}
else
{
*(buf + level + 1) = NULL;
cout << buf << " ";
}
}
}


void KeypadPermute(char *numbers)
{
int length = strlen(numbers);
char buf[100];
rcsv_KeyPermute(numbers, buf,0, length-1);
}

(Continued on next question...)

Other Interview Questions