#K2601. Minimum Operations to Convert a Binary String to All Ones
Minimum Operations to Convert a Binary String to All Ones
Minimum Operations to Convert a Binary String to All Ones
You are given a binary string \( S \) consisting of characters '0' and '1'. Your task is to determine the minimum number of operations required to convert the entire string into all '1's. An operation is defined as follows: if the string contains at least one '0', you can perform a single operation to flip all the '0's to '1's.
Formally, let \( S \) be a binary string. The answer is given by:
[ \text{ans} = \begin{cases} 0, & \text{if } S \text{ contains no } 0,\ 1, & \text{if } S \text{ contains at least one } 0. \end{cases} ]
Note that if the string is empty, consider the answer to be 0.
inputFormat
The input is given via standard input (stdin) and consists of two parts:
- An integer \( N \) which denotes the length of the binary string \( S \). \( N \) can be 0.
- A binary string \( S \) of length \( N \) (this part is omitted if \( N = 0 \)).
Elements are separated by whitespace.
outputFormat
Output a single integer representing the minimum number of operations required to convert the given string into all '1's. The output should be printed to standard output (stdout).
## sample7 1111111
0