MissingDwarf
TCO19 SRM 754 · 2019-03-25 · by misof
Problem Statement
One of Snow White's seven dwarves has gone missing! She is sure he will turn up eventually, but she needs to know his height because she is knitting him a sweater. Here is what she remembers about the heights:
- The missing dwarf is strictly taller than any of the other six dwarves.
- The height of each dwarf is a positive integer.
- The average of all seven heights is also a positive integer.
You are given the
Constraints
- otherHeights will contain exactly 6 elements.
- Each element of otherHeights will be between 1 and 1000, inclusive.
{1,2,3,4,5,6}
Returns: 7
The height of the missing dwarf is 7. (The average height of a dwarf is exactly 4.)
{6,5,4,3,2,1}
Returns: 7
The six heights can be given in any order.
{10,10,20,20,30,30}
Returns: 34
Sometimes some of the six heights given as the input can be equal.
{7,7,7,7,7,7}
Returns: 14
The missing dwarf must be taller than each of the six remaining dwarves.
{1000,1000,1000,1000,1000,1000}
Returns: 1007
Submissions are judged against all 17 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MissingDwarf with a public method int getHeight(vector<int> otherHeights) · 17 test cases · 2 s / 256 MB per case