Created
January 5, 2026 14:17
-
-
Save chaosmonster/80b196254e7d367c68d0219f758f48c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // written while juggling a baby- not tested and not verified | |
| function maxScoreWithReset(nums) { | |
| let maxScore = 0; | |
| let aboveZero = false; | |
| let reset = false; | |
| for(const num in nums) { | |
| maxScore = maxScore + num; | |
| // only one reset allowed | |
| if (reset) { | |
| continue; | |
| } | |
| // we only reset once we were above zero at least once | |
| if (maxScore > 0 && !aboveZero) { | |
| aboveZero = true; | |
| } | |
| // reset when it's best for us | |
| if (aboveZero && maxScore < 0) { | |
| maxScore = 0; | |
| reset = true; | |
| } | |
| } | |
| return maxScore; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment