We have to check if there exists a string in the given set of strings which can be written by using only the first terms of the set of strings.
Store all the first letters of the string in an array, and then check each string.
We are given that n,|s| < 100 so we can iterate each string.
We store the first characters of each string while taking the input.
Then we need iterate through all the strings to check if the given string is possible to be written using those first letters.
for i in (1..n): cin >> a* firstLetters[a*]++ kind=false for i in (1..n): currKind=true for each character in a*: curr[character]++ for c in ('a'..'z'): if(curr[c]>firstLetters[c]): currKind=false if currKind == true: kind = true
Time Complexity: O(n*|s|)