Microsoft Interview Question
Software Engineer / DevelopersI defined test cases like
- Passing first string as null string
- passing second string as null string
- passing both strings as null string
- passing two different strings (non anagrams)
- passing two anagram strings, one with upper case
- passing two anagram strings containing integers
- passing two strings composed of whitespace only
- passing two correct anagram strings
- passing two correct anagram non english strings
Actually I had 25 minutes interview only, I dont know why. But before starting interview, the interviewer told me that we will be having 25 minutes interview. Before it was scheduled for 45 minutes. So these were the only 3 to 4 questions which were asked to me in interview :(
Test cases:
1. Test with known anagrams e.g. "care" and "race"
2. Test with know non-anagrams
3. Test above cases with different cases - upper case and lower case
4. Test with non dictionary words
5. Test with super long strings
6. Test with null strings
7. Test with one valid and another null string
8. Test with one char strings
9. Test with strings containing a space in between
10. Test with hyphenated words
11. Repeatedly call the function 1000 times
12. Call the method in a a multi threaded environment
13. Test with unicode
14. Test with foreign language words
15. Test with alpha-numeric strings
Code for checking if two strings are anagrams...
#include<stdio.h>
#include<stdlib.h>
void main()
{
char str1[1000], str2[1000], len1 = 0, len2 =0, a[256];
int flag = true;
printf("Enter the first string\n");
gets(str1);
printf("Enter the second striing\n");
gets(str2);
for(int i =0;i<256;i++)
a[i] = 0;
while(str1[len1] != '\0')
{
a[str1[len1]] = a[str1[len1]] + 1;
len1++;
}
while(str2[len2] != '\0')
{
a[str2[len2]] = a[str2[len2]] - 1;
len2++;
}
if((len1 != len2) || str1 == 0 || str2 == 0)
{
printf("Not an Anagram\n");
exit(0);
}
for(int i =0;i<256;i++)
if(a[i] != 0)
{
printf("Not an Anagram\n");
flag = false;
break;
}
if(flag)
printf("The two strings form an Anagram\n");
}
Altaf, I am just curious how you answered this question. I think you did pretty well on the interview. Were there any other questions that you think you might have done bad on?
- Neo May 04, 2006