Problem 3: Gotta Max Profits

I’m a determined and ferocious trader on wall street. I only care about maximizing profits. An adaptive manipulator, I’m always the first person to react to (or rather to help my company adapt to) changes in the rules of the wall street money game. Yesterday, some rules pertaining to profits displays (on the floor of the main market) got changed.

Hitherto, maximum profits made by my company were displayed on the floor in a simple and intuitive way. So the only thing we needed to do to keep track of our max profits was to pipe the displayed maximum profits to our wall street data repository. But starting today, no maximum profits will be displayed. Only “crude” stock changes will be displayed. For example, the stock changes for the day (collected each hour) might look like this: [-2, 11, -4, 13, -5, 2].

Now I have to make some algorithm to compute the maximum profits I made during the day. For example, the maximum profit (from the data set above) is 20 over the subarray [11,-4,13].

Can you help construct an algorithm to solve this problem? I’m actually a good trader I promise.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s