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 .

Answers were Sorted based on User's Feedback



Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all ..

Answer / aniruddha

public int check(int a[], int b[])
{  int value,w;
   for(int i=0; i<=a.length; i++)
   {  w=0;
      for(int j=0; j<b.length; j++)
      {  
         if(a[i]!=b[j])
         {  w++;
            break;
         }
      }
      if(w==0)
      value=a[i];
   }
   return value;
}

Is This Answer Correct ?    12 Yes 9 No

Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all ..

Answer / 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

Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all ..

Answer / ninad

public int check(int a[], int b[])
{
int x;
int[] c=new int[a.length];
for(int i=0; i<=c.length; i++)
{
c[i]=0;
}
for(int i=0; i<=a.length; i++)
{
for(int j=0; j<b.length; j++)
{
if(a[i]==b[j])
c[i]=1;
}
}
for(int i=0;i<=c.length;i++)
if(c[i]==0)
x=a[i];
return x;
}

Is This Answer Correct ?    0 Yes 0 No

Give two integer arrays A & B.A has n elements and B has ' n-1 ' elements . A has all ..

Answer / abhi

#include<iostream>
using namespace std;
#include<algorithm>
int main()
{
int n;
cin>>n;
int a[n],b[n-1];
int sum1=0,sum2=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum1+=a[i];
}
for(int i=0;i<n-1;i++)
{
cin>>b[i];
sum2+=b[i];
}
cout<<sum1-sum2<<endl;



}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More STL Interview Questions

Is string part of stl?

0 Answers  


What is stl stand for?

0 Answers  


How to write a function that goes through an array of characters and eliminates any elements that are not letters (Legal letters can be either in an uppercase or a lowercase format.) The function removeNonLetters should return the new effective size of the array as the result.

2 Answers  


What does stl mean in slang?

0 Answers  


i want a road rash 3d game code if some one know please help me

1 Answers  






what is template and type convertion

0 Answers   TATA,


What is Object Oriental Progam

2 Answers  


Write a program in C++ returning starting locations of a substring using pointers

1 Answers  


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

0 Answers   informatics,


how to use C++?

0 Answers   NIIT,


Give the output of the following program main() {char *p='a'; int *i=100/*p; } what will be the value of *i= 1

6 Answers   Sun Microsystems,


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

0 Answers  


Categories