I am getting partially correct answer. Can anybody please tell me what case I am missing?
Thanks in advance!
My Code Link: CodeChef: Practical coding for everyone
Your solution fails for S=âtvrâ and R=âttvrâ.
Correct answer for this test case is âttvrâ but code outputs âtvrtâ.
thank you harry_game
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đ
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â