PROBLEM LINK:
DIFFICULTY:
EASY
PREREQUISITES:
Strings
PROBLEM:
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.
QUICK EXPLANATION:
Store all the first letters of the string in an array, and then check each string.
EXPLANATION:
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[i] firstLetters[a[i][0]]++ kind=false for i in (1..n): currKind=true for each character in a[i]: curr[character]++ for c in ('a'..'z'): if(curr[c]>firstLetters[c]): currKind=false if currKind == true: kind = true
Time Complexity: O(n*|s|)