Can anyone explain the reason for runtime error in my python code
def solve(s,n,k):
s = sorted(s)
s = "".join(s)
if s[0] != s[k-1]:
print(s[k-1])
return
print(s[0],end ="")
if s[k] != s[n-1]:
print(s[k:])
else:
r = (n-1)//k
print(s[n-1]*r)
t = int(input())
for _ in range(t):
n,k = map(int,input().split())
s = input()
solve(s,n,k)
for the problem phoenix and distribution
You forgot k=n case