Problem statement

https://binarysearch.com/problems/Wolves-of-Wall-Street/

Solution

Equal to Leetcode 0122 Best Time to Buy and Sell Stock II.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, nums):
        diffs = [y - x for x, y in zip(nums, nums[1:])]
        return sum(max(0, x) for x in diffs)