Interview Question


Country: United States
Interview Type: Written Test




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

I think problem is defined a little bit wrong. First of all if we talk about permutations - the order matters, so in your problem we are talking about subsets. For example if we have one array and we need to form all subsets of it array. You can whether take an element from array or not. if lenght of array if n, then you've got 2^n subsets and you can represent it like bit strings.

000
001
010
011
100
101
110
111

You can form form subsets of each array and answer will be Cartesian product of theese sets.

- glebstepanov1992 December 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In not wrong,
I believe they are looking for a given a list of arrays, form sets which contains atleast one elements from each array
String a[] = {"1","2","3"};
String b[] = {"a","b","c","d"};
String c[] = {"i","ii","iii","iv","v"};

- crack December 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

typo.. if not wrong. ..

- crack December 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

public class CartesianOfLists {

    public static List<List> getCartesianOfLists(List<List> inputListOfLists) {
        List<List> permutations = new ArrayList<List>();
        for (List list : inputListOfLists) {
            permutations = generatePermutations(permutations, list);
        }
        return permutations;
    }

    private static List<List> generatePermutations(List<List> permutations, List<String> list) {
        List<List> newPermutations = new ArrayList<List>();
        for (String str : list) {
            if (permutations.isEmpty()) {
                List tempList = new ArrayList();
                tempList.add(str);
                newPermutations.add(tempList);
            } else {
                for (List tempList : permutations) {
                    List innerList = new ArrayList();
                    innerList.addAll(tempList);
                    if (!innerList.contains(str)) {
                        innerList.add(str);
                        newPermutations.add(innerList);
                    }
                }
            }
        }
        return newPermutations;
    }
}

- techpanja December 12, 2013 | 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