{"id":"4fdea595-68b2-4828-b7b6-abc876b004ad","name":"Maximum Consecutive Ones - 1","description":"1. You are given an array(arr) which contains only 0's and 1's.\r\n2. You have to find the maximum number of consecutive 1's in the given array if you can flip at most one zero.","inputFormat":"A number N\r\narr1\r\narr2... N numbers","outputFormat":"A number representing maximum number of consecutive 1's after flipping at most one zero.","constraints":"1 &lt;= N &lt;= 10^5\r\n0 &lt;= arr[i] &lt;= 1","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr) {\n //write your code here\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<int>arr(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n };\n\n cout << solution(arr);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr){\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n \r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n System.out.println(solution(arr));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n1 1 0 0 1 1","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/ix_TazzqHn0?end=211","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"37c50f50-23aa-4796-82a2-7cce20d18999","name":"Maximum Consecutive Ones - 1","slug":"maximum-consecutive-ones-1","type":1}],"next":{"id":"75bacd44-6edc-4df8-9f37-358a3e774475","name":"Maximum Consecutive Ones - 1 MCQ","type":0,"slug":"maximum-consecutive-ones-1-mcq"},"prev":{"id":"b5ddf4b5-4562-4949-84f5-1c299e5105bc","name":"Equivalent Subarrays","type":3,"slug":"equivalent-subarrays"}}}

Maximum Consecutive Ones - 1

1. You are given an array(arr) which contains only 0's and 1's. 2. You have to find the maximum number of consecutive 1's in the given array if you can flip at most one zero.

{"id":"4fdea595-68b2-4828-b7b6-abc876b004ad","name":"Maximum Consecutive Ones - 1","description":"1. You are given an array(arr) which contains only 0's and 1's.\r\n2. You have to find the maximum number of consecutive 1's in the given array if you can flip at most one zero.","inputFormat":"A number N\r\narr1\r\narr2... N numbers","outputFormat":"A number representing maximum number of consecutive 1's after flipping at most one zero.","constraints":"1 &lt;= N &lt;= 10^5\r\n0 &lt;= arr[i] &lt;= 1","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(vector<int> arr) {\n //write your code here\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<int>arr(n, 0);\n for (int i = 0; i < n; i++)\n {\n cin >> arr[i];\n };\n\n cout << solution(arr);\n return 0;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static int solution(int[] arr){\r\n // write your code here\r\n\r\n return 0;\r\n }\r\n \r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n System.out.println(solution(arr));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"6\r\n1 1 0 0 1 1","sampleOutput":"3\r\n","questionVideo":"https://www.youtube.com/embed/ix_TazzqHn0?end=211","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"37c50f50-23aa-4796-82a2-7cce20d18999","name":"Maximum Consecutive Ones - 1","slug":"maximum-consecutive-ones-1","type":1}],"next":{"id":"75bacd44-6edc-4df8-9f37-358a3e774475","name":"Maximum Consecutive Ones - 1 MCQ","type":0,"slug":"maximum-consecutive-ones-1-mcq"},"prev":{"id":"b5ddf4b5-4562-4949-84f5-1c299e5105bc","name":"Equivalent Subarrays","type":3,"slug":"equivalent-subarrays"}}}
plane

Editor


Loading...

Maximum Consecutive Ones - 1

easy

1. You are given an array(arr) which contains only 0's and 1's. 2. You have to find the maximum number of consecutive 1's in the given array if you can flip at most one zero.

Constraints

1 <= N <= 10^5 0 <= arr[i] <= 1

Format

Input

A number N arr1 arr2... N numbers

Output

A number representing maximum number of consecutive 1's after flipping at most one zero.

Example

Sample Input

6 1 1 0 0 1 1

Sample Output

3

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode