Microsoft Interview Question for Software Engineer in Tests


Country: United States




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

Please provide some more data... or at least an example.

Data insufficient.

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

def string_duplicate(a,b):
set_result = set(a) and set(b)
result = ''.join(list(set_result))
return result

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

public class RemoveDuplicates
{

private static String str1;
private static String str2;
private static boolean flag=false;

private static int i;

public static void main(String [] a)
{
str1=a[0];
System.out.println("1st Input: "+ str1);
str2=a[1];
System.out.println("2nd Input: "+ str2);
new RemoveDuplicates().remover(str1,str2);

}
public void remover(String s1, String s2)
{
String token = "\\ ";
String [] fs = s1.split(token);
String [] ss = s2.split(token);
for( i=0;i<fs.length;i++)
{
if(fs[i]!=null)
{
int j=0;
do
{
while(ss[j]==null)
{
j++;
}
if(fs[i].equals(ss[j]))
{
ss[j]=null;
flag=true;

}
j++;
}while(j<ss.length);
int k=i+1;

do
{
if(k==fs.length)
break;
while(fs[k]==null)
{
k++;
if(k==fs.length) break;
}
if(k==fs.length)
break;
if(fs[i].equals(fs[k]))
{
fs[k]=null;
flag=true;
}
k++;
}while(k<fs.length);

}
if(flag)
{
fs[i]=null;
flag=false;
}

}
System.out.println ("Post Removal of Duplicate Strings ");
System.out.print ("1st String becomes: ");
for(String s: fs)
{
if(s!=null)
{
System.out.print(s + " ");
}
}
System.out.println();
System.out.print ("2nd String becomes: ");
for(String s: ss)
{
if(s!=null)
System.out.print(s + " ");
}

}


}
==============================
OUTPUT:
=======
1st Input: Subham is good boy Subham
2nd Input: Subham is not a good girl
Post Removal of Duplicate Strings
1st String becomes: boy
2nd String becomes: not a girl

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

Remove duplicates of chars as well? removed duplicates from one of the strings? What happens if you get the following 2 strings: "aa", "aa"?

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

I think it is the combination of both.no harm.actually problem becomes interesting.

- subham November 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

check_duplicate( char * S1, char * S2)
{
//Hash both strings S1 and S2 with a Key = tolower(S[i]) - 'a';
// length of String S1 : S1len = strlen(S1); S2len = strlen(S2);

for (i = 0; i < S1len; i++) {
key = tolower(S1[i]) - 'a' ;
A[ key ] = A[key] + 1;
}

for (i = 0; i < S2len; i++) {
key = tolower(S2[i]) - 'a' ;
A[ key ] = A[key] - 1;
}

// Now check the hash value for S1, find out duplicates and copy the not duplicates to target array
for (i = 0; i < S1len ; i++) {
key = tolower(S1[i]) - 'a';
if ( A[ key ] != 0) target1[i] = S1[i];
}

// Now check the hash value and find out duplicates in S2 and copy not duplicates to target2
for (i = 0; i < S2len ; i++) {
key = tolower(S2[i]) - 'a';
if ( A[ key ] != 0) target2[i] = S2[i];
}
}

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

public List<char> RemoveDupInStr(string str1, string str2)
{
List<char> Res = new List<char>();
List<char> CommonStr = new List<char>();

for (int i = 0; i < str1.Length; i++)
{
if (Res.Contains(str1[i]))
{
CommonStr.Add(str1[i]);
}
else
{
Res.Add(str1[i]);
}
}

for (int i = 0; i < str2.Length; i++)
{
if (Res.Contains(str2[i]))
{
CommonStr.Add(str1[i]);
}
else
{
Res.Add(str2[i]);
}
}
return Res;
}

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

public List<char> RemoveDupInStr(string str1, string str2)
{
List<char> Res = new List<char>();
List<char> CommonStr = new List<char>();

for (int i = 0; i < str1.Length; i++)
{
if (Res.Contains(str1[i]))
{
CommonStr.Add(str1[i]);
}
else
{
Res.Add(str1[i]);
}
}

for (int i = 0; i < str2.Length; i++)
{
if (Res.Contains(str2[i]))
{
CommonStr.Add(str1[i]);
}
else
{
Res.Add(str2[i]);
}
}
return Res;
}

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

Simple Ruby Solution in linear time

# O(n)
def remove_duplicates str1, str2
  bigger = (str1.length > str2.length ? str1 : str2).split('')
  smaller = (bigger == str1 ? str2 : str1).split('')  
    bigger.each do |c|
      if smaller.include?(c)
        bigger.delete(c)
        smaller.delete(c)
      end
    end
   smaller.join + ' ' + bigger.join
end

- VinceBarresi August 26, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

import java.util.*;

public class Recusiveley_Remove_all_Duplicates {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		String str = "";
		str = in.next();
		System.out.println("Initial String is: " + str);
		System.out.println("Removing Duplicates ...");
		String retVal ="";
		int initialLength = 0;
		int finalLength = str.length();
		retVal = str;
		/* Check if string is of length 1 or 0 */
		if(str.length() == 1 || str.length() == 0)
		{
			initialLength = finalLength;
		}
		while(initialLength != finalLength)
		{
			initialLength = finalLength;
			retVal = removeDuplicates(retVal);
			finalLength = retVal.length();
		}
		System.out.println("Final String is: " + retVal);
		in.close();
	}
	
	public static String removeDuplicates(String strVal)
	{
		int ctr = 0;
		for(int i=1; i<strVal.length(); i++)
		{
			if (strVal.toLowerCase().substring(i-1, i).equals(strVal.toLowerCase().substring(i,i+1)))
			{
				strVal = strVal.substring(0, i) + strVal.substring(i+1, strVal.length());
				ctr = 1;
				i -= 1;
			}
			else if(ctr == 1)
			{
				strVal = strVal.substring(0, i-1) + strVal.substring(i, strVal.length());
				ctr = 0;
				i -= 1;
			}
			else{}
		}
		if (ctr == 1)
		{
			strVal = strVal.substring(0, strVal.length()-1);
		}
		return strVal;
	}
}

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

#include <iostream>
#include <string>
#include <assert.h>

using namespace std;

#define S 6

int main()
{
	string n1 = "aabbb", n2 = "aaaa";

	int s1 = n1.length(), s2 = n2.length();
	int bigger = ((s1 > s2) ? s1 : s2);
	int smaller = ((s1 < s2) ? s1 : s2);

	for (int z = 0; z < bigger; ++z)
	{
		char c = n1[z];
		for (int j = 0; j < smaller; ++j)
		{
			if (c == n2[j])
			{
				n1[z] = '*';
				n2[j] = '*';
				break;
			}
		}
	}
	cout << "n1 : " << n1 << endl;
	cout << "n2 : " << n2 << endl;

	string score1 = "**bbb", score2 = "**aa";
	assert(score1==n1);
	assert(score2 == n2);

	system("pause");
	return 0;
}

- And November 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

You make this website into a easy jungle.

-Guest DS

- algos November 08, 2013 | 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