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.
[lenth,que]=input().split(" ");
lenth=int(lenth);
que=int(que);
num=input();
ans=[];
for i in range(0,lenth):
if int(num[i])==0:
ans.append(int(num[i]));
continue;
for j in range(i+1,lenth+1):
ans.append(int(num[i]+num[i+1:j]));
ans.sort();
for i in range(que):
print((ans[int(input())-1])%(10**9+7));
Can you tell me what is wrong in the code?
Test case 6 onwards this code is not working. It is failing due to time out.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Stacy numbers
You are viewing a single comment's thread. Return to all comments →
[lenth,que]=input().split(" "); lenth=int(lenth); que=int(que); num=input(); ans=[]; for i in range(0,lenth): if int(num[i])==0: ans.append(int(num[i])); continue; for j in range(i+1,lenth+1): ans.append(int(num[i]+num[i+1:j])); ans.sort(); for i in range(que): print((ans[int(input())-1])%(10**9+7));
Can you tell me what is wrong in the code? Test case 6 onwards this code is not working. It is failing due to time out.