def count(a,b):#a's presence in b
n = 0
for i in range(len(b)):
if a == b[i]:
n += 1
return n
def comb(i,j):
if i == j:
return 1
elif j == 1:
return i
else:
c = comb(i-1,j-1) + comb(i-1,j)
return c
T = int(input())
for i in range(T):
N,K = map(int, input().split(" "))
A = list(map(int,input().split(" ")))
A.sort()
B = A[:K+1]
Z = B[-1]
cntZ = count(Z,B)
Y = count(Z,A)
print(comb(cntZ,Y))
why am i getting nzec error in this? works fie in my ide. please help
try :
def count(a,b):#a’s presence in b
n = 0
for i in range(len(b)):
if a == b[i]:
n += 1
return n
def comb(i,j):
if i == j:
return 1
elif j == 1:
return i
else:
c = comb(i-1,j-1) + comb(i-1,j)
return c
T = int(input())
for i in range(T):
N,K = map(int, input().split(" "))
A = list(map(int,input().split(" ")))
A.sort()
B = A[:K+1]
Z = B[-1]
cntZ = count(Z,B)
Y = count(Z,A)
print(comb(cntZ,Y))
python doesn’t give NZEC for no reason i’ve got it more than 25 times when i start codiung in python.don’t use try and except bcoz after that u will get wrong answer there must be some problem in list insexing like it might be going out of range or it can be anything try to do dry run for atleast 3 test cases.there is something wrong in your code