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.
frommathimportcomb# Read inputN=int(input())letters=input().split()K=int(input())# Count occurrences of 'a'count_a=letters.count('a')# Calculate probabilityifcount_a==0:probability=0else:# Probability of not selecting any 'a'prob_no_a=comb(N-count_a,K)/comb(N,K)# Probability of selecting at least one 'a'probability=1-prob_no_a# Output resultprint(f"{probability:.4f}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Iterables and Iterators
You are viewing a single comment's thread. Return to all comments →