Store the given words, then read . Compare each word with . Print YES if any comparison succeeds, or NO if no word is equal to .
Two words are equal exactly when their lengths are equal and their characters agree at every position. First compare the lengths, then compare the characters only when the lengths match. A string equality operator checks the same condition. Repeated words do not affect the result.
Including the time to read and store the words, the time complexity is , and the space complexity is .
Proof
If the algorithm prints YES, it has found an index for which and have the same length and the same character at every position. Hence, is one of the words dadas08 can say.
Conversely, if dadas08 can say , then for some index . Comparing all the words necessarily finds this equality and prints . Therefore, printing when every comparison fails is also correct.
Solution written by GPT6
YESNO