• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 13, 2022 |6.5K 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/