Step 3: Solve Problems on Arrays [Easy -> Medium -> Hard]›Easy
Maximum Consecutive Ones & The Winning Streak
EasyFunction: maximumConsecutiveOnes()
ASCI Mission Breakdown • Simple as Hell
"Find the maximum number of consecutive 1s in a binary array."
Real-World Metaphor:
Think of flipping a coin. You want to see what is your longest consecutive streak of heads before a tail interrupts you.
Interactive Visual WalkthroughARRAY-POINTERS
Step 1 / 3
Matches: [1, 1, 0, 1, 1, 1]
1
[0]
streak
1
[1]
0
[2]
1
[3]
1
[4]
1
[5]
Memory Notepad / State Tracker
Current Streak:2
Max Streak:2
Evaluating
1. First Winning Streak
First two matches are wins: streak = 2, max = 2.
How to Think About This (Mental Model)
Keep two counters: currentStreak = 0, maxStreak = 0.
Iterate through the array:
If num === 1, currentStreak++, maxStreak = Math.max(maxStreak, currentStreak).
If num === 0, currentStreak resets to 0.
Return maxStreak.
### The Mission
Imagine tracking a game where `1` represents a win and `0` represents a loss in an array of match results: `[1, 1, 0, 1, 1, 1]`.
Your mission is to calculate the **longest uninterrupted winning streak** (maximum consecutive 1s) achieved throughout the season.
Examples
Example 1
Input: nums = [1,2,3,4,5]
Output: 15
Constraints
1 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9
Topic Tags:
Solve Problems on Arrays [Easy -> Medium -> Hard]EasymaximumConsecutiveOnes