# All Substring Help needed

I am getting partially correct answer. Can anybody please tell me what case I am missing?
My Code Link: https://www.codechef.com/viewsolution/26842954

Your solution fails for S=âtvrâ and R=âttvrâ.
Correct answer for this test case is âttvrâ but code outputs âtvrtâ.

1 Like

thank you harry_game

1 Like

Where do you think mine goes wrong?

The strings âsâ and ârâ can be 1e5 digits longâŚ so try using long in place of intâŚ

Your code fails for S=âbcâ and R=âabbcâ.
Correct answer is âabbcâ but your code shows âabcbâ

Hey @harry_game it would be great if you could share you thought process behind coming up with these corner casesâŚ

I tried like this:
Suppose two strings are R and S,initialise ans="" then finding the characters in R which are smaller than S[0] and storing in ans after that pushing the S in the ans after that storing all left characters in the ans in smallest lexicographical order,but i m getting wrong answer .can anybody explain what is wrong with this logic and how to come up to generalised solutionđ

1 Like

where did i go wrong?

Why is this giving segmentation error?
https://www.codechef.com/viewsolution/26848720

It is giving correct answers, in all the above test cases. Can someone please tell me, why is it giving wrong answer on submission?

``````t=int(input())
for _ in range(t):
s=list(input().strip())
r=list(input().strip())
d={}
f={}
o=0
for i in s:
try:
d[i]+=1
except Exception:
d[i]=1
#print(d)
for i in r:
try:
f[i]+=1
except Exception:
f[i]=1
#print(f)
for x in d:
try:
if(d[x]>f[x]):
o=1
break
else:
f[x]-=d[x]
except Exception:
o=1
break
if o==1:
print("Impossible")
else:
l=[]
for x in f:
for h in range(f[x]):
l.append(x)
l.append(''.join(s))
l=sorted(l)
print(''.join(l))``````

that will not always work. you have to take care of equality with s[0]. consider two examples
suppose s=âbcâ and r=âaabbcâ
then ans must be âaabbcâ
now suppose s=âbaâ and r=âaabbaâ
then ans must be âaababâ