Yahoo Interview Question for Software Engineer / Developers






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

simply use a hash table and solve it O(n+m).
int[] union
for i=1 to n
if(H.find(A[i])!=true)
H.put(A[i]),union.append(A[i]);
end
end
for i=1 to m
if(H.find(B[i])!=true)
H.put(B[i]),union.append(B[i]);

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

simply use a hash table and solve it O(n+m).
int[] union
for i=1 to n
if(H.find(A[i])!=true)
H.put(A[i]),union.append(A[i]);
end
end
for i=1 to m
if(H.find(B[i])!=true)
H.put(B[i]),union.append(B[i]);
return union

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

simply use a hash table and solve it O(n+m).
int[] union
for i=1 to n
if(H.find(A[i])!=true)
H.put(A[i]),union.append(A[i]);
end
end
for i=1 to m
if(H.find(B[i])!=true)
H.put(B[i]),union.append(B[i]);
end
end
return union

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

Make a BST of set A's elements and then try to find B's elements in it. If any of B's element is not found then insert it. Thus found BST is (A U B).

- sumit September 18, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort the sets if you are not able to have an hash table.
Them merge them if you get equal numbers eliminate one of them in the new set. That is all.

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

BST is a good way

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

Use rooted tree and solve it in O(n+m).

- Riyad Parvez January 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Simple use another HashSet and keep adding the element of both the array, At the end you will have all the elements of both the array without repetition.
Time Complexity O(max(n,m)), Space O(n+m)

- Abhishek Kothari June 03, 2014 | 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