I am getting RunTime Error(NZEC) in September 2019 LunchTime ALLSUB ..........please help me by pointing out where am going wrong

My [code] link.

All test cases mentioned in the question are getting passed but on submission am getting Runtime Error. Please help me by pin-pointing, probably in which test case i can get runtime error.

Add the topic pythonn , it may help

Therez no topic ‘Python’ as such

Did you check whether len(s) \leq len(r) before further processing, because if that’s not true, you’ve got to print Impossible. :slightly_smiling_face:

This condition is automatically handled when am setting flag in the first for loop. Isn’t it?
pls correct me if am wrong

Yes, you’re right. I’m not sure I really understand your logic. It’d be great if you could explain your logic in words. Also, I noticed that you used sorting. However, sorting is gonna take up too much time I guess. Maybe something is not quite right with the logic. You may also refer to this for the logic. I hope you find it helpful. :slightly_smiling_face:

1 Like

Wait a second! Does this loop (lines 33 - 36) come to a halt always?

while s[0] > temp[i]:
    ns = ns + temp[i] * c2[temp[i]]
    c2[temp[i]] = 0
    i += 1
1 Like

Test case:

1
zzab
zzaabb

Output:

Error:

Traceback (most recent call last):
  File "./prog.py", line 33, in <module>
    while s[0] > temp[i]:
IndexError: list index out of range

This is happening because by the time we reach line 33, temp stores ['a', 'b'], while s[0] stores z. The condition:

while s[0] > temp[i]:

keeps evaluates to True until we hit a value of i (2) that tries to access an element of temp (temp[2]) that really is out of its bounds. That’s giving rise to this error. :slightly_smiling_face:

1 Like

I got my mistake.
Finally got all AC.

Ty…Brother.