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.
n = int(input()) # Length of the list
letters = input().split() # List of letters
k = int(input()) # Number of indices to select
comb = list(combinations(letters, k))
favorable = sum(1 for group in comb if 'a' in group)
probability = favorable / len(comb)
print(f"{probability:.3f}")
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 →
n = int(input()) # Length of the list letters = input().split() # List of letters k = int(input()) # Number of indices to select
comb = list(combinations(letters, k)) favorable = sum(1 for group in comb if 'a' in group) probability = favorable / len(comb) print(f"{probability:.3f}")