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.

- DashDash June 02, 2012 | Flag Reply
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 ...

- Anonymous June 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Siva krishna June 04, 2012 | Flag
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];
}

- sqw June 04, 2012 | Flag Reply
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

- wzyflyleaf June 04, 2012 | Flag Reply
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.

- Tenon July 05, 2012 | Flag Reply
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]);
}
}

}

- sathishwaran March 05, 2013 | Flag Reply
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){
			set2.add(num);
		}
		ArrayList<Integer> missingNumbers = new ArrayList<Integer>();
		for(int num:array1){
			if (set2.add(num)) {
				missingNumbers.add(num);
			}
		}
		return missingNumbers;
	}

- Zakon September 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

- pthonic December 02, 2013 | Flag Reply
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;
}

- Vickey May 04, 2017 | Flag Reply
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)
{
set.add(i);
}
for(int i=0;i<arr1.length;i++)
{
if(!set.contains(arr1[i]))
{
return arr1[i];
}
}
return -1;
}

- Shabana Khan June 01, 2020 | Flag Reply
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)
		{
			set.add(i);
		}
		for(int i=0;i<arr1.length;i++)
		{
			if(!set.contains(arr1[i]))
			{
				return arr1[i];
			}
		}
		return -1;
	}

- Shabana Khan June 01, 2020 | Flag Reply
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;
}

- Abey June 26, 2012 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More