#C4898. Longest Unique Substring
Longest Unique Substring
Longest Unique Substring
Given a string s, find the longest contiguous substring of s that contains only unique characters (i.e. no repeating characters). If there are multiple substrings of the same maximum length, return the one that appears first in s.
The solution should read the input string from standard input (stdin) and write the result to standard output (stdout).
For example:
- Input:
abcabcbb
→ Output:abc
- Input:
pwwkew
→ Output:wke
- Input:
bbbbb
→ Output:b
The problem can be formulated mathematically as follows. Define a function f(s) such that \[ f(s)=\max_{0 \le i \le j \le |s|}\{ s[i:j] : \forall k,l,\, i \le k < l < j,\ s[k] \neq s[l] \}\] find f(s) and output this substring.
inputFormat
A single line string s is given via standard input. The string may be empty or contain spaces and various characters.
outputFormat
Output the longest substring of s that contains only unique characters. If the input string is empty, output an empty string. The result is printed to standard output.## sample
abcabcbb
abc