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

If its allowed to use extra space, create a int array of 256.

iterate through set 1, and increment value of array element at position (int)char. Then iterate through set 2.

Iterate through int array for all values = 2.

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

Elegant solution, +1.

If space is an issue, another alternative is to sort both the arrays. A modified version of the 'merge' step of mergesort can be used to verify if a given element occurs exactly twice in either of the arrays or both of the arrays combined.

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

If you cld use collections, then - Put all elements from both arrays in set, if it returns false, then add it to ur array. (Set returns false, if the object already present in it). Or u cld use hash map, put same key and value as ur input to map. If the return value is not null, then add it in new array.

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

This wont work. We need to return array that has elements occurring exactly twice.
Hashset would add elements occurring thrice also

- Neeraj September 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class GetList 
{
	public static void main(String[] args) 
	{
		Character arr1[]={'A','A','B','L','C','F','D','E','F','D','Z','R'};
		Character arr2[]={'C','E','X','Z','M','X','P','L','M','N','S','T','P','B','A'};
		List<Character> l1=new ArrayList<Character>();
		List<Character> l2=new ArrayList<Character>();
		l1=Arrays.asList(arr1);
		l2=Arrays.asList(arr2);
		System.out.println(method1(l1,l2));
	}
	static ArrayList<Character> method1(List<Character> a1,List<Character> a2)
	{
		HashMap<Character,Integer> hm=new HashMap<Character,Integer>();
		for ( char a : a1 )
		{
             
			 if(hm.containsKey(a))
			{
                 int x=hm.get(a);
				 x++;
				 hm.put(a,x);
			 }
			 else
			{
				 hm.put(a,1);
			}
		}
		for(char b:a2)
		{
            if(hm.containsKey(b))
			{
                 int x=hm.get(b);
				 x++;
				 hm.put(b,x);
			 }
			 else
			{
				 hm.put(b,1);
			}
		}
       ArrayList<Character> nal=new ArrayList<Character>();
	   Set<Character> s=hm.keySet();
	   for(char c : s)
		{
		   if(hm.get(c)==2)
			   nal.add(c);
	   }
	   return nal;
	}
}

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

public static ArrayList<String> findTwiceRepeat(List list1 , List list2){
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> input = new ArrayList<String>();
//contains the element which appears more than twice
ArrayList<String> more = new ArrayList<String>();
input.addAll(list1);
input.addAll(list2);
System.out.println("input : " + input);
for(int i=0;i < input.size();i++){
int count=1;
//if the element has already appeared twice, just go to next element
if(more.contains(input.get(i))){
continue;
}
for(int j=i+1;j<input.size();j++){
if(input.get(i).equals(input.get(j))){
count++;
}
// if the element appears more than twice , put it in the list
if(count > 2){
more.add(input.get(i));
break;
}
}
if(count == 2){
result.add(input.get(i));
}
}
return result;
}

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

Create a HashMap: where
<key> = element of the arraylist <AL1,AL2>,
<value> = number of times it appears in <AL1,AL2>

Once the HashMap is created, just restore the <keys> having <value>=2.
This logic will use extra space of O(N) = sizeof(AL1)+sizeof(AL2) in the worst case.
Time complexity will be order of 'N' .

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class ExactTwo {

	/**
	 * @param args
	 */
	
	public static ArrayList<Character> exactTwoChar(ArrayList<Character> AL1,ArrayList<Character> AL2)
	{
		ArrayList<Character> AL3 = new ArrayList<Character>();
		ArrayList<Character> AL4 = new ArrayList<Character>();
		ArrayList<Character> AL5 = new ArrayList<Character>();
		AL3.addAll(AL1);
		AL3.addAll(AL2);
		Set<Character> s = new HashSet<Character>();
		s.addAll(AL3);
		AL4.addAll(s);
		for (int i=0;i<AL4.size();i++)
		{
			int count = 0;
			Character a = (char) AL4.get(i);
			for (int j=0;j<AL3.size();j++)
			{	
				
				if(a.equals(AL3.get(j)))
				{
					count++;
				}
			}
			if(count == 2)
			{
				AL5.add(a);
			}
		}
		return AL5;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<Character> AL1 = 
			new ArrayList<Character>(Arrays.asList('A','A','B','L','C','F','D','E','F','D','Z','R'));
		ArrayList<Character> AL2 = 
			new ArrayList<Character>(Arrays.asList('C','E','X','Z','M','X','P','L','M','N','S','T','P','B','A'));
		ArrayList<Character> AL6 = new ArrayList<Character>();
		AL6 = exactTwoChar(AL1,AL2);
		for (Character ch : AL6) 
		{
		System.out.println(ch);
		}
	}

}

- Punith G September 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sdc

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

public class GetPairElements {

	private static List<String> getPairElements(List<String> a1, List<String> a2) {
		List<String> all = new ArrayList<String>(a1);
		all.addAll(a2);

		Map<String, Integer> cMap = new HashMap<String, Integer>();
		for(String s : all) {
			Integer i = cMap.get(s);
			if(i == null) {
				cMap.put(s, 1);
			} else {
				cMap.put(s, ++i);
			}
		}
		List<String> result = new ArrayList<String>();
		Set<Entry<String, Integer>> entrySet=  cMap.entrySet();
		for(Entry<String, Integer> entry: entrySet) {
			if(entry.getValue() == 2) {
				result.add(entry.getKey());
			}
		}

		return result;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String AL1[] = {"A","A","B","L","C","F","D","E","F","D","Z","R"};
		String AL2[] = {"C","E","X","Z","M","X","P","L","M","N","S","T","P","B","A"};

		List<String> pairElements = getPairElements(Arrays.asList(AL1), Arrays.asList(AL2));
		System.out.println(pairElements);

	}

}

- Pani Dhakshnamurthy September 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void getCharCount(
			HashMap<String, Integer> charCounter, ArrayList AL){
		for(int i = 0; i < AL.size(); i++) {
			String keyString = (String)AL.get(i);
			
			if(charCounter.get(keyString) == null) {
				charCounter.put(keyString, 1);
			}
			else {
				int count = charCounter.get(keyString);
				charCounter.put(keyString, ++count);
			}
		}
	}
	
	private static ArrayList twoCount(ArrayList AL1, ArrayList AL2){
		HashMap<String, Integer> charCounter = new HashMap<>();
		ArrayList AL3 = new ArrayList();

		getCharCount(charCounter,AL1);
		getCharCount(charCounter,AL2);
		
		for(String s:charCounter.keySet()){
			if(charCounter.get(s) == 2) {
				AL3.add(s);
			}
		}
		return AL3;
	}

- C0d3r December 07, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def duplicate_in_list(lst1, lst2):
    count = {}

    for i in lst1:
        if i in count:
            count[i] += 1
        else:
            count[i] = 1

    for i in lst2:
        if i in count:
            count[i] += 1
        else:
            count[i] = 1

    return [k for k, v in count.iteritems() if v == 2]

- TnG July 16, 2018 | 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