Connection Status:
Competition Arena > OddSum
Rookie SRM 10 · 2022-02-07 · by erinn · Brute Force
Class Name: OddSum
Return Type: int
Method Name: getSum
Arg Types: (vector<int>)
Problem Statement

Problem Statement

You are given a int[] x. Find the sum of all the odd integers in x.

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • Each element of x will be between 0 and 100, inclusive.
Examples
0)
{ 1, 2, 3 }
Returns: 4

Here, we want to include 1 and 3, but not 2. 1 + 3 = 4

1)
{ 2, 4, 6 }
Returns: 0

Here there are no odd elements at all, so our sum is 0.

2)
{ 8, 3, 3, 4 }
Returns: 6

Elements are not necessarily unique, and not necessarily sorted.

3)
{ 73, 82, 16, 47 }
Returns: 120
4)
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Returns: 25

Submissions are judged against all 6 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class OddSum with a public method int getSum(vector<int> x) · 6 test cases · 2 s / 256 MB per case

Submitting as anonymous