← Discussions on Count Primes
M mchatterjee
31 Jul 2026, 18:35

Simple approach explained for beginners.

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

imran.n 2 months, 1 week ago

Thanks! The dry run on the second example made it click.

hdas 2 months, 1 week ago

This should be marked as the editorial approach honestly.

Sign in to reply.