JuniorString

Circular Sentence

A sentence is a list of words that are separated by a single space with no leading or trailing spaces.

  • For example, "Hello World", "HELLO", and "hello world hello world" are all sentences.

Words consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.

A sentence is circular if:

  • The last character of each word in the sentence is equal to the first character of its next word.
  • The last character of the last word is equal to the first character of the first word.

Given a string sentence, return true if it is circular. Otherwise, return false.

Example 1
Inputsentence = "leetcode exercises sound delightful"
Outputtrue
Each word's last character matches the next word's first character, and the last word connects back to the first word.
Example 2
Inputsentence = "eetcode"
Outputtrue
The only word's last character is equal to its first character.

Constraints

  • 1 <= sentence.length <= 500
  • sentence consist of only lowercase and uppercase English letters and spaces.
  • The words in sentence are separated by a single space.
  • There are no leading or trailing spaces.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate