Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Nous sommes désolés de vous informer que quelque chose s'est mal passé. Qu'est-il arrivé ?

book
One Flip Game

Bob likes to play his game on paper. He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak for which their positions are in range [i, j] (that is i ≤ k ≤ j). Flip the value of ak means to apply operation ak = 1 - ak.

The goal of the game is that after exactly one move to obtain the maximum number of ones.

Given a list of 0 or 1. Return the maximal number of 1s that can be obtained after exactly one move.

Example 1

Input:

[1, 0, 0, 0, 1, 0, 0, 0]

Output:

7
main.c

main.c

c

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt