FastPrepConsecutive Characters

Consecutive Characters

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

The power of a string is the maximum length of a nonempty contiguous substring containing only one repeated character. Return the power of text. Return 0 for an empty string.

Function

maxConsecutivePower(text: String) → int

Examples

Example 1

text = "abbcccddddeeeeedcba"return = 5

The longest run is five e characters.

Constraints

  • 0 <= text.length <= 10^5.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int maxConsecutivePower(String text) {
  // Write your code here.
}
text"abbcccddddeeeeedcba"
expected5
Checking account…