Yahoo Interview Question for Software Engineer / Developers






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

1) Sort the first array and search for every element of second array in first using binary search
2) Create a tree of first array and search in the tree with elements from second array

Time Complexity in both the cases : O(nlogn)

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

Simply insert one array in a hashtable (O(n)), then go through all elements of the second array and lookup in the hashtable (O(m)). Time complexity would be O(n) + O(m) which is O(n) if n>=m.

- Dr. Z October 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

No need to use sorting/ hashing. It can be done in O(n) with mere array traversals.

Let us say 2 arrays A[1..Na] B[1...Nb] where Na, Nb are size of arrays and Na > Nb.

- Now start traversing both the arrays with startingIndex of A = 1+Na and that of B = 1.
- Traverse each array by 1 element and find save the first index, startI from A where the elements in A and B are equal.
- Continue traversing till all elements from A & B are equal.
- if however any mismatch occurs, reset the startI

- hjindal December 30, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

a mistake...

start A from 1 + Na - Nb and start B from 1.

And in case arrays are of same size, start both from 1.

- hjindal December 30, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

the question does not say that the arrays are sorted

- chandransuraj February 07, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

its absolutely either sorting OR hashing.. ur method is complex and cumbersome.. embrace the beautiful concepts man..

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

$arr1=array("ankush","sameer","manish","rajeev","somesh","mukul");
$arr2=array("rohit","sameer","a","b","c","mukul");
$unique_array=array();
for($i=0;$i<count($arr2);$i++)
{
for($j=0;$j<count($arr1);$j++)
{
//echo "i is ",$arr2[$i],"--","j is ",$arr1[$j],"<br/>";
if ($arr2[$i]==$arr1[$j])
{
$unique_array[]=$arr1[$j];
}
}
}

- In php October 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/// Using Sort + Uniq Method

- zombie June 17, 2013 | 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