Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

void c15321835RemoeAI(char s[]) {
    int p = 0, i = 0;
    for (i = 0; s[i]!=0; i++) {
        if (s[i] == 'a' || s[i] == 'i')
            p++;
        else
            s[i - p] = s[i];
    }
    s[i - p] = 0;
    cout << s;
}

- isandesh7 January 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Gud One

- amit February 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 votes

this is a beautiful solution

- sdubey March 20, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

does it work for string ="anpi"

- deep July 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How do you do in Java

- AVK November 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

static void RemoveChars(ref string s, char c)
{
	int index;
	while (( index = s.IndexOf(c)) >= 0)
	{
		s = s.Substring(0, index) + s.Substring(index + 1);
	}			
}
static void ModifyString(string s)
{
	RemoveChars(ref s, 'A');
	RemoveChars(ref s, 'L');
	Console.WriteLine(s);
}

- S.Abakumoff January 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.HashSet;
import java.util.Set;

public class RemoveChar {

	public static void remove(char[] string, Set<Character> set) {
		int currPtr = 0;
		int ptr = 0;
		for(currPtr = 0;currPtr < string.length;currPtr++){
			if(set.contains(string[currPtr])){
				ptr++;
			}else{
				string[currPtr - ptr] = string[currPtr];
			}
		}
		while(ptr > 1){
			string[currPtr - ptr] = 0;
			ptr--;
		}
		string[currPtr - ptr] = 0;
	}

	public static void main(String[] args) {
		Set<Character> set = new HashSet<Character>();
		set.add('a');
		set.add('i');
//		char[] string = { 'a', 'b', 'c', 'i', 'a', 'b', 'c' };
		char[] string = { 'a', 'i', 'a'};
		remove(string, set);
		for (char c : string) {
			System.out.print(c + " ");
		}
	}

}

- Kevin February 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public String removeOccurence(String word, char[] letters){
        int pivot1 = 0;
        int pivot2 = 0;
        char[]  words = word.toCharArray();
        int length = words.length-1;
        while (pivot1 <= length){
            while (pivot1 <= length && (!isContainsLetter(words[pivot1], letters))){
                words[pivot2] = words[pivot1];
                pivot2++;
                pivot1++;
            }
            while (pivot1 <= length && (isContainsLetter(words[pivot1],letters))){
                pivot1++;
            }
        }
        String result =  String.copyValueOf(words);
        return result.substring(0,pivot2);
    }

    public boolean isContainsLetter(char letter, char[] letters){
        int i = 0;
        while (i <= letters.length - 1){
            if (letters[i] == letter){
                return true;
            }
            i++;
        }
        return false;

}

- m3th0d.itbhu April 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Algorithm: Keep two pointers for this work
While(string != '\0') {
1. "GOING" is the string.Initially both will point to 'G'.
2. Move first pointer if it 'a' or 'i'.If it is not then don't move first pointer.
3. Copy first pointer data in second pointer and increment second pointer.
return second pointer.
}

char * string_removal(char *string, char a, char i)
{
	char *first = string;
	char *second = string;
	char *temp = string;

	while(*string != '\0') {
		if(*first == a || *first == i)			
			first++;
		else {
			*second = *first++;
			second++;
		}
		string++;
	}
	*second = '\0';
	return temp;
}

- aka January 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
char str[]="vhjabsaaiibnca";
int len=strlen(str);
int start=0;
for(int i=0;i<len;)
{
if(str[i]=='a' || str[i]=='i')
i++;
else
swap(str[i++],str[start++]);
}
memset(str+start,'\0',len-start);
getchar();
return 0;
}

- Anonymous January 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

char* remove_ai_occurence(char* str) {
unsigned int len = strlen(str);
char* nextHolePtr = NULL;
for (unsigned int i = 0; i < len; i++) {
if (str[i] == 'i' || str[i] == 'a') {
if (!nextHolePtr)
nextHolePtr = str + i;
} else if (nextHolePtr) {
//if the nextHolePtr is non-null, fill the whole
nextHolePtr[0] = str[i];
nextHolePtr++;
}
}
if (nextHolePtr)
*nextHolePtr = '\0';
return str;
}

- Qi February 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void Replaces(char* str)
{
	int it =0;
	int in=0;
	while( str[it] != '\0')
	{
		if((str[it] != 'A')&&(str[it] != 'L'))
		{
			if( it != in)
				str[in] = str[it];
			in++;it++;
		}
		else
		{
			it++;
		}
	}
	str[in] = '\0';
	
}

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

