Count 1's in binary array(Contest)
Count 1's in binary array easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Count 1's in binary array easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement :
Given a binary sorted non-increasing array arr of size N. You need to print the count of 1's in the binary array.
Try to solve the problem using binary search Input The input line contains T, denotes the number of testcases. Each test case contains two lines. The first line contains N (size of binary array). The second line contains N elements of binary array separated by space.
Constraints: 1 <= T <= 100 1 <= N <= 10^6 arr[i] = 0,1
Sum of N over all testcases does not exceed 10^6 Output For each testcase in new line, print the count 1's in binary array. Example Input: 2 8 1 1 1 1 1 0 0 0 8 1 1 0 0 0 0 0 0
Output: 5 2
Explanation: Testcase 1: Number of 1's in given binary array : 1 1 1 1 1 0 0 0 is 5. Testcase 2: Number of 1's in given binary array : 1 1 0 0 0 0 0 0 is 2.
link: