Accenture Coding Round Question – Arm Value

Problem Statement

You are given an array of N positive integers. The array has an Arm Value associated with it, which can be found using the following rules:

If the sum of all odd numbers in the array is odd, then
Arm Value = | (sum of all even numbers) – (sum of all odd numbers) |

If the sum of all odd numbers in the array is even, then
Arm Value = (sum of all even numbers) + (sum of all odd numbers)

Your task is to find and return an integer representing the Arm Value of the given array.

Input Format

First line: Integer N (size of array)

Second line: N space-separated integers (array elements)

Output Format

A single integer representing the Arm Value.

Example 1

Input:

5
1 2 3 4 5

Explanation:

Odd numbers = 1 + 3 + 5 = 9 (odd)

Even numbers = 2 + 4 = 6

Arm Value = |6 – 9| = 3

Output:

3

Comments (1)