This was an algorithm problem but I am having problems in formulating it.
I have a certain approach but I do not know how to fully execute:
Given
- 26 letters in total
- All possible strings of length n
Example
Find all possible strings of length 5 such that given [{a, b, c}, {d, g, h}], no two letters from each set can occur in that string:
- 'a' and 'd' can occur any number of times in the string, as well as 'a' and 'g'.
- no single instance of 'a' and 'b' occurring or 'b' and 'c' or 'a', 'b' and 'c' ( basically any pair )
- No two sets will have any characters in common such as [{a, b, c}, {d, g, h}, {c, l, f}] not allowed.
My naive approach
- Find all possible strings of length n consisting of characters other than the ones mentioned in the set of sets.
- Take a single set:
- Take 1 character from a set.
- Find the characters that are valid with this character and count the possible strings of length n.
- Take 1 character from a set.
But this does not take care of repetitions I think. So is there some other way or do I need to refine more?