Last Updated: 6 Dec, 2025

Longest Unique Subarray

Easy

Problem statement

You are a developer at a text processing company, and you've been tasked with a feature that identifies the longest segment of a document that contains no repeated characters. This is useful for data validation and linguistic analysis.


A "subarray" or "substring" is a contiguous sequence of characters. For example, in the string "abac", "aba" is a substring, but "aac" is not.


Given an input string s, your task is to find the length of the longest substring that contains only distinct (unique) characters.


Input Format:
The input consists of a single line containing the string s.


Output Format:
The output should be a single integer representing the length of the longest substring with all distinct characters.


Note:
If the input string is empty, the longest such substring has a length of 0.

If all characters in the string are the same, the longest such substring has a length of 1.