Microsoft Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

sort the array using heap sort which takes o (n log n). Print the unique values in o(n)

- Sunil February 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Make a hash table.

- prashantsitm February 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Algorithm:

1) Scan the string from left to right and construct the count array.
2) Again, scan the string from left to right and check for count of each
character, if you find an element who's count is 1, return it.

- prashantsitm February 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

prashantsitm, what if there are negative integers in the array? How do you build the count array?

- IHE February 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It will work for negative integers also
as we can use
if(num<0)
{
num=(num*-1)+9;
}
so the numbers who are negative wll be in array at index more than 10,while positive integers are at less than 10,and while giving output again multiply the numbers at index more than 10 with -1.
}

- Hector March 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The approach is good for sure, but how do we take care of the negative numbers in the array? Hector, your solution assumes that all the array elements lie in the range -9 to +9, which might not always be the case.

- Rocky August 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi all,
I think we can create balanced tree out of the array, like AVL tree
For ā€œNā€ elements it will take O (N log N)
While creating the Tree we can discard all the elements which are already in the Tree.

Now just go for a walk in the Tree which will take O(Z) <=O(N)

So overall complexity is O(N log N +N)
Which is O( N Log N)

- Joker February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

without using extra space?any algorithm?

- shivacherukuri February 14, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Logic- Sort the array by bubble sort Checking every last two number in the array. If they are not equal print them.. This require the same complexity as bubble sort (nlogn) and no extra space.
Program:

void PrintNonDuplicateElement(int a[])
{
int len = sizeof(a)/sizeof(a[0]);
int i,r,temp, count = 0;

for (int j= len-1;j>=1;j--)
{
i = 0;
r = j;
count++;
while(i<r)
{
if (a[i] > a[r])
{
temp = a[i];
a[i] = a[r];
a[r] = temp
}
i++;
}
if ( (count%2) == 0
&& (a[r] != a[r+1]))
{
printf("%d , %d", a[r],a[r+1]);
}
}
}

- Himanshu chauhan August 08, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can't we use a Hashmap for this ? So that we can eliminate the keys which has a count value > 1 and print out the rest, in which case we have a o(n+m)

- Shadow_ February 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the best solution for this and the time would be O(n). Also, you would only need to traverse the array once. ^_^

- noMAD April 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

hashmap implementation takes o(logn) space for insertion

- arpit July 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry, space -> time

- arpit July 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can't we use a Hashmap for this ? So that we can eliminate the keys which has a count value > 1 and print out the rest, in which case we have a o(n+m)

- Shadow_ February 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

apply quick sort on the data because its not sorted so quick sort will work perfectly fine then...and traverse the array then ...O(nlogn)

- Anonymous September 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

int arr[]=new int[]{1,2,1,3,3};
        Set s=new HashSet();
          for (int a: arr)
            {
                if(!s.add(a))
                    System.out.println("duplicate"+a);
             }

Complexity is O(n)

- Deepika Sethi February 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

To print unique values add:
System.out.println(s.size() + " distinct words: " + s);

- Deepika Sethi February 22, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You have to negate the if check.
if(s.add(a)) {
System.out.println(a);
}

- smffap March 01, 2012 | 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