Tuesday, May 27, 2008

MICROSOFT INTERVIEW QUESTIONS

Programming Questions

** Code (in pseudocode) the unix 'tr' function.

** Traverse a binary tree w/o recursion or an explicit stack. The way to do this is modify the left-right pointers in the tree structure during the traversal.

** Write some simple string-processing functions for 16-bit international char sets (trickier than you 1st think)[sic]. Not that tricky. Just use short * instead of char *.

** Reverse the elements in a linked list. -- I actually received this question. (See above)

** Open a file and read every word that contains an 'a'.

int main()
{
int count = 0;
char data[256];
FILE *f = fopen("file.txt", "r");
if (f) while (scanf("%s", data)) count += tolower(*data)=='a';
printf("%d words beginning with a\n", count);
}

** Implement strrev() in C
This handles all special cases (odd,even,zero) elegantly.

char *strrev(char *str)
{
if (str) {
char *s=str, *e = s + strlen(s);
while(s }
return str;
}

No comments: