June 13, 2022 |17.7K Views

    Count 1’s in a sorted binary array

    Description
    Discussion

    Given a binary array sorted in non-increasing order, count the number of 1’s in it.

    Examples:

    Input: arr[] = {1, 1, 0, 0, 0, 0, 0}
    Output: 2

    Input: arr[] = {1, 1, 1, 1, 1, 1, 1}
    Output: 7

    Input: arr[] = {0, 0, 0, 0, 0, 0, 0}
    Output: 0

    Count 1’s in a sorted binary array : https://www.geeksforgeeks.org/count-1s-sorted-binary-array/