VMWare Inc Interview Question for Quality Assurance Engineers


Team: QATeam
Country: India
Interview Type: In-Person




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

Sort both the arrays and use a modified version of the 'merge' step that checks for the uniqueness of an element in both the arrays.

- Murali Mohan August 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

You can use to ArrayList and

import java.util.*;

public class UniqueElements {

public static void main(String[] args) {
List <Integer> al1 = new ArrayList<Integer>();
List <Integer>al2 = new ArrayList<Integer>();
al1.add(1);
al1.add(4);
al1.add(5);
al1.add(9);
al1.add(10);
al2.add(2);
al2.add(3);
al1.add(3);
al2.add(5);
al2.add(6);
al2.add(7);
al2.add(10);
al2.add(11);
al2.add(6);
al2.add(9);
System.out.println(al1);
System.out.println(al2);
List <Integer>result = new ArrayList <Integer>();
int i,j;
for(i=0;i<al1.size();i++)
{
if(!result.contains(al1.get(i)))
{
result.add(al1.get(i));
}
}
for(j=0;j<al2.size();j++)
{
if(!result.contains(al2.get(j)))
{
result.add(al2.get(j));
}
}

System.out.println(result);
}
}

Output :

Contents of Array1 : [1, 4, 5, 9, 10, 3]
Contents of Array2 : [2, 3, 5, 6, 7, 10, 11, 6, 9]
Unique elements in Result : [1, 4, 5, 9, 10, 3, 2, 6, 7, 11]

- Kavya November 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Answer will depend on the data.

Solution is to find a hash to data item to map to array index.

- KnowledgeSeeker August 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void make_unique(vector<int> & first , vector<int> &  second , vector<int> &third)
{
    sort(first.begin(),first.end());
    sort(second.begin(), second.end());
    third.clear();

    int f_pos = 0 , s_pos = 0 ; // index on first array and second array

    while(f_pos < first.size() && s_pos <second.size())
    {
        // 2 elements to compare
        if(first[f_pos] < second[s_pos])
        {
              third.push_back(first[f_pos]);
              // i want to skip all element in first array which are the same as first[f_pos]
              skip_dup(first,f_pos);
        }
        else if( second[s_pos] < first[f_pos])
        {
            third.push_back(second[s_pos]);
            //  // i want to skip all element in second array which are the same as second[f_pos]
            skip_dup(second,s_pos);
        }
        else
        {
          // 2 elements quals so push any of them and skip dup in both
            third.push_back(first[f_pos]);
            skip_dup(first,f_pos);
            skip_dup(second,s_pos);
        }
    }
    while(f_pos <first.size())
    {
        third.push_back(first[f_pos]);
        skip_dup(first,f_pos);
    }
    while(s_pos <second.size())
    {
        third.push_back(second[s_pos]);
        skip_dup(second,s_pos);
    }
}

Time O(NlogN) , Space O(1)

- spik August 26, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

void skip_dup(vector<int> & nums , int &pos)
{
    int elem = nums[pos];
    for( pos = pos+1 ; pos < nums.size() ; pos++)
    {
        if(nums[pos] != elem)
            return ;
    }
}

- spik August 26, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sort the smaller array. Perform binary search on it for each key in the larger array. If binary search is unsuccessful, they key is unique. Put this key in the third array

- Anonymous January 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote
{{{ void merge_arrays(int arr1[],int arr2[],int arr[],int size,int *pos1) { int i=0,j=0,last=-99; int pos = 0; while(i <size && j< size) { if(arr1[i] == arr2[j]) { if(last != arr1[i]) arr[pos++] = arr1[i]; last =arr1[i]; i++; j++; } else if(arr1[i] < arr2[j]) { if(last != arr1[i]) arr[pos++] = arr1[i]; last = arr1[i]; i++; } else { if(last != arr2[j]) arr[pos++] = arr2[j]; last = arr2[j]; j++; } } while(i != size) { if(last != arr1[i]) arr[pos++] = arr1[i]; last = arr1[i]; i++; } while(j != size) { if(last != arr2[j]) arr[pos++] = arr2[j]; last = arr2[j]; j++; } *pos1 = pos; } }]} - amit February 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

As time complexity is not mentioned with question, here is an easy solution:

public static void removeDuplicates(int[] arr1, int[] arr2){
		int[] arr = new int[arr1.length + arr2.length];
		int index=0,i,j;
		
		for (i=0;i<arr1.length;i++){
			if(!contains(arr, arr1[i])){
				arr[index++]=arr1[i];
			}
		}
		
		for (j = 0; j < arr2.length; j++) {
			if (!contains(arr, arr2[j])) {
				arr[index++] = arr2[j];
			}
		}
		
		for (int a: arr)
			System.out.println(a);
	}

	private static boolean contains(int[] arr, int i) {
		for (int a: arr){
			if(a==i) return true;
		}
		return false;
	}

- pawanKjajara February 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include <iostream>
#include <vector>
#include <set>

int main() {
	std::vector<int> first = { 5, 4, 3, 2, 1, 6, 7, 8};
	std::vector<int> second = { 5, 6, 7, 8, 9, 10, 11, 20, 19, 18};

	std::set<int> rSet(&first[0], &first[0] + first.size());	
	rSet.insert(second.begin(), second.end());
	
	std::vector<int> third(rSet.begin(), rSet.end());	
	for (size_t i = 0; i < third.size(); ++i) {
		std::cout << third[i] << std::endl;
	}
	std::cin.get();

	return 0;
}

O(nlogn).

- Passerby_A March 05, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class PutUniqueDataFrom2ArraysIn3rdArray1
{
public static void main(String args[])
{
ArrayList ar = new ArrayList();

int[] a1 = new int[]{1,2,3,4,5};
int[] a2 = new int[]{1,3,5,7};

for(int i=0;i<a1.length;i++)
{
if(ar.contains(a1[i]) == false)
ar.add(a1[i]);
}

for(int i=0;i<a2.length;i++)
{
if(ar.contains(a2[i]) == false)
ar.add(a2[i]);
}

System.out.println("arraylist= "+ar);
}
}

- pal April 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use HashMap: Store all the elements from smaller array1 into HashMap and into the resulting array3. Now start inspecting bigger array2 by checking HashMap.contains() call, if true - don't do anything. If false - store the value in resulting array3.

- Dhruvin July 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If only 2 arrays are given:
Python 3:

def unik(a,b):

res = []
	for i in a:
		if i in b:
			continue
		else:
			res.append(i)
	for j in b:
		if j in a:
			continue
		else:
			res.append(j)
	resturn res

a = [10,5,2,3,7,5]
b = [1,23,5,9,10,3]

Final result: res = [2,7,1,23,9]

- Anon May 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Looks like most people are ignoring a case. What it one if the arrays has a duplicate?

- Msa September 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<stdio.h>
#define MAX 10
#define IN 10
int main()
{

	int array_first[MAX] = {1,2,3,4,5,6,7,8,9,10};
	int array_second[IN] = {11,12,13,14,15,2,4,1,3,6};
	int temp[MAX]= {0};
	int i,j,k=0;
	for (i=0 ;i<MAX;i++)
	{
		for (j=0;j<MAX;j++)
		{
            if (array_first[i] == array_second[j])
			{
				temp[k] = array_first[i];
				printf("%d ",temp[k]);
				k++;
			}

		}
	}

	return 0;
}

- Kattupuchi October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your function is simply printing duplicate elements but whats really needed here is a third array holding unique elements from both arrays passed by caller.

- pawanKjajara February 24, 2014 | Flag


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