Magicsheet logo

Circular Sentence

Easy
12.5%
Updated 8/1/2025

Asked by 2 Companies

Topics

Circular Sentence

What is this problem about?

A sentence is "circular" if:

  1. The last character of each word is the same as the first character of the next word.
  2. The last character of the last word is the same as the first character of the first word. Given a string sentence containing words separated by single spaces, determine if it is circular.

Why is this asked in interviews?

Amazon and Bloomberg use this "Easy" problem to test your basic string parsing and loop logic. It’s a test of whether you can handle the "wrap-around" condition efficiently. It evaluates your skill in iterating through a string and checking neighbor properties.

Algorithmic pattern used

The pattern is simple String Simulation. You can either split the sentence into an array of words and compare the first and last characters of adjacent strings, or iterate through the original string and check the characters on either side of every space character.

Example explanation

sentence = "leetcode exercises sound delightful"

  1. "leetcode" ends in 'e', "exercises" starts with 'e'. (Match)
  2. "exercises" ends in 's', "sound" starts with 's'. (Match)
  3. "sound" ends in 'd', "delightful" starts with 'd'. (Match)
  4. "delightful" ends in 'l', "leetcode" starts with 'l'. (Match) Result: True.

Common mistakes candidates make

A common error is forgetting the second condition—checking the wrap-around from the last word back to the first. Another mistake is not handling sentences that consist of only a single word (in which case the first and last characters of that word must match).

Interview preparation tip

For "neighbor" problems in strings or arrays, always think about the "first and last" pair separately to handle the circularity. It's often cleaner to check the wrap-around explicitly after the main loop.

Similar Questions