Max Consecutive Ones in Binary Array

Easy
6
70.4% Acceptance

In this lab, you will be working on finding the maximum number of consecutive 1's in a given binary array.

You are given a binary array nums, and your task is to return the maximum number of consecutive 1's in the array. The task must be implemented using the ES6 module system (import/export).

Example 1:

Input: nums = [1, 1, 0, 1, 1, 1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.

Example 2:

Input: nums = [1, 0, 1, 1, 0, 1]
Output: 2
Explanation: The second and third digits, or the fifth and sixth digits, are consecutive 1s. The maximum number of consecutive 1s is 2.

Example 3:

Input: nums = [0, 0, 0, 0, 0]
Output: 0
Explanation: There are no consecutive 1s in the given array. The maximum number of consecutive 1s is 0.

Constraints:

  • 1 <= nums.length <= 105
  • nums[i] is either 0 or 1.

Your goal is to implement the findMaxConsecutiveOnes function that takes an array of binary numbers and returns the maximum number of consecutive 1's in the array. It should follow the ESM import/export scheme.

Challenges

  1. Implement the findMaxConsecutiveOnes function and export it properly.
  2. Test your function on various inputs, ensuring it satisfies the given constraints and correctly calculates the maximum number of consecutive 1's.