Skip to content

Fix sequence counting across separated zeros - #102

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-sequence-counter-overcounting-issue
Closed

Fix sequence counting across separated zeros#102
krotname wants to merge 1 commit into
mainfrom
codex/fix-sequence-counter-overcounting-issue

Conversation

@krotname

@krotname krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The existing maximumSequenceWithOneZero implementation accumulated runs across multiple non-consecutive zeros and returned incorrect results for inputs like [1, 0, 1, 0, 1].

Description

  • Replace the single accumulating counter with previousCount and currentCount and compute maxCount as previousCount + currentCount while iterating, so only a single zero-separated pair contributes to the sum.
  • Remove the unnecessary ArrayList copy and add a regression test shouldNotCountAcrossMultipleSeparatedZeros in MaximumSequenceWithOneZeroTest.java that asserts maximumSequenceWithOneZero(List.of(1, 0, 1, 0, 1)) == 2.

Testing

  • Ran the focused unit test with mvn -q -Dtest=interview.MaximumSequenceWithOneZeroTest test and it passed.
  • Ran the full test suite with mvn -q test and mvn -q verify, both completed without failures.

Codex Task

@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the validated combined merge in #115: #115

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-sequence-counter-overcounting-issue branch August 1, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant