#C10645. Obtain Exactly k Consecutive Ones
Obtain Exactly k Consecutive Ones
Obtain Exactly k Consecutive Ones
You are given a binary string S of length \(n\) and an integer \(k\). Your task is to determine whether it is possible to obtain exactly \(k\) consecutive ones by applying a flip operation on some contiguous segment of length \(k\).
The flip operation works as follows: if the selected segment consists entirely of zeros, you may flip all bits to ones. If the segment already contains all ones, then no flip is necessary. In any other case, you cannot obtain exactly \(k\) consecutive ones by flipping that segment.
If there exists at least one contiguous segment of length \(k\) in S that is either all zeros or all ones, then the answer is YES; otherwise, it is NO.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains two integers (n) and (k) separated by a space, where (1 \leq k \leq n) and (n) is the length of the binary string. The second line contains the binary string (S) of length (n).
outputFormat
Output to standard output (stdout) a single line containing either "YES" if it is possible to obtain exactly (k) consecutive ones by flipping a contiguous segment, or "NO" if it is not possible.## sample
8 3
10001101
YES