Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Maybe because some programmers are programmed to program programmatically... rather than to think ;)
such problems don't score well on CW :(
@k2bralex - the input array represents the time series of the price of a company stock/share.
For simplicity, consider case with only 2 time periods - say
[3,17]
.If you bought one stock at time t=0 (index 0) and sold it at time t=1 (index 1) you would make a profit of 17 - 3 = 14. This is the maximum possible profit you can make with this input array.
Now if there are, say, 3 time periods - it becomes a bit more difficult:
[3,8,17]
for example: this allows you to buy one stock at time t=0 at price 3, and buy another stock at time t=1, at price 8, and then sell both stocks at time t=2 for price 17. What is total profit you made? It is (17-3) + (17-8) in this case.Now even more complicated is case like in description:
[ 1, 2, 10, 3, 2, 7, 3, 2 ]
where you might have to buy and sell at multiple times.I`m looking at this task 15 minutes and cant understand what is a process(((
The new example test case is added ;)
maybe 46?
This comment is hidden because it contains spoiler information about the solution