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
240
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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top