← 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 month, 3 weeks ago

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

akash_70 1 month, 3 weeks ago

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

vsaxena 1 month, 3 weeks ago

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

Sign in to reply.