Question: Please let me know avout the answer! A binary array You are given a binary array A. A binary array contains only 0 and 1




A binary array You are given a binary array A. A binary array contains only 0 and 1 (1-based indexing). You can perform the following operation at most one times. Change an array element from 1 to 0. You are required to maximize the number of subarrays that contain at least one 0 and find the number of such subarrays that contain at least one 0 . Input format - The first line contains T denoting the number of test cases. - The first line of each test case contains N denoting the size of the binary array. - The next line of each test case contains N space-separated integers denoting array elements. Output format Print the maximum number of subarrays which will contain at least one 0 in a new line. Constraints: 1T1001N106 1T1001N105 A[i] will be either 0 or 1 Sample input G Sample output 251001171011101 Explanation For the first test case: Change A[4] from 1 to 0 . The new array will be [1,0,0,0,1]. The number of subarrays with at least one 0 are [0],[0],[0] [1,0],[0,0],[0,0),(0,1] [1,0,0],[0,0,0],[0,0,1] Therefore the answer is 3+4+3+2+1=13 Similarly, For the 2 nd test case if we change A[4] to 0 then the number of subarrays with at least one 0 will be 24 . The following test cases are the actual test cases of this question that may be used to evaluate your submission. Sample input 2 Sample output 2 4716060611011100010101616110111111 Limits Time Limit: 5.0sec(s) for each input file Memory Limit: 256 MB Source Limit: 1024 KB
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
