Longest Run of Ones
Updated
Problem statement
You are given an array nums that holds only 0s and 1s.
Return the length of the longest block of 1s that sit next to each other with no 0 between them. If the array has no 1, return 0.
Function
longestOnesRun(nums: int[]) → intExamples
Example 1
nums = [1,1,1,0,0,1,1,0]return = 3The runs of 1s have lengths 3 (at the start) and 2. The longest is 3.
Example 2
nums = [0,0,0]return = 0There is no 1 at all, so the longest run has length 0.
Example 3
nums = [1,0,1,0,1,1,1,1]return = 4The runs have lengths 1, 1 and 4. The longest run is the one that reaches the end of the array.
Constraints
1 <= nums.length <= 10^4- Each
nums[i]is0or1
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Best Stock Trade with Buy and Sell DaysGoogle · PHONE SCREENGoogle interview questions
- Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Total Years of Work ExperienceLinkedIn · PHONE SCREENLinkedIn interview questions
- Array-Backed Set Without Library CollectionsOde with Anthropic · PHONE SCREEN
- Find Unique ElementsCisco · PHONE SCREENCisco interview questions
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions