nums = [-5,2,4,1,2,3]


dp = [[0 for i in range(len(nums))] for j in range(len(nums))]

for i in range(0, len(nums)):
    dp[i][i] = nums[i]

for i in range(0, len(nums)):
    for j in range(i+1, len(nums)):
        dp[i][j] = dp[i][j-1] * nums[j]

max = dp[0][0]

for i in dp:
    for j in i:
        if j > max:
            max = j

print(max)

print(dp)

 Public
Share a link to this review

22.73% issue ratio

O23 Calculated multiple times

Calculating something multiple times is redundant - use variables to store result of some calculation.

len() is called multiple times

L50 Reinventing a wheel

Whatever you want to code, usually someone has already done that. And usually there are some tools to cover your case. And usually you can find them using Google.

[0] * 5 == [0, 0, 0, 0, 0]

Suggested change:
length = len(nums)
dp = [ [0] * length for _ in range(length)]
L12 Redundant code / overengineering

This code is not really needed or may be simplified

range() already starts with 0

Suggested change:
for i in range(len(nums)):
L50 Reinventing a wheel

Whatever you want to code, usually someone has already done that. And usually there are some tools to cover your case. And usually you can find them using Google.

To count maximum of all elements, just use max() function on all the elements.

Suggested change:
from itertools import chain

all_elements = chain.from_iterable(dp)
max_value = max(all_elements)
R40 Overwriting builtins

Never overwrite built-in names, like list, sum or max - if later someone wants to use built-in function, he will find it replaced with your variable. If you really need to use one of those names, append underscore: sum_ = 15.


Create new review request