All About the Money
If you're viewing this on the Challenge Zone website, you can click here to open the challenge in a new tab.
Scenario
Suppose you have an array for which the m element is the price of a given stock on the n day. Since you are a relatively new investor and stock trader, you want to take things slowly when you buy and sell shares of a stock. In other words, you only complete one transaction (i.e: you buy and sell one share of a stock) on a given day.
Task
Your task is to write a function optimizedProfit
which finds the max profit of your transaction. Your function should accept an input of type Array
that contains prices for a stock. The function is expected to return an Integer
which is the max profit of your transaction.
Note/Tips: you cannot sell a stock before you buy one. Also, your selling price should be larger than your buying price in order to achieve the max profit possible!
optimizedProfit
The optimizedProfit
function should accept an Array
arguement and return an Integer
value.
Sample Results
Explanation
Your function should work for any Array
argument. DO NOT HARDCODE!