kesar
BAN USER- 0of 0 votes
AnswersYou are given a binary array with N elements: d[0], d[1], ... d[N - 1].
- kesar in United States
You can perform AT MOST one move on the array: choose any two integers [L, R], and flip all the elements between (and including) the L-th and R-th bits. L and R represent the left-most and right-most index of the bits marking the boundaries of the segment which you have decided to flip.
What is the maximum number of '1'-bits (indicated by S) which you can obtain in the final bit-string?
'Flipping' a bit means, that a 0 is transformed to a 1 and a 1 is transformed to a 0 (0->1,1->0).
Input Format
An integer N
Next line contains the N bits, separated by spaces: d[0] d[1] ... d[N - 1]
Output:
S
Constraints:
1 <= N <= 100000
d[i] can only be 0 or 1f
0 <= L <= R < n
Sample Input:
8
1 0 0 1 0 0 1 0
Sample Output:
6
Explanation:
We can get a maximum of 6 ones in the given binary array by performing either of the following operations:
Flip [1, 5] ==> 1 1 1 0 1 1 1 0| Report Duplicate | Flag | PURGE
VMWare Inc Problem Solving
Repellabryan25416, Accountant at A9
Hello, I am a Managing editor. I have completed my studies from New York. Apart from this, whenever I am ...
Repednaheeks, Android test engineer at Automated Traders Desk
I am Edna, a blogger . As an editor with a strong background in English and Hindi language. I enjoy writing ...
RepHayleyGuez, Malwarebytes customer service at CDK Global
I am Hayley , a freelance artist with 7 years of experience in creating impressionist works. My most recent work was ...
RepGlennaJames, Android test engineer at Accenture
Glenna , an illustrator for more than 8 years in California . I also feel I could have an actual understanding of ...
Repsophiaddelano, Android Engineer at 247quickbookshelp
Extensive experience setting up, installing, and maintaining a variety of audio equipment. I Work with loudspeakers, amplifiers,microphones, and more ...
Rephejalbbelans299, Animator at ABC TECH SUPPORT
Professional agile project manager with over 2 years of experience in various facets of project management. Implement agile management ideals ...
Repstephenroach41, Android Engineer at Alliance Global Servies
Experienced and professional facilities coordinator with a commitment to customer service. An analytical business person as well as a practiced ...
Repwilsontrent895, Android Engineer at Accenture
My name is WilsonTrent . I am working at A.J. August Fashion Wear as a Physician . Here I am helping ...
RepChloeKing, Accountant at A9
I like to snowboard, rock climb, and water ski. I volunteer some of my time each spring and summer to ...
RepEllaFlores, Associate at Alcatel Lucent
Ella , a Tour bus driver in Sounds Great company Inc. A charter bus driver is responsible for providing comfortable and ...
RepMarlinThomas, Backend Developer at ASAPInfosystemsPvtLtd
I am Marlin, an industrial maintenance mechanic. I can help you create a job listing. Feel free to revise, add ...
Repjuanitasfalbo45, Android Engineer at 247quickbookshelp
Hey, Juanita Falbo, and I am working as a Yoga instructor. And nowadays I am doing a new experiment on ...
RepAndreTmily, Area Sales Manager at Axiom Sources
A purchasing manager, also known as a purchasing director or supply manager, responsible for procuring goods and services for resale ...
RepAveryPerez, abc at 8x8
I am a self-driven and motivated librarian skilled at providing excellent public service to students and staff, managing the library ...
RepEllaScotz, abc at A9
I am a creative designer with innovative ideas and a unique approach to visuals. I am also a skilled painter ...
RepYuvaanMoore, abc at 8x8
I have extensive experience as a newspaper reporter, television news reporter, AM radio talk show host and anchorman for major ...
RepRianaHudge, Integration Software Engineer at Autoportal.com
Riana , a caring and compassionate Home Health Aide with more than 7 years of experience in providing daily living and ...
Repericsumm059, Backend Developer at ASU
My name is EricSummey . I am working as a Sound engineering technician at Foreman & Clark . as a sound technician it ...
RepOllieObrien, Financial Application Engineer at Accenture
Ollie , professional writer and translator with more than 4+ years of experience. I had a passion for lifelong learning about ...
RepKaiDolern, abc at 8x8
I am knowledgeable and agile legal assistant offering varied experience working as office assistant in a lawyer’s office and ...
RepAmyuDiaz, abc at 8x8
Professional cost accountant with several years of experience in accounting tasks such as maintaining inventory, calculating liability, budgeting labor costs ...
RepEileenWenda, DIGITAL MARKETING at Accenture
I am Eileen , a football Referee skilled at maintaining a safe environment for both players and observers, inspecting the playing ...
RepKeilyPrice, Applications Developer at 247quickbookshelp
I am a creative chef with 5 years of experience making the kitchen run efficiently. Collaborated with marketing specialists to ...
RepCathyCruz, Analyst at AMD
I am a highly responsible service station manager seeking an opportunity to work in a top company oy aid in ...
RepDeevaAllen, Android Engineer at Absolute Softech Ltd
I am Deeva, currently a Credit Card Authorizer , where I assess authorization requests for credit limit increases, and handle lost ...
Repvickidsmithv, Android Engineer at 247quickbookshelp
Hello, I am a Managing editor. I have completed my studies from New York. Apart from this, whenever I am ...
If array sorted descending order like 6,5,4,3,2,1 rotated like 3 2 1 6 5 4 then it fails.
- kesar February 02, 2014