Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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: 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started