Company: Agoda_20april
Difficulty: medium
Count Valid Prefix Sequences 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 valid 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 valid non-empty prefix sequences of the given binary sequence. Notes: A sequence is a subsequence if it can be obtained by deleting digits (possibly none) without altering the relative positions. 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. Function Description Complete the function calculateTotalPrefix in the editor with the following parameters: string sequence : the binary sequence int k : the number of "10" subsequences desired Returns int : the total number of non-empty prefix sequences of