Given a list of integers, return a new list of the same length where each element at position i is the maximum value seen in the input from position 0 through position i. Return null for null input and an empty list for empty input.
Examples:
Input: nums = [3, 1, 4, 1, 5, 9, 2, 6]
Output: [3, 3, 4, 4, 5, 9, 9, 9]
Explanation: At each index, the running max is: max(3)=3, max(3,1)=3, max(3,1,4)=4, etc.
Input: nums = [5, 4, 3, 2, 1]
Output: [5, 5, 5, 5, 5]
Explanation: The first element is the largest, so all running maxes equal 5
Input: nums = [1, 2, 3, 4, 5]
Output: [1, 2, 3, 4, 5]
Explanation: Each new element is larger than the previous, so the running max matches each element
Input: nums = [42]
Output: [42]
Explanation: Single element list
Input: nums = []
Output: []
Explanation: Empty list returns empty list
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 August 2026
Contest runs August 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.