Sum21
Rookie SRM 16 · 2022-08-22 · by erinn
Rookie SRM 16 · 2022-08-22 · by erinn · Simple Math, Simple Search, Iteration
Problem Statement
Problem Statement
You are given a list of integers in
Notes
- In the case of duplicate integers appearing in the list, each one may be used separately (see example #2).
Constraints
- x will contain between 1 and 50 elements, inclusive.
- Each element of x will be between 1 and 20, inclusive.
Examples
0)
{ 1, 20 }
Returns: 1
This is the simplest case, where the only thing to do is take both elements, which thus add up to 21.
1)
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Returns: 0
There's a lot of choices, but no pair will add up to 21.
2)
{ 10, 10, 11, 11 }
Returns: 4
There's a total of four ways to select a pair that adds to 21.
3)
{ 18, 3, 6, 17, 9, 4, 2, 11, 8, 19 }
Returns: 3
4)
{ 18, 3, 6, 17, 9, 4, 2, 11, 8, 19, 3, 6, 17, 9, 4, 2, 11, 8, 19 }
Returns: 10
5)
{ 8 }
Returns: 0
There's no way to even select a pair of numbers when there's only one in the list.
Submissions are judged against all 13 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Sum21 with a public method int countWays(vector<int> x) · 13 test cases · 2 s / 256 MB per case