#K76472. Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters
Given a string s, your task is to find the longest substring of s that contains no repeating characters. If there are multiple substrings with the maximum length, the substring that appears first in s should be returned.
The problem can be mathematically described as follows: given a string \( s \), find indices \( i \) and \( j \) (with \( 0 \leq i \leq j < |s| \)) such that the substring \( s[i \ldots j] \) has all unique characters and \( j - i + 1 \) is maximized. If there exists another substring with the same maximum length, choose the one with the smallest starting index.
Examples:
- For
s = "abcabcbb"
, the answer is"abc"
. - For
s = "bbbbb"
, the answer is"b"
. - For
s = "pwwkew"
, the answer is"wke"
.
inputFormat
The input consists of a single string s provided via standard input (stdin). The string can contain letters, digits, and special characters.
Input Format:
s
outputFormat
Output the longest substring of s with all unique characters to standard output (stdout). If s is empty, output an empty string.
Output Format:
substring## sample
abcabcbb
abc