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.
defsolve(n,k,s):# Write your code herevalid_pairs=0counter=[0]*(n+1)# at counter[i] there will be count of 1s upto ifori,bitinenumerate(s):counter[i+1]=counter[i]+int(bit)p=0fori,bitinenumerate(s):ifbit=="1":p+=counter[min(n,i+k+1)]-counter[max(0,i-k)]total_pairs=n*ngcd_val=math.gcd(p,total_pairs)numerator=p//gcd_valdenominator=total_pairs//gcd_valreturnf"{numerator}/{denominator}"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Probability
You are viewing a single comment's thread. Return to all comments →