DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Array

Max Consecutive Ones

**Problem Statement:** Given a binary array `nums`, return the maximum number of consecutive `1`s in the array. **Hint / Expected Approach:** Single-pass counter reset **Edge Cases to Consider:** - (1) All ones - (2) All zeros - (3) Single element

Examples

Example 1
Input: [1, 1, 0, 1, 1, 1]
Output: 3
Example 2
Input: [1, 0, 1, 1, 0, 1]
Output: 2
Example 3
Input: [1]
Output: 1

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪All ones
  • ▪All zeros
  • ▪Single element
Frequently Asked At
MicrosoftAmazonTCSWipro