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 to making game in c++ ?
How connect plc and pc through software
Is there any error below, its a code to delete all entires from a map #include
What are the symptoms of stl?
What two types of containers does the stl provide?
write a program that will accept a number and print.its equivalent in words the maximum input number is 9999
What are the various types of stl containers?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
What is a standard template library (stl)?
In what scenario does the Logical file and Physical file being used?
write a program to convert a decimal number in to its equivalent binary number?
What is stl in oop?
what is template and type convertion
How is stl different from c++ standard library?
To modify an, existing worksheet. What steps are involved for: 1. Inserting and deleting rows and columns. 2. Printing cell formulas 3Jld displayed values 3. Using the page setup command