Microsoft Interview Question for Interns


Country: India
Interview Type: In-Person




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

try it soon it will help for your micro interview

- oxymoron November 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string.h>
#include<malloc.h>
using namespace std;
void remove_alternate_dup(char* str)
{
int len=strlen(str);
bool *h=(bool*)calloc(sizeof(bool),len);
int tail=0;
int i=0;
int flag_space=0;
while(i<len)
{
if((str[i]>=65&&str[i]<=90)||(str[i]>=97&&str[i]<=122))
{
if(str[i]>=65&&str[i]<=90)
{
if(h[str[i]]==0||h[str[i]+32]==0)
{
h[str[i]]=1;
h[str[i]+32]=1;
str[tail++]=str[i++];
}
else if(h[str[i]]==1||h[str[i]+32]==1)
{
h[str[i]]=0;
h[str[i]+32]=0;
i++;

}

}
else if(str[i]>=97&&str[i]<=122)
{
if(h[str[i]]==0||h[str[i]-32]==0)
{
h[str[i]]=1;
h[str[i]-32]=1;
str[tail++]=str[i++];
}
else if(h[str[i]]==1||h[str[i]-32]==1)
{
h[str[i]]=0;
h[str[i]-32]=0;
i++;

}
}

}
else
{
if(flag_space==0)
{
str[tail++]=str[i++];
flag_space=1;
}
else
{
flag_space=0;
i++;
}



}

}

str[tail]='\0';
}
int main()
{
char str[]="Today is the day";
remove_alternate_dup(str);
cout<<str<<endl;
return 0;
}

- Neta_Ji November 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Please find below java implementation:

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class RemoveDuplicatesFromString {
	public static void main(String[] args) {
		String inputString = "";
		String outputString = "";
		Map<Character, Integer> dictionary = new HashMap<Character, Integer>();
		Scanner sc = new Scanner(System.in);
		System.out.println("Please Ente String:");
		inputString = sc.nextLine();
		for (int i = 0; i < inputString.length(); i++) {
			if (!dictionary.containsKey(inputString.toLowerCase().charAt(i))) {
				dictionary.put(inputString.toLowerCase().charAt(i), 1);
				outputString += inputString.charAt(i);
			}
		}
		System.out.println(outputString);
	}
}

- kedarsdixit November 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you can optimized your code if you use char [] or StringBuilder but It works.
Here are some test cases:
Base case:
1) "abcabc"
2) "abcABC"
3) "abc"
4) ""
5) NULL
6) "aaaaaaaaaa"
7) "aAaAaAaAaAaA"
8) "A very big string which length is bigger than INTEGER.MAX_VALUE ( If possible )"
9) "123123"
10) "!"#$#%&/()?=)(/&%$#"!°¡ "
11) " " (spaces)
12) Is it thread safe? HashMap is not thread Safe, so we can do something to break it maybe
13)

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> November 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

BY THE WAY! You implementation is wrong!

This is about deleting ALTERNATE duplicates, not all the duplicates.
So for Example:
Input: "aaAaaAAA"
Output: "aAaA"

Check my code:

void removeDuplicates(char str[],int n){
	int letters [256];
	int i = 0;
	int index=0;
	for(i=0;i<256;i++)
		letters[i]=0;
	for(i=0; i<n;i++){
		char lowerCase = str[i];
		if(str[i] >= 65 && str[i] <= 90){
			lowerCase +=('a' - 'A');
		}
		if(letters[lowerCase] == 0){
			letters[lowerCase]++;
			str[index++]=str[i];
		}else{
			letters[lowerCase]--; // We want to Alternate
		}
	}
	while(index < i){
		str[index++]= 0;
	}
}

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> November 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void removeALTERNATEDuplicates(char str[],int n){
	int letters [256];
	int i = 0;
	int index=0;
	for(i=0;i<256;i++)
		letters[i]=0;
	for(i=0; i<n;i++){
		char lowerCase = str[i];
		if(str[i] >= 65 && str[i] <= 90){
			lowerCase +=('a' - 'A');
		}
		if(letters[lowerCase] == 0){
			letters[lowerCase]++;
			str[index++]=str[i];
		}else{
			letters[lowerCase]--; // We want to Alternate
		}
	}
	while(index < i){
		str[index++]= 0;
	}
}

- .·´¯`·.´¯`·.¸¸.·´¯`·.¸><(((º> November 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

boolean check =false; //"";
		 String word = "Hello World";
		 HashSet<Character>s = new HashSet<Character>();
		 String result = "";
		 for(int i = 0 ; i < word.length();++i)
		 {
			 check =s.add(word.charAt(i));
			 if(check==true)
			 {
				 result += word.charAt(i);
			 }
		 }
		 System.out.println(result);

- Anonymous April 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

my code is up (anonymous)
and it is modified

public  String dup(String word)
	{
		boolean check =false; //"";
		 HashSet<Character>s = new HashSet<Character>();
		 String result = "";
		 for(int i = 0 ; i < word.length();++i)
		 {
			 check =s.add(word.charAt(i));
			 if(check==true)
			 {
				 result += word.charAt(i);
			 }
		 }
		 return result;
	}

- waledsalah2005 April 18, 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