TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

HatGame

Problem statement, definition, constraints, and public examples.

Problem Statement

You and your friend are playing a game. There are 12 pieces of paper in a hat numbered 1 through 12. Each of you randomly picks 6 pieces of paper from the hat and averages the values on the papers. Whoever has the higher average wins. Given 4 of the numbers you picked from the hat, determine how many combinations of 2 other numbers you can pick and win. Ties do not count as wins. Averages are computed as real numbers and not integers. See the examples for further clarifications.

Create a class HatGame that contains the method numWays, which takes an int[] nums, and returns an int that represents the number of ways to pick 2 other numbers and win.

Definition

Class:
HatGame
Method:
numGroups
Parameters:
int[]
Returns:
int
Method signature:
int numGroups(int[] nums)
(be sure your method is public)

Constraints

  • nums must contain 4 elements
  • Each element of nums must be between 1 and 12 inclusive
  • nums must not contain any duplicate values

Examples

  1. {1,2,3,4}
    Returns: 0
    There are no numbers you can pick that will allow you to beat the other player.
  2. {12,11,10,9}
    Returns: 28
  3. {1,4,8,12}
    Returns: 11
  4. {2,4,6,8}
    Returns: 5
  5. {1,12,2,11}
    Returns: 12
  6. {1,2,4,12}
    Returns: 1
Back to all problems