There is a given list of strings where each string contains only lowercase letters from , inclusive. The set of strings is said to be a GOOD SET if no string is a prefix of another string. In this case, print GOOD SET. Otherwise, print BAD SET on the first line followed by the string being checked.
Note If two strings are identical, they are prefixes of each other.
Here 'abcd' is a prefix of 'abcde' and 'bcd' is a prefix of 'bcde'. Since 'abcde' is tested first, print
No string is a prefix of another so print
Complete the noPrefix function in the editor below.
noPrefix has the following parameter(s):
- string words[n]: an array of strings
- string(s): either GOOD SET or BAD SET on one line followed by the word on the next line. No return value is expected.
First line contains , the size of .
Then next lines each contain a string, .
the length of words[i]
All letters in are in the range 'a' through 'j', inclusive.
7 words size n = 7
aab words = ['aab', 'defgab', 'abcde', 'aabcde', 'bbbbbbbbbb', 'jabjjjad']
'aab' is prefix of 'aabcde' so it is a BAD SET and fails at string 'aabcde'.
'aab' is a prefix of 'aabghgh', and aac' is prefix of 'aacghgh'. The set is a BAD SET. 'aacghgh' is tested before 'aabghgh', so and it fails at 'aacghgh'.