You are viewing a single comment's thread. Return to all comments →
Would it possible to optimise this, many testcase failing due to time complexity, as its time complexity is O(n^3)
def solve(a, queries): res = [] for q in queries: sum = 0 for i in range(q[0]-1,q[1]): sum += a[i] for j in range(i+1,q[1]): sum += max(a[i:j+1]) res.append(sum) return res
Seems like cookies are disabled on this browser, please enable them to open this website
Sum of the Maximums
You are viewing a single comment's thread. Return to all comments →
Would it possible to optimise this, many testcase failing due to time complexity, as its time complexity is O(n^3)