Anyone help in codeforces problem

iam getting TLE in my problem.But my code takes just o(n) times.means just traversing the input string.but i cant understand why giving TLE?
problem link is

my solution is

It’s not just input

val1=int(a)
val2=int(b)

This is your culprit

1 Like

I think the problem is comparison. When you compare two strings it doesn’t take O(1) time like integers. In worst case scenario your comparison itself takes O(n). I’d suggest you try another approach.

First off, you can figure out which number is larger based on the first digit where they are different. Also string concatenation is slow. And converting string to int is slow, and input is taken faster using sys.stdin.readline()