Counting Zeros in a Sorted Array

Reported in interviews at Akuna Capital

Problem statement

Given a sorted array that may contain zeros, count how many zeros it holds. You are expected to beat a linear scan.

Example

count_zeros([-1, 1]) -> 0
Show hint

What property of a sorted array lets you locate a boundary without looking at every element?

Relevant roles: ML Engineer, Forward Deployed Engineer and AI Engineer.

Related free problems