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.
import itertools
List=[]
count = 0
n = int(input())
l = input().split(" ")
k = int(input())
for i in range(len(l)):
if(l[i]=="a"):
List.append(i+1)
comb = list(itertools.combinations([i+1 for i in range(len(l))],k))
for i in comb:
for j in List:
s=""
if(j in i):
s+=" "
if(len(s)>=1):
count+=1
break
print(count/len(comb))
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 →
import itertools List=[] count = 0 n = int(input()) l = input().split(" ") k = int(input()) for i in range(len(l)): if(l[i]=="a"): List.append(i+1) comb = list(itertools.combinations([i+1 for i in range(len(l))],k)) for i in comb: for j in List: s="" if(j in i): s+=" " if(len(s)>=1): count+=1 break print(count/len(comb))