395. Longest Clear Section in Garbled Text
Longest Clear Section in Garbled Text

A damaged book contains a line of garbled text. A section is considered clear when every character in it is different.

Find the length of the longest consecutive clear section in the text. Characters cannot be skipped.

Method Signature

int longestClearSection(String garbledText)

Parameters

  • garbledText: The text found in the damaged book.

Returns

The length of the longest consecutive section containing no repeated characters.

Constraints

  • 0 ≤ garbledText.length() ≤ 100,000
  • garbledText may contain letters, digits, spaces and special characters.
  • Uppercase and lowercase characters are considered different.
  • garbledText is never null.
  • An empty string has an answer of 0.

Examples

Example 1

longestClearSection(garbledText = "chaptermark")

Returns 8.

The section "chapterm" contains eight different characters.

Example 2

longestClearSection(garbledText = "%%%%")

Returns 1.

Every character is the same, so a clear section can contain only one character.

Example 3

longestClearSection(garbledText = "editorial")

Returns 6.

The sections "editor" and "torial" each contain six characters without repetition.



Please use Laptop/Desktop or any other large screen to add/edit code.