Maximum calorie
Medium Accuracy: 38.47% Submissions: 26 Points: 4

Given an array Arr of size N, each element of the array represents the amount of calories, the task is to calculate the maximum of amount of calories you can get remembering the fact that you cannot take three consecutive calories.

Example 1:

Input: N = 5, arr[] = {3, 2, 1, 10, 3}
Output: 18
Explanation: You can take 1st, 2nd, 4th 
and 5th calories (3 + 2 + 10 + 3) = 18

Example 2:

Input: N = 2, arr[] = {8, 15}
Output: 23
Explanation: You can take 1st and 2nd
calories (8 + 15) = 23

Your Task: 
You don't need to read input or print anything. Complete the function maxCalories() which takes N  and array Arr as input parameter and returns an integer value.

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

Constraints:
1 ≤ N ≤ 105

1 ≤ Arr[i] ≤ 104

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.