Consecutive Characters

The power of a string is the length of its longest non-empty substring that contains only one distinct character. Given a string `s`, return its power.

30:00

Consecutive Characters
easy
Free written solution
Topics
Companies

The power of a string is the length of its longest non-empty substring that contains only one distinct character. Given a string s, return its power.

Example 1:
Input: {"s":"leetcode"}
Output: 2
Constraints:
  • 1≤s.length≤5001 \leq s.\text{length} \leq 500

  • s consists of only lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"leetcode"}

s cut into runs of one letter: current run · best run

l

★ 1

e
e
t
c
o
d
e

The first letter 'l' starts a run of length 1, and it is also the best run so far.

run

1

best

1

Variables
VariableValue
i0
s[i]l
run1
best1
DepthFunction Call
Stack empty
0/8