Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 is a stl vector?

1169


how to use C++?

2491


Name the different types of stl containers.

1127


What is a standard template library (stl)?

1077


i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

2180


What does stl mean in slang?

1065


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.

1907


draw a flowchart that accepts two numbers and checks if the first is divisible by the second.

3330


Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.

2123


Who wrote stl?

1087


In what scenario does the Logical file and Physical file being used?

2786


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

2189


What is a standard template library (stl)? What are the various types of stl containers?

1119


What is stl language?

1097


Explain stl.

1310