adarshj322's blog

By adarshj322, history, 4 years ago, In English

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

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it