Not Even Max Sum
Practice
3.9 (10 votes)
Greedy algorithms
Basics of greedy algorithms
Algorithms
Problem
44% Success 4778 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) of size \(N\) where \(A_i \) is a positive integer at \(i^{th} \) position.. Find out the maximum sum of the elements that can be obtained which is not even. If the sum can never be not even return \(0\)

Task

Find out the maximum sum of the elements that are not even.

Example

\(N = 5 \)
\(A = [7, 4, 4, 4, 6] \)

Approach:

First, we find the sum of all the elements which in this case is \(25 \). Since the sum is odd and we have to find the maximum sum that is not even, it is the final answer.

Function description

Complete the function solve provided in the editor. This function takes the following two-parameter and returns the required answer:

\(N\): number of elements in the array.
\(A\): a list containing positive integers. 

Input Format:

The first line contains an integer \(T\) denoting the number of test cases
For each test case:
The first line contains the integer \(N \), the size of the array \(A\)
The second line contains the \(N\) spaced positive integer values.

Output Format:
For each test case, print the answer in a new line.

Constraints:

\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^{5} \\ 1 \leq A_i \leq 10^8\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
2 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms
Points:10
48 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Points:10
3 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsSortingAlgorithmsMerge Sort