We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
String Transmission
String Transmission
Sort by
recency
|
28 Discussions
|
Please Login in order to post a comment
This problem should be a DP problem not bit Manipulation.
Here is String Transmission problem solution in Python Java C++ and c programming - https://programs.programmingoneonone.com/2021/07/hackerrank-string-transmission-problem-solution.html
/python
T = int(input()) M = 1000000007
from math import factorial, sqrt
def nck(n, k): res = 0
def divisors(n): d1 = [1] d2 = [] for i in range(2, int(sqrt(n)) + 1): if n % i == 0: d1.append(i) if i*i != n: d2.append(n//i)
d1.extend(d2[::-1]) return d1
for _ in range(T):
for those who didnt unsderstood the question
in the input we are given with length(n) and number of bits we can flip in this binary representation (k)...
now for a particular test case we need to find the count such that after flipping the binary digit; the resultant binary digit is not periodic.
eg first test case ...... 001 and k = 1
now flip the 0 with 1 (flip the first digit) we get 101 ...this is aperiodic so count ++; (google definition of aperiodic string) now flip the second digit and youll get 011 ....aperiodic...count++;
remember you can only flip the <=k digits in given binary representation
if k == 3; you need to flip from 1 <= k <= 3......and check the aperiodics
C++ Solution