JuniorString

Consecutive Characters

The power of a string is the maximum length of a non-empty substring that contains only one unique character.

Given a string s, return the power of s.

Example 1
Inputs = "leetcode"
Output2
The substring "ee" is of length 2 with the character 'e' only.
Example 2
Inputs = "abbcccddddeeeeedcba"
Output5
The substring "eeeee" is of length 5 with the character 'e' only.

Constraints

  • 1 <= s.length <= 500
  • s consists of only lowercase English letters.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate