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 is a stl vector?
how to use C++?
Name the different types of stl containers.
What is a standard template library (stl)?
i wanted to know about questions about c,c++ , which is required for placements.... im a fresher
What does stl mean in slang?
a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.
draw a flowchart that accepts two numbers and checks if the first is divisible by the second.
Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.
Who wrote stl?
In what scenario does the Logical file and Physical file being used?
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
What is a standard template library (stl)? What are the various types of stl containers?
What is stl language?
Explain stl.