Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python code There is a given list of strings where each string contains only lowercase letters from a - j , inclusive. The set of
Python code
There is a given list of strings where each string contains only lowercase letters from aj 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.
Example
wordsabcdbcd'abcde','bcde'
Here 'abcd' is a prefix of 'abcde' and bcd is a prefix of 'bcde'. Since 'abcde' is tested first, print
BAD SET
abcde
wordsabbccd
No string is a prefix of another so print
GOOD SET
Function Description
Complete the noPrefix function in the editor below.
noPrefix has the following parameters:
string wordsn: an array of strings
Prints
strings: either GOOD SET or BAD SET on one line followed by the word on the next line. No return value is expected.
Input Format
First line contains n the size of words
Then next n lines each contain a string, wordsi
Constraints
n
the length of wordsi
All letters in wordsi are in the range a through j inclusive.
Sample Input
STDIN Function
words size n
aab words aab 'defgab', 'abcde', 'aabcde', bbbbbbbbbb 'jabjjjad'
defgab
abcde
aabcde
cedaaa
bbbbbbbbbb
jabjjjad
Sample Output
BAD SET
aabcde
Explanation
'aab' is prefix of 'aabcde' so it is a BAD SET and fails at string 'aabcde'.
Sample Input
aab
aac
aacghgh
aabghgh
Sample Output
BAD SET
aacghgh
Explanation
'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'.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started