public class RemoveLetters
{

public static void main(String[] args)
{
String s = null ;
System.out.println("Enter the first string\n");
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
s = br.readLine();
}
catch(Exception e){}
char arr[] = s.toCharArray();
int len = s.length();
int index1 = 0;
for (int i=0; i<len; i++)
{

if(arr[i] != 'i' && arr[i] != 'l')
{
arr[index1] = arr[i];
index1++;
}
}

arr[index1] = 0;

for (int i=0; arr[i] != 0 ; i++)
System.out.print(arr[i]);

}

}

- Twinkling star March 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

pls suggest some method to reduce its complexity.......
#include<stdio.h>
int main()
{
char str[100];
int i=0,j;
printf("enter the string:\n");
scanf("%s",str);
while(str[i++])
{
if(str[i]=='A'||str[i]=='I'||str[i]=='a'||str[i]=='i')
{
j=i;
while(str[j]){
str[j]=str[j+1];j++;}
i--;
}
}
printf("thus the resultant string is:%s",str);
return 0;
}

- ram rs March 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void removeA(char* str)
{
for(int i=0, j=0; str[i]; i++, j++)
{
while (str[j] == 'A') j ++;
str[i] = str[j];
}
}

- Al May 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void removeAI(char s[])
{
char *p = s;
for(int i=0;i<strlen(s);)
{
if(*p=='A'|| *p=='I')
{
p++;
}
else {
s[i]=*p;
p++;
i++;
}
}
}

- crickmasterdhawal June 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void remove_chars(char* str)
{
	int freq = 0;
	for(int i = 0; str[i] !' ='\0'; ++i)
	{
		if(str[i] == 'a' || str[i] == 'A' || str[i] == 'i' || str[i] == 'I')
		{
			++freq;
		}
		else
		{
			str[i - freq] = str[i];
		}	
	}

	str[i - freq] = '\'0';
}

- Anonymous July 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

static void RemoveAandI(char [] s)
{
int index = 0;
for (int i = 0; i < s.Length; i++)
{
if (s[i] != 'a' && s[i] != 'i')
{
if (i > index)
{
s[index++] = s[i];
}
}

}
if (index == 0 && (s[index] == 'a' || s[index] == 'i'))
{
throw new Exception("Unable to find char other then 'a' and 'i'");
}

Console.WriteLine(s);
}

- Imran Arshad October 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int removeCharInPlace(char[] str){
		int lo = 0, hi = str.length - 1, len = str.length;
		while(lo < hi){
			while(lo < len && (str[lo] != 'A' && str[lo] != 'I')){
				lo ++;
			}
			
			if(lo >= len || lo > hi){
				break;
			}
			
			while(hi >= 0 && (str[hi] == 'A' || str[hi] == 'I')){
				len --;
				hi --;
			}
			
			if(lo >= len || lo > hi){
				break;
			}
			
			swapTwoChar(str, lo, hi);
		}
		return len;
	}
	
	public static void swapTwoChar(char[] str, int from, int to){
		char tmpChar = str[from];
		str[from] = str[to];
		str[to] = tmpChar;
	}

- Anonymous December 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public string CharRemovalForString(string inputString, Char removalChar)
        {
            int p = 0;
            Char[] inputCharArray = inputString.ToCharArray();
            for (int i = 0; i < inputCharArray.Length; i++)
            {
                if (inputCharArray[i] == removalChar)
                {
                    p++;
                }
                else
                {
                    inputCharArray[i - p] = inputCharArray[i];
                }
            }

            for (int j = inputCharArray.Length - 1; j > inputCharArray.Length - p - 1; j--)
            {
                inputCharArray[j] = ' ';
            }
            return new string(inputCharArray);
        }

- G Kumar March 09, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void RemoveA_I(char* str)
{
	auto copyCounter = 0;
	auto strItr = 0;
	while (str[strItr] != '\0')
	{
		while (str[strItr+copyCounter] == 'A' || str[strItr+copyCounter] == 'I')
		{
			copyCounter++;
		}
		if (copyCounter>0)
		{
			str[strItr] = str[strItr + copyCounter];
		}
		strItr++;
	}
}

- soni.anshul93 February 15, 2016 | 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