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.
fromitertoolsimportcombinationsN=int(input())letters=input().split()K=int(input())#Creating list of letters with r=Kcombos=list(combinations(letters,K))#Incrementing value of count by 1 if 'a' found in ccount=sum(1forcincombosif'a'inc)#Calculating count by total no. of c(tuples) in combos and rounding up to 3 decimal placesprint(f"{count/len(combos):.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 →