## Facebook Interview Question

Software Engineer Interns**Country:**United States

**Interview Type:**Phone Interview

In recursive mode, we can do cool in ZoomBA :

```
def do_join( tuple, arr, result ){
i = size(tuple)
if ( i == size(arr) ){
result.add ( tuple )
return
}
for ( item : arr[i] ){
do_join ( tuple + item, arr, result )
}
}
s1 = [0,1,2]
s2 = [true, false]
arr = [s1, s2]
result = list()
do_join( [], arr, result )
println ( result )
```

```
/**
* Assuming that sets dont have duplicates as in the Mathematical definition of set.
* @param sets: The input list of the Sets.
* @return Intersection of the sets.
*/
public List<Integer> setIntersection(final List<Set<Integer>> sets) {
final List<Integer> intersection = new ArrayList<>();
if (sets.isEmpty()) {
return intersection;
}
final Map<Integer, Integer> occurance = new HashMap<>();
for (final Set<Integer> s : sets) {
for (final Integer i : s) {
if (occurance.containsKey(i)) {
occurance.put(i, occurance.get(i) + 1);
} else {
occurance.put(i, 1);
}
}
}
for (final Integer key : occurance.keySet()) {
if (occurance.get(key).equals(sets.size())) {
intersection.add(key);
}
}
return intersection;
}
```

void productOfSets(std::vector<std::set<int>> vec)

```
{
int mul = 1;
int smallest = vec[0].size();
int largest= vec[0].size();
for (size_t l = 0; l < vec.size(); l++)
{
smallest = vec[l].size() < smallest ? vec[l].size() : smallest;
largest = vec[l].size() > largest ? vec[l].size() : largest;
}
for (size_t k = 0; k < smallest; k++)
{
mul = 1;
for (int i = 0; i < vec.size(); i++)
{
std::set<int>::iterator itr = vec[i].begin();
for (int j = 0; j < k; j++)
{
itr++;
}
mul = *itr * mul;
}
std::cout << mul << "\n";
}
for (size_t t = 0; t < largest-smallest; t++)
{
std::cout << "0" << "\n";
}
```

}

```
void product(std::vector<std::set<int>> vec)
{
int mul = 1;
int smallest = vec[0].size();
int largest= vec[0].size();
for (size_t l = 0; l < vec.size(); l++)
{
smallest = vec[l].size() < smallest ? vec[l].size() : smallest;
largest = vec[l].size() > largest ? vec[l].size() : largest;
}
for (size_t k = 0; k < smallest; k++)
{
mul = 1;
for (int i = 0; i < vec.size(); i++)
{
std::set<int>::iterator itr = vec[i].begin();
for (int j = 0; j < k; j++)
{
itr++;
}
mul = *itr * mul;
}
std::cout << mul << "\n";
}
for (size_t t = 0; t < largest-smallest; t++)
{
std::cout << "0" << "\n";
}
```

}

This is how you do it :

In that case, here is how ZoomBA implemented join operation :-) from ZoomBA with love:

- NoOne December 22, 2016