VMWare Inc Interview Question for Member Technical Staffs


Country: United States
Interview Type: Phone Interview




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

rehash
careercup.com/question?id=6318635089920000
collabedit.com/4pmvt

- S O U N D W A V E October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks!

- xmen_wolv October 17, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

public class CharNumberAI {

    public static void Do()
    {
        Map<Integer, List<String>> listHashMap = new HashMap<Integer, List<String>>();
        List<List<String>> inputList=new ArrayList<List<String>>();
        List<String> arrayList=null;
        arrayList=new ArrayList<String>();
        arrayList.add("a1");
        arrayList.add("b1");
        inputList.add(arrayList);
        arrayList=new ArrayList<String>();
        arrayList.add("a2");
        arrayList.add("b2");
        inputList.add(arrayList);
        arrayList=new ArrayList<String>();
        arrayList.add("a3");
        arrayList.add("b3");
        inputList.add(arrayList);
        PrintPowerSet(inputList, inputList.size()-1, new HashSet<String>());
    }

    private static void PrintPowerSet(List<List<String>> allchars, int index, Set<String> permSet)
    {
        List<String> stringList = allchars.get(index);

        Set<String> subPremSet = null;
        for(String str :stringList)
        {
            subPremSet=new HashSet<String>();
            subPremSet.addAll(permSet);
            if (index == 0)
            {
                subPremSet.add(str);
                printSet(subPremSet);
            }
            else
            {
                //Console.Write(ch);
                subPremSet.add(str);
                PrintPowerSet(allchars, index - 1, subPremSet);
            }
        }
    }

    public static void printSet(Set<String> hashSet){
        Iterator<String> i=hashSet.iterator();
        System.out.print("{ ");
        while(i.hasNext()){
            System.out.print(i.next()+", ");
        }
        System.out.println("}");
    }
}

- xmen_wolv October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static List<ArrayList<String>> getPermutations(
			List<ArrayList<String>> lists) {
		
		List<ArrayList<String>> currentPermutations = 
				new ArrayList<ArrayList<String>>();
		
		// generate new permutations one list at a time
		for (ArrayList<String> list : lists) {
			currentPermutations = 
					generatePermutations(currentPermutations, list);
		}
		
		return currentPermutations;	
	}
	
	private static List<ArrayList<String>> generatePermutations(
			List<ArrayList<String>> currentPermutations, 
			ArrayList<String> list) {
		
		// we'll be creating a whole new set of permutations from 
		// currentPermutations and the 'list' of new items
		List<ArrayList<String>> newPermutations = 
				new ArrayList<ArrayList<String>>();
		for (String item : list) {
			if (currentPermutations.isEmpty()) {
				
			    // first generated list - just add the single items
				ArrayList<String> newPermutation = new ArrayList<String>();
				newPermutation.add(item);
				newPermutations.add(newPermutation);
			}
			else {
				// create a new permutation list based 
				// on the old list plus our new item
				for (ArrayList<String> curList : currentPermutations) {
					if (!curList.contains(item)) {
						ArrayList<String> newPermutation = 
								new ArrayList<String>(curList);
						newPermutation.add(item);
						newPermutations.add(newPermutation);
					}
				}
			}
		}		
		
		return newPermutations;		
	}

   public static void getPermutationsTest() {
	   List<ArrayList<String>> permutations = 
			   new ArrayList<ArrayList<String>>();
	   ArrayList<String> list = new ArrayList<String>();
	   list.add("a1");
	   list.add("a2");
	   permutations.add(list);
	   list = new ArrayList<String>();
	   list.add("b1");
	   list.add("b2");
	   list.add("b3");
	   permutations.add(list);
	   list = new ArrayList<String>();
	   list.add("c1");
	   list.add("c2");
	   permutations.add(list);
	   
	   permutations = Util.getPermutations(permutations);
	   for (ArrayList<String> permutation : permutations) {
		   System.out.println(permutation);
	   }	   
   }

