Question: I want in python Given a binary array arr[] of size n. The array contains only 0 and 1 . You can perform the following
![I want in python Given a binary array arr[] of size](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66e0631076a14_45566e0630fd3fac.jpg)




I want in python
Given a binary array arr[] of size n. The array contains only 0 and 1 . You can perform the following operation atmost once: Select any subarray from the given array and flip all its elements i.e. change 0 to 1 and 1 to 0 . After the operation, find the length of the largest subarray containing all 1s. Example 1: Example 1: Input : n=5 arr ={1,,,,1} Output: 5 Explanation: After applying the flip operation on subarray {,,} the array becomes {1,1,1,1,1}. Therefore, the largest possible subarray with all 1 s has length 5. Input : n=4 arr={,1,1,} Output: 3 Explanation: The optimal way is to choose subarray arr[:] that is {} and flip it to 1 so finally array becomes {1,1,1,0}. So the answer is 3 . so finally array becomes {1,1,1,0}. So the answer is 3 . Your Task: You don't need to read input or print anything. Your task is to complete the function toggle() which takes an integer n, anchan integer array arr as input parameters and returns the length of the largest subarray which has all 1 in it. Constraints: 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
