A decorator is inspecting one row of square floor tiles, described as a string of lowercase letters where each letter names a tile's color. A solid block is a maximal group of consecutive tiles that all share the same color — it cannot be extended in either direction because it either touches the edge of the row or is next to a tile of a different color on that side. Given the row and an integer k, determine whether the row contains at least one solid block made of exactly k tiles.
Line 1: a string s of lowercase English letters — the tile colors in order. Line 2: an integer k.
Print "true" if the row contains a solid block of exactly k tiles, or "false" otherwise.
1 <= k <= length of s <= 100. s consists only of lowercase English letters.
Example 1
Input
wwwzzxzz 3
Expected
true
Explanation
The row breaks into solid blocks www (length 3), zz (length 2), x (length 1), zz (length 2). The first block of 'w' has length exactly 3, matching k, so the answer is true.
Example 2
Input
abcdefg 2
Expected
false
Explanation
Every tile differs from both of its neighbors, so every solid block has length 1. None of them has length 2, so the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →