LeetCode 485 – Max Consecutive Ones
#leetcode #datastructures #arrays
LeetCode 485 – Max Consecutive Ones
Given a binary array, return the maximum number of consecutive 1s present in the array.
Example:
Input: [1,1,0,1,1,1]
Output: 3
Approach:
Traverse the array once. Keep a count of current consecutive 1s. Whenever you encounter a 0, reset the count. Continuously update the maximum count found so far.
Time Complexity: O(n)
Space Complexity: O(1)
A simple yet important array problem that teaches counting patterns and linear traversal.
#LeetCode
#DataStructures
#Arrays
#CodingInterview
#Programming
Comments
Comments from the original post on Instagram
No comments yet
