Find the Longest Consecutive Run of Ones
Company: Molocoads
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Find the longest contiguous run of ones in a binary array under an explicit no-flips assumption. The prompt fixes empty-input behavior, a portable scalar return value, and two examples for later four-language console verification.
Read the full Molocoads Machine Learning Engineer interview experience this question came from
Constraints
- 0 <= nums.length <= 1,000,000
- Every element is the integer 0 or 1.
- No bit flips are permitted.
- Return 0 when nums is empty or contains no 1.
Examples
Input: ([],)
Expected Output: 0
Explanation: The empty array has no run of ones.
Input: ([0],)
Expected Output: 0
Explanation: A single zero has no run of ones.
Hints
- Keep the length of the run ending at the current element.
- A zero ends the current run, while the maximum found so far remains unchanged.