← Discussions on Max Consecutive Ones
A aaravsingh
10 Jul 2026, 18:04

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.

3 replies

pgupta 3 months ago

Watch out for integer overflow in Java on the large test.

kavyasub5 3 months ago

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

ritikabose 2 months, 4 weeks ago

This should be marked as the editorial approach honestly.

Sign in to reply.