Yahoo Interview Question for Software Engineer / Developers






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

public void removeduplicates(LinkNode head){
HashTable hash = new HashTable();
LinkNode currentnode = head;
while(currentnode !=null){
if(hash.get(currentnode.data)==null){
hash.put(currentnode.data)
currentnode = currentnode.next;
}
else{
remove(currentnode);
}
}
}

public void removenode(LinkNode node){
node.next = node.next.next;
node.data= node.next.data;
}

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

wrong .concept is right .Because you r sending current node that has to be remove.node->data = node.next.data means y u copy the data part only but node.next=node.next.next have no meaning .check it

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

The problem is only the removeNode method. For removing, you have to remember the previous mode also. This is O(n) space and time.

- S September 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort the list using merge sort and then remove duplicates easily by traversing

Time Complexity : O(nlogn)
Space Complexity : None

- DashDash September 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you are using recursive merge-sort version, the space complexity is not constant (you are using stack space). If you know an in-place merge-sort algorithm for lists, please give us the reference. :)

- S September 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@S: excellent last line ;)

- son_of_a_thread August 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

public static void removeDuplicates(Node head) {
		
		if (head == null) {
			return;
		}
		
		Node current = head;
		
		while (current != null) {
			
			Node fast = current;
			
			while (fast.next != null) {
				
				if (current.data == fast.next.data) {
					fast.next = fast.next.next;
				}
				else {
					fast = fast.next;
				}
			}
			
			current = current.next;
		}

}

- dk December 18, 2012 | 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