Given **N **lists of strings, the task is to find the count of lists which are not a sublist of any other given lists.

**Examples:**

Input:[[“hey”, “hi”, “hello”], [“hey”, “bye”], [“hey”, “hi”]]

Output:2

Explaination

The third list is a subset of the first list, hence the first and the second list are the required lists.

Input:[[“geeksforgeeks”, “geeks”], [“geeks”, “geeksforgeeks”]]

Output:0

Explanation:Both the lists comprise of same set of strings.

**Approach**

Follow the steps below to solve the problem:

- First of all, enumerate all the possible strings in all vectors, i.e. assign them an integer.
- Then, use a Bitset for all individual lists to store the strings present in them.
- Compare the bitsets. If one of the bitsets is a subset of another, ignore that list. Otherwise insert the index of that list in a set.
- Print all the indices in the set.

Below code is the implementation of the above approach:

## C++

`// C++ program to find all lists ` `// which are not a subset of any ` `// other given lists ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `#define N 50005 ` ` ` `// Function to print all lists which ` `// are not a subset of any other lists ` `void` `findNonSubsets(vector<vector<string> >& v, ` ` ` `vector<` `int` `>& ans) ` `{ ` ` ` `unordered_map<string, ` `int` `> mp; ` ` ` `int` `id = 1; ` ` ` `// Enumerate all strings ` ` ` `// present in all lists ` ` ` `for` `(` `int` `i = 0; i < v.size(); i++) { ` ` ` `for` `(` `int` `j = 0; j < v[i].size(); j++) { ` ` ` `if` `(mp.count(v[i][j]) > 0) ` ` ` `continue` `; ` ` ` ` ` `mp[v[i][j]] = id++; ` ` ` `} ` ` ` `} ` ` ` ` ` `// Compute and store bitsets ` ` ` `// of all strings in lists ` ` ` `vector<bitset<N> > v1; ` ` ` ` ` `for` `(` `int` `i = 0; i < v.size(); i++) { ` ` ` `bitset<N> b; ` ` ` `for` `(` `int` `j = 0; j < v[i].size(); j++) { ` ` ` `b[mp[v[i][j]]] = 1; ` ` ` `} ` ` ` `v1.push_back(b); ` ` ` `} ` ` ` `for` `(` `int` `i = 0; i < v.size(); i++) { ` ` ` `bool` `flag = ` `false` `; ` ` ` `for` `(` `int` `j = 0; !flag and j < v.size(); j++) { ` ` ` `if` `(i != j) { ` ` ` `// If one of the bitsets is ` ` ` `// a subset of another, the ` ` ` `// logical AND is equal to the ` ` ` `// subset(intersection operation) ` ` ` `if` `((v1[i] & v1[j]) == v1[i]) { ` ` ` `flag = ` `true` `; ` ` ` `} ` ` ` `} ` ` ` `} ` ` ` ` ` `if` `(!flag) { ` ` ` `ans.push_back(i); ` ` ` `} ` ` ` `} ` ` ` `return` `; ` `} ` ` ` `// Driver Program ` `signed` `main() ` `{ ` ` ` `vector<vector<string> > v ` ` ` `= { { ` `"hey"` `, ` `"hello"` `, ` `"hi"` `}, ` ` ` `{ ` `"hey"` `, ` `"bye"` `}, ` ` ` `{ ` `"hey"` `, ` `"hi"` `} }; ` ` ` ` ` `vector<` `int` `> ans; ` ` ` `findNonSubsets(v, ans); ` ` ` ` ` `if` `(ans.size() == 0) { ` ` ` `cout << -1 << endl; ` ` ` `return` `0; ` ` ` `} ` ` ` ` ` `for` `(` `int` `i = 0; i < ans.size(); i++) { ` ` ` `cout << ans[i] << ` `" "` `; ` ` ` `} ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

0 1

**Time Complexity:** O ( N * M )

**Auxiliary Space:** O ( N * M )

## Recommended Posts:

- Largest possible Subset from an Array such that no element is K times any other element in the Subset
- Find maximum subset sum formed by partitioning any subset of array into 2 partitions with equal sum
- Strings from an array which are not prefix of any other string
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Count of elements not divisible by any other elements of Array
- Check whether bitwise AND of a number with any subset of an array is zero or not
- Sum of maximum and minimum of Kth subset ordered by increasing subset sum
- Array with GCD of any of its subset belongs to the given array
- Check if any permutation of a number without any leading zeros is a power of 2 or not
- Check if there exists any sub-sequence in a string which is not palindrome
- Longest subarray in which absolute difference between any two element is not greater than X
- Construct a graph which does not contain any pair of adjacent nodes with same value
- Divide array into two arrays which does not contain any pair with sum K
- Check if bitwise AND of any subset is power of two
- Largest subset where absolute difference of any two element is a power of 2
- Print all possible combinations of the string by replacing '$' with any other digit from the string
- Minimize count of given operations required to make two given strings permutations of each other
- Count of elements which cannot form any pair whose sum is power of 2
- Count the nodes of a tree whose weighted string does not contain any duplicate characters
- Maximum in array which is at-least twice of other elements

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.