Statistics

Problem Statement for "MissingDwarf"

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

Definition

Class:
MissingDwarf
Method:
getHeight
Parameters:
int[]
Returns:
int
Method signature:
int getHeight(int[] otherHeights)
(be sure your method is public)

Constraints

  • otherHeights will contain exactly 6 elements.
  • Each element of otherHeights will be between 1 and 1000, inclusive.

Examples

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

  2. {6,5,4,3,2,1}

    Returns: 7

    The six heights can be given in any order.

  3. {10,10,20,20,30,30}

    Returns: 34

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

  4. {7,7,7,7,7,7}

    Returns: 14

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

  5. {1000,1000,1000,1000,1000,1000}

    Returns: 1007

  6. {1000,1000,997,1000,1000,1000}

    Returns: 1003

  7. {353,545,432,325,42,425}

    Returns: 552

  8. {353,545,432,325,43,425}

    Returns: 551

  9. {353,545,432,325,44,425}

    Returns: 550

  10. {353,545,432,325,45,425}

    Returns: 549

  11. {353,545,432,325,46,425}

    Returns: 548

  12. {353,545,432,325,47,425}

    Returns: 547

  13. {353,545,432,325,48,425}

    Returns: 546

  14. {7, 7, 7, 7, 7, 7 }

    Returns: 14

  15. {1000, 1000, 1000, 1000, 1000, 1000 }

    Returns: 1007

  16. {10, 10, 20, 20, 30, 30 }

    Returns: 34

  17. {6, 6, 6, 6, 6, 6 }

    Returns: 13


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: