menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Count the ...
source image

Prodevelopertutorial

1w

read

194

img
dot

Count the number of 1’s in an array sorted in decreasing order.

  • The given problem is to count the number of 1's in an array that is sorted in decreasing order.
  • To solve this problem, we can use binary search.
  • We find the last occurrence of 1 in the array and return its index + 1 as the result.
  • If the mid index is not the last index of 1, we move towards the right half; otherwise, we move towards the left half.

Read Full Article

like

11 Likes

For uninterrupted reading, download the app