Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all the elements that are there in B. But B has one missing element. Write a function that takes arrays , A & B as imnput and finds the missing element in most optised manner .
Answer Posted / rajesh
<?php
function findMissing($a1, $a2) {
for($i= 0; $i<count($a1); $i++) {
$found = false;
for($j= 0; $j<count($a2); $j++) {
if($a1[$i] == $a2[$j] ) {
$found = true;
break;
}
}
if($found == false) {
break;
}
}
return $a1[$i];
}
$element = findMissing(array(1, 3, 5, 7, 9, 10, 6), array(1, 3, 7, 9, 10, 6));
echo "Missing Element in second Array : " . $element;
?>
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What are the various types of stl containers?
How stl is different from the c++ standard library?
Name the different types of stl containers.
please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html
Who created stl?
Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister
What do stl stand for?
Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.
What two types of containers does the stl provide?
What is stl in c++ with example?
i wanted to know about questions about c,c++ , which is required for placements.... im a fresher
Is stl part of c++ standard?
Can we use stl in coding interviews?
Why should a c++ programmer be interested in stl?
Is stl open source?