Given a list of integers, return the length of the longest run of consecutive equal values.
A run is a stretch of neighbouring positions that all hold the same value. If the list is null or empty, return 0.
Examples:
Input: nums = [1, 1, 2, 2, 2, 3]
Output: 3
Explanation: The three twos in the middle form the longest run
Input: nums = [7, 7, 7, 7]
Output: 4
Explanation: The whole list is one single run
Input: nums = [1, 2, 3]
Output: 1
Explanation: No value repeats so every run has length 1
Input: nums = [4, 4]
Output: 2
Explanation: The two fours sit next to each other
Input: nums = []
Output: 0
Explanation: An empty list has no runs at all
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay November 2026 (Nov 16–30)Sponsored by FLXBL
Contest runs November 16 - 30. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.