← Discussions on Find the Balance Index
B bhavanasub3 OFFICIAL
30 Sep 2026, 05:33

Clean C++ solution, beats most submissions.

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

tarunrao 1 week, 5 days ago

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

akash_70 1 week, 4 days ago

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

vsaxena 1 week, 3 days ago

Nice. Got asked a variant of this in an interview.

Sign in to reply.