Ctrl K

A Letter Run of Exact Length

Easy
You are given a string text of lowercase English letters and an integer length. Check whether the string contains a block of exactly length identical letters in a row that cannot be extended: the letter before the block (if any) and the letter after it (if any) both differ from the block's letter. Return True if such a block exists and False otherwise.
Example 1
text='bbbxbbbb', length=3 → True

The first three b's form a run of exactly three: nothing stands before them and an "x" follows.

Example 2
text='qqqq', length=2 → False

Any two q's here touch another "q", so there is no standalone block of length 2.

Example 3
text='tree', length=1 → True
Constraints
  • 1 ≤ length ≤ len(text) ≤ 100
  • text consists of lowercase English letters
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
text='bbbxbbbb', length=3
Expected
True

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