← Discussions on Intersection of Two Arrays
G gurpreet_92 OFFICIAL
25 Jul 2026, 18:58

Why does my solution TLE on the last test case?

A single pass with a running value is enough here. Keep track of the best answer so far and update it as you scan, which gives O(n) time and O(1) extra space.

2 replies

saibose 2 months, 2 weeks ago

This should be marked as the editorial approach honestly.

shegde 2 months, 2 weeks ago

For the TLE: you are rebuilding the list inside the loop, move it outside.

Sign in to reply.