Ctrl K

Word Ring

Easy
Kids play a word-chain game: each word must start with the letter the previous word ended with. The chain closes into a ring if, in addition, the last word ends with the first letter of the very first word. You are given phrase: words separated by exactly one space, with no leading or trailing spaces. Return True if its words form such a ring, and False otherwise. Uppercase and lowercase letters count as different.
Example 1
phrase="tiger rabbit tulip pot" → True

tige**r** → **r**abbi**t** → **t**uli**p** → **p**o**t**, and that final t matches the first letter of tiger.

Example 2
phrase="level" → True

A single word closes on itself: it starts and ends with l.

Example 3
phrase="Apple eagle" → False

Case matters: eagle ends in e while Apple starts with A.

Constraints
  • 1 ≤ len(phrase) ≤ 500
  • phrase consists of Latin letters (either case) and spaces
  • Words are separated by a single space, with no leading or trailing spaces
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
phrase="tiger rabbit tulip pot"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 222 tests on the server, hidden ones included.