Company: citadel_3aug
Difficulty: medium
Count Good Prefixes Problem Description Given a binary sequence of length n as a string, perform the following operation any number of times: Append either a '0' or a '1' to the end of the sequence. A sequence is considered good if it is possible to make the total number of "10" subsequences in the updated sequence exactly equal to k . Your task is to count the total number of non-empty prefix sequences of the given binary sequence that are good . Notes: 1. A subsequence is a subsequence if it can be obtained by deleting digits from the sequence, possibly none, without altering the relative order. 2. A non-empty prefix sequence is any sequence derived by deleting digits from the end of the given sequence, ensuring the length of the prefix is at least 1. Examples Example 1: Input: sequence = "100", k = 1 Output: 2 Explanation: We analyze all non-empty prefixes of "100": Prefix "1": It has 0 "10" subsequences and one '1'. We need to reach k=1 . We can append a '0' to form "10", which has