Why is Melody so chocolaty?
Basic Accuracy: 0.0% Submissions: 3 Points: 1

Chunky gets happy by eating Melody.
Given an array of N elements, each element represents happiness chunky get by eating melody.
Chunky knows why melody is so chocolaty but will only tell you once you tell him the Max happiness he can get by eating two adjacent melodies.

Example 1:

​Input : arr[ ] = {1, 2, 3, 4, 5}
Output : 9
At index 0, arr[0] + arr[1] = 3
At index 1, arr[1] + arr[2] = 5
At index 2, arr[2] + arr[3] = 7
In this way, 9 will be the answer.

​Example 2:

Input : arr[ ] = {1, 2, 3, 4} 
Output :  7


Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function max_adjacent_sum() that takes an array (arr), sizeOfArray (n), and return the maximum happiness. The driver code takes care of the printing.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).


2 ≤ N ≤ 105
-107 ≤ A[i] ≤ 107

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Why is Melody so chocolaty?

Output Window