Connection Status:
Competition Arena > MissingDwarf
TCO19 SRM 754 · 2019-03-25 · by misof · Simple Math, Simple Search, Iteration
Class Name: MissingDwarf
Return Type: int
Method Name: getHeight
Arg Types: (vector<int>)
Problem Statement

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 int[] otherHeights. The elements of otherHeights are the heights of the other six dwarves. Determine the height of the missing dwarf. As there are always multiple possibilitities, return the smallest one that matches the information you have. (After all, dwarves are small.)

Constraints

  • otherHeights will contain exactly 6 elements.
  • Each element of otherHeights will be between 1 and 1000, inclusive.
Examples
0)
{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.)

1)
{6,5,4,3,2,1}
Returns: 7

The six heights can be given in any order.

2)
{10,10,20,20,30,30}
Returns: 34

Sometimes some of the six heights given as the input can be equal.

3)
{7,7,7,7,7,7}
Returns: 14

The missing dwarf must be taller than each of the six remaining dwarves.

4)
{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.

Coding Area

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

Submitting as anonymous