Microsoft Interview Question for Software Engineer in Tests






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

1> Sort and Delete .T.C=O(nlogn)
Or

2> Map and rewrite .T.C=O(N) , S.C=O(N)

- Anonymous May 19, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The second solution is not preferred. Because it could happen to have different element hashed to same key. Then you got to distinguish between them.

- anon June 06, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
import java.lang.*;

class Main
{
    static String[] strs = {
        "arrays", "java", "manipulate", "java",
        "simple", "arrays", "manipulate", "java"
    };

    public static void main(String[] args) {
        print(strs, "strs");
        int num = getNumUniqueValues();
        String[] uniqueValues = new String[num];
        for(int j = 0, k = 0; j < strs.length; j++) {
            if(!containsValue(uniqueValues, strs[j]))
                uniqueValues[k++] = strs[j];
        }
        print(uniqueValues, "uniqueValues");
    }

    private static int getNumUniqueValues() {
        String[] values = new String[strs.length];
        int count = 0;
        for(int j = 0; j < strs.length; j++) {
            if(!containsValue(values, strs[j]))
                values[count++] = strs[j];
        }
        return count;
    }

    private static boolean containsValue(String[] array, String target) {
        for(int j = 0; j < array.length; j++) {
            if(array[j] != null && array[j].equals(target))
                return true;
        }
        return false;
    }

    private static void print(String[] array, String s) {
        System.out.println(s + ":");
        for(int j = 0; j < array.length; j++) {
            System.out.print(array[j]);
            if(j < array.length-1)
                System.out.print(", ");
        }
        System.out.println();
    }
}

- Gayle L McDowell May 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Gayle, i would like to modify your code, 2 methods
public static void main(String[] args) {
print(strs, "strs");
getNumUniqueValues();

}

private static void getNumUniqueValues() {
String[] values = new String[strs.length];
int count = 0;
for(int j = 0; j < strs.length; j++) {
if(!containsValue(values, strs[j]))
values[count++] = strs[j];
}

print(values, "uniqueValues");
}

there is no difference with your code except values[] array has same size as strs[] array.

- Anonymous May 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CsTest
{
class Program
{
static void Main(string[] args)
{
string[] arr = { "google", "name", "what", "google" };
remdup(arr);
}

static void remdup(string[] arr)
{
string[] unique = new string[arr.Length];
int i=0;
foreach (string str in arr)
{
if (!unique.Contains(str))
{
unique[i++] = str;
}
}
foreach (string str in unique)
Console.WriteLine(str);
}
}
}

- C# Version May 22, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

gayle are u stupid or what..u r running CC and u don't even have dis much sense that u shud give a pseudo code or general idea...instead of giving any stupid code in any specific language...

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

Construct a binary tree with the given input array and ignore the repeated numbers!

Simple!

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

The solution for an integer array

public int[] RemoveDuplicates(int[] elems)
        {
            HashSet<int> uniques = new HashSet<int>();
            foreach (int item in elems)
                uniques.Add(item);
            elems = new int[uniques.Count];
            int cnt = 0;
            foreach (var item in uniques)
                elems[cnt++] = item;
            return elems;
        }

- prolific.coder May 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am thinking isn't there a generic way to handle this? i mean how abt creating a method that takes in any type of array and return it without duplicates?

- prolific.coder May 20, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Okay I got solution that takes in any array and returns it without duplicates in C# -

public T[] RemoveDuplicates<T>(T[] elems)
        {
            HashSet<T> uniques = new HashSet<T>();
            foreach (var item in elems)
                uniques.Add(item);
            elems = new T[uniques.Count];
            int cnt = 0;
            foreach (var item in uniques)
                elems[cnt++] = item;
            return elems;
        }

- prolific.coder May 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is simple...just sort the array and remove the duplicates..O(nlogn).
Rough code:

/* returns the new size of the array*/
int remDup(int num[],int size)
{
	sort(num,size); //assume sort function
	int i=0,j=0;
	while(i<size)
	{
		if(num[i]!=num[j])
		{
			j++;
			num[j]=num[i];
		}
		i++;
	}
	return j+1;
}

- Fig Pucker May 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Oops my bad...i assumed they were integers..

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

<pre lang="java" line="1" title="CodeMonkey95817" class="run-this">import java.util.*;
import java.lang.*;

class Main
{
static String[] strs = {
"arrays", "java", "manipulate", "java",
"simple", "arrays", "manipulate", "java"
};

public static void main(String[] args) {
print(strs, "strs");
getNumUniqueValues();
}

private static void getNumUniqueValues() {
String[] values = new String[strs.length];
int count = 0;
for(int j = 0; j < strs.length; j++) {
if(!containsValue(values, strs[j]))
values[count++] = strs[j];
}
print(values, "uniqueValues");
}

private static boolean containsValue(String[] array, String target) {
for(int j = 0; j < array.length; j++) {
if(array[j] != null && array[j].equals(target))
return true;
}
return false;
}

private static void print(String[] array, String s) {
System.out.println(s + ":");
for(int j = 0; j < array.length; j++) {
System.out.print(array[j]);
if(j < array.length-1)
System.out.print(", ");
}
System.out.println();
}
}
</pre>

- Gayle L McDowell May 22, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

MS IDC makes fool of people.
People have to come to office on weekends due to workload and do night outs, no work life balance. They pay 10-20% more make people labour.

Do take the feedback from employees before joining MS.

And work is junk, all junk wor from Redmond is transferred to IDC. Ask any team, whether they design, implement products or just do porting or maintenance or make tools.

- Anonymous June 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

What the F*** is wrong with this guy? Get the hell outta here. Nobody is asking for your suggestion!!

- Micro March 12, 2011 | Flag


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