Given N lists of strings, the task is to find the count of lists which are not a sublist of any other given lists.
Input: [[“hey”, “hi”, “hello”], [“hey”, “bye”], [“hey”, “hi”]]
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”]]
Explanation: Both the lists comprise of same set of strings.
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:
Time Complexity: O ( N * M )
Auxiliary Space: O ( N * M )
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price.