Max Consecutive Ones

Logic Building: Rotations & Sets DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Find the maximum number of consecutive 1's in a binary array, Arrays, Loops, Conditional Statements, Time Complexity, Space Complexity, Big O Notation, Frequency Counting, array traversal, state management, counting, time complexity analysis, Consecutive Elements, State Management in Arrays.

Problem Statement Given a binary array nums, return the maximum number of consecutive 1's in the array. Input Specification The input consists of a single line containing a list of integers, nums, where each element is either 0 or 1. Output Specification Return a single integer representing the maximum count of consecutive 1's. Constraints The array nums will only contain 0s and 1s. Sample Test Cases Sample Input 1: nums = [1, 1, 0, 1, 1, 1] Sample Output 1: 3 Explanation 1: There are two consecutive 1s and three consecutive 1s in the array, out of which the maximum is 3. Sample Input 2: nums = [1, 0, 1, 1, 0, 1] Sample Output 2: 2 Explanation 2: There are two consecutive 1's in the array.