CountHighlyProfitableMonths function Optimization

Joined
Dec 7, 2021
Messages
1
Reaction score
0
How would you guys optimize this code, im getting runtime error:

def countHighlyProfitableMonths(stockPrices, k):

profitable_groups = 0
profitable_group_boolean = 1
groups = [stockPrices[i:i+k] for i in range(len(stockPrices)-k+1)]

for group in groups:
for i in range(k-1):
profitable_group_boolean *= 1 if group[i+1]>group[i ] else 0
profitable_groups += profitable_group_boolean
profitable_group_boolean = 1

return profitable_groups
 
Last edited:
Joined
Mar 3, 2021
Messages
241
Reaction score
30
Hello! Can you please give an example of stockPrices and k that's causing the runtime error? Just making an array of random integers is returning a valid value (I can't interpret the value, so I can't say if it's correct or not). I'm also not 100% sure where the blocks are, can you slap your example code and data in a code tag? It also wouldn't hurt to have a general description of the algorithm so I can check it on paper while I test it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top