Question: Given a non-empty array arr with n integers both positive and negative, find the maximum sur contiguous subarray within arr which has the largest sum.
Given a non-empty array arr with n integers both positive and negative, find the maximum sur contiguous subarray within arr which has the largest sum. def solution (arr): max_so_far = arr[@] curr_max = arr[@] for 1 in range(1, len(arr)): curr max = max(arr[i], curr max + arr[i]) max_so_far = max(max so far, curr_max) return max so far What is the runtime of this solution (using big notation? On QA2| On 3) Ollogn)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
