Problems > Word Chain

Word Chain

Difficulty: 1000 2000 ms 128 MB

strings

In a word chain, each word must start with the last letter of the previous word. Is the given sequence a valid chain?

Input: one line with words separated by single spaces.

Output: YES or NO.

Constraints:

  • 1 to 200 words of lowercase letters

Sample Tests

Input 1
cat tiger rat
Output 1
YES
Input 2
dog fish
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.