Alexa is Amazon's virtual AI assistant. It makes it easy to set up your Alexa-enabled devices, listen to music, get weather updates, and much more. The team is working on a new feature that evaluates the aggregate temperature changes for a period based on the changes in temperature of previous and upcoming days.

Taking the change in temperature data of n days, the aggregate temperature change evaluated on the ith day is the maximum of the sum of the changes in temperatures until the ith day, and the sum of the change in temperatures in the next (n-i) days, with the ith day temperature change included in both.

Given the temperature data of n days, find the maximum aggregate temperature change evaluated among all the days.

Example

tempChange = [6, -2, 5]

The aggregate temperature on each day is evaluated as: see image.

The maximum aggregate temperature change is max(9, 4, 9) = 9.

Function Description

Complete the function getMaxAggregateTemperatureChange.

getMaxAggregateTemperatureChange has the following parameter:

int tempChange[n]: the temperature change data of n days

Returns

long: the maximum aggregate temperature change

Constraints

  • 1 <= n <= 10^5
  • -10^9 <= tempChnage[i] <= 10^9 where, 1 <= i <= n.

Sample Case 0

Sample Input For Custom Testing

STDIN   FUNCTION
----- --------
3 -> tempChange[] size n = 3
-1 -> tempChange = [-1, 2, 3]
2
3

Sample Output

5
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.