> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Circular Sentence Python Solution with Tests

> Tested Python solution for LeetCode 2490 with 30 pytest cases. Generate a practice environment with lcpy.

LeetCode 2490, [Easy](/catalog/easy). Topics: [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/circular-sentence/description/).

Generate this problem as a practice environment: tested reference solution, 30 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 2490   # by problem number
lcpy gen -s circular_sentence   # by problem name
```

## Problem

\<p>A \<strong>sentence\</strong> is a list of words that are separated by a\<strong> single\</strong> space with no leading or trailing spaces.\</p>

\<ul>
\<li>For example, \<code>"Hello World"\</code>, \<code>"HELLO"\</code>, \<code>"hello world hello world"\</code> are all sentences.\</li>
\</ul>

\<p>Words consist of \<strong>only\</strong> uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.\</p>

\<p>A sentence is \<strong>circular \</strong>if:\</p>

\<ul>
\<li>The last character of each word in the sentence is equal to the first character of its next word.\</li>
\<li>The last character of the last word is equal to the first character of the first word.\</li>
\</ul>

\<p>For example, \<code>"leetcode exercises sound delightful"\</code>, \<code>"eetcode"\</code>, \<code>"leetcode eats soul" \</code>are all circular sentences. However, \<code>"Leetcode is cool"\</code>, \<code>"happy Leetcode"\</code>, \<code>"Leetcode"\</code> and \<code>"I like Leetcode"\</code> are \<strong>not\</strong> circular sentences.\</p>

\<p>Given a string \<code>sentence\</code>, return \<code>true\</code>\<em> if it is circular\</em>. Otherwise, return \<code>false\</code>.\</p>

### Examples

```
Input: sentence = "leetcode exercises sound delightful"
Output: true
Explanation: The words in sentence are ["leetcode", "exercises", "sound", "delightful"].
- leetcode's last character is equal to exercises's first character.
- exercises's last character is equal to sound's first character.
- sound's last character is equal to delightful's first character.
- delightful's last character is equal to leetcode's first character.
The sentence is circular.
```

```
Input: sentence = "eetcode"
Output: true
Explanation: The words in sentence are ["eetcode"].
- eetcode's last character is equal to eetcode's first character.
The sentence is circular.
```

```
Input: sentence = "Leetcode is cool"
Output: false
Explanation: The words in sentence are ["Leetcode", "is", "cool"].
- Leetcode's last character is not equal to is's first character.
The sentence is not circular.
```

### 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.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/circular_sentence/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/circular_sentence/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def is_circular_sentence(self, sentence: str) -> bool:
        for i, char in enumerate(sentence):
            if char == " " and sentence[i - 1] != sentence[i + 1]:
                return False
        return sentence[0] == sentence[-1]
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.