## EMC Interview Question for Software Engineer in Tests

Team: RSA
Country: India
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
0
of 0 vote

Add both arrays and substract them.

Comment hidden because of low score. Click to expand.
0
of 0 vote

take min and max element of the second array and make array of make an array of (max-min) size u can also use bit array if max -min is ahuge number because of space complexity
then traverse the second array and according to each digit set bits on bit array after that traverse first array and in which, which bit not set that is a missing number ...

Comment hidden because of low score. Click to expand.
0

@panshul21
would u please tell me the missing element must be replaced with only '0' or any other element in second array

Comment hidden because of low score. Click to expand.
0
of 2 vote

``````// assume a.length == b.length + 1;
// XOR all the elements in both a and b arrays.

int getMissingInteger(int[] a, int b[]) {
int ret = 0;
for (int i=0; i<a.length-1; i++) {
ret ^= a[i];
ret ^= b[i];
}
return ret ^= a[i];
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

1)hash or bit map
2)sum(array1)-sum(array2)=x-y, square(array1) - square(array2) = x^2 - y^2, with this we will get x and y

Comment hidden because of low score. Click to expand.
0
of 0 vote

This is very easy because the foreign element in the second array is 0, it would have been harder if it wasn't.
So just compute the total of each array and substruct them, you will get exactly the missing number.

Comment hidden because of low score. Click to expand.
0
of 0 vote

int[] sat1 = {5,15,2,20,30,40,8,1};
int[] sat2 = {2,20,15,30,1,40,0,8};
for(int i=0;i<sat2.length;i++){
int count = 0;
for(int j=0;j<sat1.length;j++){
if(sat2[i]==sat1[j]){

}else{
count++;
}
}
// System.out.print(count + " ");
if(count==8){
System.out.print(sat2[i]);
}
}

}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static ArrayList<Integer> getMissingNumbers(int[] array1, int[] array2) {
HashSet<Integer> set2 =  new HashSet<Integer>();
for(int num:array2){
}
ArrayList<Integer> missingNumbers = new ArrayList<Integer>();
for(int num:array1){
}
}
return missingNumbers;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``C = [x for x in B if x not in A]``

Comment hidden because of low score. Click to expand.
0
of 0 vote

This solution only works when 0 is the number which is introduced in place of missing numbers.

``````int getMissingNumber(int arr1[], int arr2[], int sz)
{
int xor1=0;
int xor2=0;
for(int i = 0; i < sz; i++) {
xor1 ^= arr1[i];
xor2 ^= arr2[i];
}
return xor1^xor2;
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int findMissing(int[] arr1,int[] arr2)
{
Set<Integer> set = new HashSet<Integer>();
for(int i : arr2)
{
}
for(int i=0;i<arr1.length;i++)
{
if(!set.contains(arr1[i]))
{
return arr1[i];
}
}
return -1;
}

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````public static int findMissing(int[] arr1,int[] arr2)
{
Set<Integer> set = new HashSet<Integer>();
for(int i : arr2)
{
}
for(int i=0;i<arr1.length;i++)
{
if(!set.contains(arr1[i]))
{
return arr1[i];
}
}
return -1;
}``````

Comment hidden because of low score. Click to expand.
-1
of 1 vote

``````Employing 2 loops:

#include <p30fxxxx.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/*Write a program to find the missing element in second array(Array2):
Array1:
5 15 2 20 30 40 8 1
Array2:
2 20 15 30 1 40 0 8 */
5 0 */

volatile int ara[8] = {5, 15, 2, 20, 30, 40, 8, 1};
volatile int arb[8] = {2, 20, 15, 30, 1, 40, 0, 8};
volatile int x;

int main (void)
{
int *ptr;
volatile int i, j, count;
for (i=0; i<8; i++)
{ 	count =0x0;
for (j=0; j<8; j++)
{
if (arb[i]== ara[j])
count++;
}
if (!count)
printf ("Missing element is %d\n",arb[i]);
}
x++;
return 0;
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.