← Discussions on Count Primes
H hkapoor
25 Jun 2026, 16:33

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.

1 reply

poojamenon 3 months, 2 weeks ago

Same idea, but I used a deque. Works fine.

Sign in to reply.