Problem · String

Longest Consecutive Identical Character Run

Learn this problem
EasyNetflix logoNetflixFULLTIMEPHONE SCREEN

Problem statement

Given a string s, return the length of its longest nonempty consecutive run whose characters are all identical.

For this exercise, assume s contains only lowercase English letters and may be empty. Return 0 when s is empty.

Function

longestIdenticalRun(s: String) → int

Examples

Example 1

s = "aaabbc"return = 3

The prefix aaa is the longest identical-character run, so the answer is 3.

Example 2

s = "abbbbbaccc"return = 5

The run bbbbb has length 5, longer than every other run.

Example 3

s = ""return = 0

The empty string contains no nonempty run.

Constraints

  • s contains only lowercase English letters.
  • s may be empty.

More Netflix problems

drafts saved locally
public int longestIdenticalRun(String s) {
    // Your code here
}
s"aaabbc"
expected3
checking account