Skip to content

2490. Circular Sentence #779

Answered by mah-shamim
mah-shamim asked this question in Q&A
Nov 2, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to verify two conditions:

  1. Each word’s last character should match the next word’s first character.
  2. The last character of the final word should match the first character of the first word, making it circular.

Let's implement this solution in PHP: 2490. Circular Sentence

<?php
/**
 * @param String $sentence
 * @return Boolean
 */
function isCircularSentence($sentence) {
    // Split the sentence into words
    $words = explode(" ", $sentence);

    // Loop through the words and check the circular condition
    for ($i = 0; $i < count($words); $i++) {
        // Get the last character of the current word
        $lastChar = substr($words[$i], -1);

        // Determine the next wor…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Nov 2, 2024
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Nov 2, 2024
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants