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

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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!