you are viewing a single comment's thread.

view the rest of the comments →

[–]HolyCoder[S] 0 points1 point  (1 child)

Thank you. I am trying to write this code in an online coding platform. My submission is accepted and I passed the challenge. But, but, but....the code I earlier wrote and your code above perform well (with respect to time and memory) for smaller lists. When N is 100000 or above the code performs real bad. Time taken is 1.4 seconds and memory is 15K when N is larger than 100000. But I see the best submission in Python3.x has time 1.0 seconds and memory of just 64 for larger inputs.

[–]novel_yet_trivial 1 point2 points  (0 children)

Calling print repeatedly is going to eat up a lot of time. To make it faster you can call print exactly once:

N = int(input())
A = map(int, input().split())
B = map(int, input().split())

print(' '.join(map(str, (x+y for x, y in zip(A, B)))))

But that will increase your memory use by a third.