Microsoft Interview Question for Software Engineer / Developers






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

you could do it with a hashtable.

- bogdan.cebere October 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Use recursive and hash table.
recursive to the end of the linklist, fill all the hash table with the count of each index in the linklist, then back tracking ,during backtracking ,
1) for each element, mark the element on the hash table to be negative ,
2)if you seen a index with a value of negative number, then remove it

-----this is based on the understanding that one node will have only one duplicated at most ;
also I assume the value in linklist is in a limited range

- Charles January 01, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i think if extra space is acceptable. use hashset.
O(n)

- gao October 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

he cannot explain, because he doesnt know either

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

if you xor the same numbers you will get a zero.

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

seriously? thats your answer?

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

only even number of times if a number is repeated then xoring will return zero , if it is odd number of times then it wont be zero , using hash table would be fine

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

Do it with hash table.

- aggarwal.richa January 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static List<Node> getDupNodes(Node n)
{
HashSet<Node> h = new HashSet<Node>();
while (n.next != null)
{
if ((n.data % 2 != 0) && (h.Contains(n)))
{
//do nothing///
}
else
{
h.Add(n);
}
n = n.next;
}
return h.ToList<Node>();

}

- kk March 28, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@to the people suggesting for hash table

range is not given how much big table will u take
foe eg list conatains
1 2 3 4 2 5 6 5 7 8 10000 u will need an array of 1000 size

- Learn Android: http://learnandroideasily.blogspot.in/ June 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry 10000 size

- Learn Android: http://learnandroideasily.blogspot.in/ June 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

You could ask the interviewer about the range of numbers. If range of numbers are given then you can use a bitmap to record occurrences. Usually if range is small then there is a constant memory space required which is not the case with hash tables. Hence you can have a solution that is technically O(n) in both space and time complexity.

- Ashish Kaila June 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey6518" class="run-this">package com.DataStructures;

import java.util.HashMap;

public class RemoveDuplicateFromLinkedList {

HashMap<Integer, Character > map=new HashMap<Integer, Character>();

public void removeDuplicates(LinkedListNodeInt current){

LinkedListNodeInt previous=null;
while(current!=null){
if(map.containsKey(current.value)){
if(current.value%2!=0)
previous.link=current.link;
else
previous=current;
}
else{
map.put(current.value,' ');
previous=current;
}
current=current.link;
}
}
public static void main(String args[]){
RemoveDuplicateFromLinkedList obj=new RemoveDuplicateFromLinkedList();
LinkedListNodeInt node=new LinkedListNodeInt();
node.insert(1);
node.insert(2);
node.insert(5);
node.insert(60);
node.insert(3);
node.insert(5);
node.insert(60);
node.insert(5);
obj.removeDuplicates(node.link);
node.traverse();
}
}
</pre><pre title="CodeMonkey6518" input="yes">
</pre>

- akash.kotadiya2000@gmail.com June 26, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public LinkedList<Integer> deleteDuplicates(LinkedList<Integer> duplicateList)
{
LinkedList<Integer> nonduplicateList = new LinkedList<Integer>();
HashSet<Integer> distinctList = new HashSet<Integer>();

for(Integer i : duplicateList )
{
if((i%2 == 0))
{
nonduplicateList.add(i);
}
else if(!nonduplicateList.contains(i))
{
distinctList.add(i);
nonduplicateList.add(i);
}
}

return nonduplicateList;
}

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

public LinkedList<Integer> deleteDuplicates(LinkedList<Integer> duplicateList)
	{
		LinkedList<Integer> nonduplicateList = new LinkedList<Integer>();
		HashSet<Integer>  distinctList = new HashSet<Integer>();
		
		for(Integer i : duplicateList )
		{
			if((i%2 == 0))
			{
				nonduplicateList.add(i);
			}			
			else if(!nonduplicateList.contains(i))
			{
				distinctList.add(i);
				nonduplicateList.add(i);
			}
		}
				
		return nonduplicateList;
	}

- pat August 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

use a xor process on all the data

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

How does XOR solution fit to this , can explain ?

- sachin323 October 31, 2010 | 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