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

What is stl in oop?

0 Answers  


what is the difference between thread and process

1 Answers   Infosys,


write a program to search and display the position of an element in a single-dimentional array using function.

1 Answers  


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

0 Answers   informatics,


If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2. please answer my question ....

0 Answers   Microsoft,






What is the use of stl?

0 Answers  


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

0 Answers  


Write a program in C++ to concatenate two strings into third string using pointers

5 Answers  


how to swap two numbers in a linked list without exchanging the data but only the links?

3 Answers   Wipro,


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

1 Answers  


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

0 Answers   Appin, NIIT,


Is stl open source?

0 Answers  


Categories