#K45197. Longest Valid Binary Subsequence
Longest Valid Binary Subsequence
Longest Valid Binary Subsequence
Given a binary string of length (n), determine the length of the longest subsequence that contains at least one '0' and at least one '1'.
If the binary string does not contain both characters, the answer is (0). Otherwise, you may take the entire string as the subsequence, and the answer is (n).
For example, for the input string "10011", the output is (5) since the string contains both '0' and '1'.
inputFormat
The input consists of two lines. The first line contains an integer (n), which is the length of the binary string. The second line contains the binary string (s) of length (n), consisting only of the characters '0' and '1'.
outputFormat
Output a single integer representing the length of the longest valid subsequence. If the binary string does not contain both '0' and '1', output (0).## sample
5
10011
5
</p>