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


Please Help Members By Posting Answers For Below Questions

What does stl stand for in basketball?

836


What is stl stack?

859


sir please send me bpcl previous question papers

2150


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

2131


Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A.Explain how a pointer to function can be declared in C++? B.List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header (“Include”) Files.

2533


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

2360


What is stl stand for?

936


Name the different types of stl containers.

897


What are the different types of stl containers?

862


Who wrote stl?

884


When did c++ add stl?

942


Can we use stl in coding interviews?

1544


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

1995


How is stl different from c++ standard library?

957


How do I convert a stl file?

769