Microsoft Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
1
of 1 vote

<pre lang="c" line="1" title="CodeMonkey31292" class="run-this">#include <stdio.h>

void RemoveCharacters(char[], char[]);

int main(void) {
char input[] = "This program removes specified characters from a string";
char remove[] = "aeiou";
RemoveCharacters(input, remove);
return 0;
}

void RemoveCharacters(char input[], char* remove)
{
int i = 0;
char bitmap[256] = {NULL};

while(remove[i])
{
bitmap[remove[i]] = 1;
i++;
}

int write = 0, curr = 0;

while(input[curr])
{
if(!bitmap[input[curr]])
{
input[write] = input[curr];
write++;
}
curr++;
}
input[write] = NULL;

printf("%s", input);
}
</pre><pre title="CodeMonkey31292" input="yes">
</pre>

- Anonymous August 08, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Since there is no restriction to use string class function, strtok() can be used.
But if not then do (crude method)

F(char* iStr, char* List)
   {
       int i = strlen(iStr); 
       int j = 0 ;
       for( k = 0 ; k < strlen(List) ; k++)    
       for( j = 0 ; j < i ; j++)
          if(iStr[j] == List[k])
          {
            iStr[j] = iStr[j+1];
            iStr[j+1] = ' ';
            j += 1;  
          }
   }
   Complexity O(strlen(List) * strlen(iStr))

- cirus February 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string removechar(string in, string remove)
{
	int i=0;
	int asciiarray[256];
	string temp;

	for (i=0; i<256; i++)
		asciiarray[i] = 0;

	for (i=0; i<remove.size(); i++)
		asciiarray[remove[i]]++;

	for (i=0; i<in.size(); i++)
		if (asciiarray[in[i]] < 1)
			temp = temp + in[i];
	
	return temp;
}

- Anonymous February 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort the list of input characters that need to be deleted. and then binary search each char in the input string.
Say if
m = length of the list of characters to be deleted.
n = number of characters in original list.

Step 1) O( nlog(m) ) for sorting
Step 2) O ( n * log(m) ) for search

Overall : O( n log (m) )

- Mac March 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Store the Input string characters in a Linked List.
2) Loop through the array of deletion chars and for those chars remove the corresponding nodes from the linked list.
3) Store the resultant linked list into another array.
4) Reverse the resultant array using swapping algorithm

- Nick March 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Store the chars to be deleted in a Hash Map. Initialize the counter i,j=0;
i: Loop though the i/p string.

If the char exists in the Hash Map, increment i
If the char does not exist in the Hash Map copy arr[j]= arr[i]; increment i,j

Put a '\0'at the jth location of the i/p string

For reversing the normal recursive code

- abhimanipal May 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void charDelete(){
	char A[]="ithss is nice  this is a very nice";
	char B[]="aeiou";
	char* delp=B;
	char* start=A;
	char* end=A;

	while(1){
		delp=B;
		while(*delp){
			if(*delp==*start){
				start++;
				*end=*start;//'$';
				delp=B;
			}
			delp++;
		}
		*end++=*start++;
		 		
		if(!*end){
			break;
		}	
	}
	
	cout << A;

};

- Anonymous December 26, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More