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
How do I convert a stl file?
What is stl language?
What are the symptoms of stl?
What does stl mean in slang?
Is stl open source?
help me i need a c++ program which takes sequesnce of characters and outputed sequence of their token taypes, work same compiler in lexical analysis phase
Is there any error below, its a code to delete all entires from a map #include
What is stl stand for?
How is stl different from c++ standard library?
When did c++ add stl?
What does stl stand for in basketball?
write a program that will accept a number and print.its equivalent in words the maximum input number is 9999
What is stl in oop?
Is stl part of c++ standard?
In what scenario does the Logical file and Physical file being used?