Show problems as
Classic problem #1446EasyString

Consecutive Characters

Real-world version: The Longest Run of One Mark
Tracked in this browser only
Read Consecutive Characters on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A tape of lowercase letters reads tape.

Return the length of the longest stretch of neighbouring positions all holding the same letter.

Examples

Example 1

Input
tape = "aabbbcc"
Output
3

The three b's in the middle form the longest stretch; the a's and the c's manage only two apiece.

Example 2

Input
tape = "zzzz"
Output
4

The whole tape is one letter repeated, so the stretch runs the full length.

Example 3

Input
tape = "abc"
Output
1

No two neighbouring letters match, so every stretch holds a single letter.

Constraints

  • 1 <= tape.length <= 500
  • The tape is made of lowercase English letters.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def max_power(tape: str) -> int:
Java
public int maxPower(String tape)