// Output: 
// [a1, b1, c1]
// [a2, b1, c1]
// [a1, b2, c1]
// [a2, b2, c1]
// [a1, b3, c1]
// [a2, b3, c1]
// [a1, b1, c2]
// [a2, b1, c2]
// [a1, b2, c2]
// [a2, b2, c2]
// [a1, b3, c2]
// [a2, b3, c2]

- Michael.J.Keating October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

The question doesn't seem to be asking anything more than to print cartesian product of the elements.

- Murali Mohan October 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Same, but a bit less code

public static Set<Set<String>> getSetPermutations(List<List<String>> lists) {
        final HashSet<Set<String>> acc = new HashSet<Set<String>>();
        getSetPermutations(new ArrayList<List<String>>(lists), 
                         new HashSet<String>(), acc);
        return acc;
    }

    private static void getSetPermutations(List<List<String>> lists, 
									Set<String> current, 
									Set<Set<String>> acc) {
        if (lists.isEmpty()) {
            acc.add(current);
            return;
        }
        List<List<String>> listsLocal = new ArrayList<List<String>>(lists);
        for (String s : listsLocal.remove(0)) {
            final HashSet<String> set = new HashSet<String>(current);
            set.add(s);
            getSetPermutations(listsLocal, set, acc);
        }
    }

- anonymous October 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package kb.learning;

import java.util.ArrayList;
import java.util.List;

public class Combinations
{
    static List<List<Character>> lists = new ArrayList<>();
    
    private static void fillInput()
    {
        List<Character> l = new ArrayList<>();
        l.add('A');
        l.add('B');
        l.add('C');
        lists.add(l);
        
        l = new ArrayList<>();
        l.add('1');
        l.add('2');
        l.add('3');
        lists.add(l);
        
        l = new ArrayList<>();
        l.add('a');
        l.add('b');
        l.add('c');
        lists.add(l);
    }
    
    public static void main(String[] args)
    {
        fillInput();
        generateCombo("", 0);
        
    }
    
    private static void generateCombo(String beginStr, int listIndex)
    {
        if(listIndex == lists.size() - 1)
        {
            for(Character c : lists.get(listIndex))
                System.out.println(beginStr + c);
        }
        else
        {
            for(Character c : lists.get(listIndex))
                generateCombo(beginStr + c, listIndex + 1);
        }
    }
}

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

package com.fb.inter;

import java.util.ArrayList;
import java.util.List;

public class Q1 {
	
	public static void main(String[] args){
		List<List<String>> permutations = 
				   new ArrayList<List<String>>();
		   ArrayList<String> list = new ArrayList<String>();
		   list.add("a1");
		   list.add("a2");
		   permutations.add(list);
		   list = new ArrayList<String>();
		   list.add("b1");
		   list.add("b2");
		   list.add("b3");
		   permutations.add(list);
		   list = new ArrayList<String>();
		   list.add("c1");
		   list.add("c2");
		   permutations.add(list);
		   printPermutations(permutations);
	}
	
	private static void printPermutations(List<List<String>> lists){
		int numOfPerms = getNumOfPerm(lists);
		int numOfLists = lists.size();
		int[] indices = new int[numOfLists];
		List<List<String>> permutations = new ArrayList<List<String>>(numOfPerms);
		for(int i = 0; i < numOfPerms; i++ ){
			List<String> onePerm = new ArrayList<String>();
			for(int k = 0; k < indices.length ; k++){
				onePerm.add(lists.get(k).get(indices[k]));
			}
			permutations.add(onePerm);
			increaseIndices(indices, lists);
		}
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < permutations.size(); i++ ){
			builder.append('[');
			List<String> currentPermutation = permutations.get(i);
			for(int j = 0; j < currentPermutation.size(); j++  ){
				builder.append(currentPermutation.get(j)).append(',');
			}
			builder.append(']');
			System.out.println(builder.toString());
			builder.setLength(0);
		}
		
	}
	
	private static void increaseIndices(int[] indices, List<List<String>> lists){
		boolean done = false;
		for(int i = 0; i < indices.length && ! done ; i++ ){
			indices[i] = (indices[i] + 1) % lists.get(i).size();
			done = indices[i] != 0;
		}
	}
	
	private static int getNumOfPerm(List<List<String>> lists){
		int total = 1;
		for(List<String> list: lists){
			int tempTotal = (list != null && list.size() != 0) ? list.size() : 1;
			total *= tempTotal;
		}
		return total;
	}

}

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

public class PermutationMain {

public static void main(String[] args) {
// TODO Auto-generated method stub
String[] arrayOne = {
"a1", "b1", "c1","d1"

};

String[] arrayTwo = {
"a2", "b2", "c2"

};

String[] arrayThree = {
"a3", "b3", "c3"

};
List<List<String>> result=new ArrayList<List<String>>();
List<String> list=null;
for(String l1Elem:arrayOne){
for(String l2Elem:arrayTwo){
for(String l3Elem:arrayThree){
list=new ArrayList<String>();
list.add(l1Elem);
list.add(l2Elem);
list.add(l3Elem);
result.add(list);
}
}
}
for(List<String> resultElem:result){
System.out.println();
for(String s:resultElem){
System.out.print(s+":");
}
}
}



}

- AV October 19, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def digTolets(digs):
  if len(digs) == 0:
    return []
  first, rest = digs[0],digs[1:]
  ret = []
  if first in d :
    for x in d[first]:
      if rest:
        for y in digTolets(rest): 
           ret.append(x+y)
      else:
        return d[first]
    return ret

- sathiyamoorthy January 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I don't see the need for all this code. I think the following is sufficient.

public static void main (String args[]){
        String []set1=  {"a1","b1","c1","d1"};
        String []set2= {"a2","b2","c2"};
        String []set3= {"a3","b3","c3"};
        for (int i=0; i<set1.length; i++){
            for (int j=0;j<set2.length; j++){
                for (int k=0; k<set3.length; k++){
                    System.out.println(String.format("{%s,%s,%s}",set1[i],set2[j],set3[k]));
                }
            }
        }
    }

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

#include<iostream>
#include<string>
#include<vector>

using namespace std;

void permutation(vector<string> a,vector<string> b, vector<string> c)
{
    for(vector<string>::iterator i=a.begin()+1;i<a.end();i++)
    {
        for(vector<string>::iterator j=b.begin()+1;j<b.end();j++)
        {
            for(vector<string>::iterator k=c.begin()+1;k<c.end();k++)
            {
                cout<<*i<<"\t"<<*j<<"\t"<<*k<<endl;
            }
            cout<<endl;
        }
        cout<<endl;
    }
}

int main()
{
    vector<string> a,b,c;
    int n;
    string in;

    cin>>n;

    for(int i=0;i<=n;i++)
    {
        getline(cin,in);
        a.push_back(in);
    }



    cin>>n;

    for(int i=0;i<=n;i++)
    {
        getline(cin,in);
        b.push_back(in);
    }



    cin>>n;

    for(int i=0;i<=n;i++)
    {
        getline(cin,in);
        c.push_back(in);
    }



    permutation(a,b,c);
}

- Vishal October 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void permuteList(String[][] list, int start, ArrayList<String> perms){
if(start == list.length){
if(perms.size() == list.length)
System.out.println(perms.toString());
return;
}

for(int i = 0; i < list[start].length; i++){
perms.add(list[start][i]);
for(int j = start+1; j <= list.length; j++){
permuteList(list, j, perms);
}
perms.remove(list[start][i]);
}
}

- zahidbuet106 November 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

public static void permuteList(String[][] list, int start, ArrayList<String> perms){
	if(start == list.length){
		if(perms.size() == list.length)
			System.out.println(perms.toString());
		return;
	}
	
	for(int i = 0; i < list[start].length; i++){
		perms.add(list[start][i]);
		for(int j = start+1; j <= list.length; j++){
			permuteList(list, j, perms);
		}
		perms.remove(list[start][i]);
	}
}

- zahidbuet106 November 14, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

def permutations(string,step=0):
if step==len(string):
print(''.join(string))
for i in range(step,string):
string=list(string)
string[i],string[step]=string[step],string[i]
permutations(string,step+1)

- Tharakanadha Reddy May 14, 2020 | 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