All problems
1060EasyString

The Longest Run of One Mark

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1446Consecutive Characters

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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