#C13497. Longest Unique Subsequence

    ID: 43041 Type: Default 1000ms 256MiB

Longest Unique Subsequence

Longest Unique Subsequence

You are given a string s which may include spaces. Your task is to find the longest contiguous subsequence (i.e. substring) in which all characters are unique.

The method to obtain the subsequence is as follows: iterate over the string from left to right, and build a current subsequence by appending characters that have not been seen in the current segment. If a duplicate character is encountered, reset the current subsequence starting from the duplicate character. During the process, keep track of the longest subsequence found. For example, given the input s = "pwwkew", the longest unique subsequence is wke with length 3.

The time complexity of an efficient solution is \(O(n)\), where \(n\) is the length of the string.

Your solution should read from standard input (stdin) and write the result to standard output (stdout) in the format specified below.

inputFormat

Input: A single line containing the string s, which may include spaces. The input is provided via standard input (stdin).

outputFormat

Output: The output should consist of two parts written to standard output (stdout):

  • The first line is an integer representing the length of the longest unique subsequence.
  • The second line is the longest unique subsequence itself.
## sample
0

</p>