PROBLEM STATEMENT
GooberBall is similar to soccer except that each time a goal is scored, the
amount of points awarded to the scoring team is chosen at random for a
collection of previously determined positive integers. The game ends either
when one team has scored 1000 points or more, or until both teams decide to
stop playing.
Unfortunately, GooberBall stadium does not have a score board and each team is
responsible for keeping track of their own score under the honor system. An
increasing number of GooberBall teams have been violated the honor code,
evidenced by claims of achieving impossible scores given the possible score
set. You will be writing a program to try to flush out a few of these cheaters.
Create a class GooberBall that contains the method cheater, which takes as
arguments an int[] scoreSet representing the possible points awarded during a
goal, and return the largest integer UNDER 1000 which can not be achieved as a
score.
DEFINITION
Class: GooberBall
Parameters: int[]
Returns: int
Method Signature: int cheater (int[] scoreSet)
Be sure to declare your method public.
NOTES
- Keep in mind that if every score from 0 to 999 can be achieved, then -1 is
the largest integer.
- Teams start with a score of 0, so 0 can always be achieved.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of the
following criteria are met:
- elements of scoreSet are ints from 1-1000 inclusive
- scoreSet will contain from 1 to 15 elements inclusive
- scoreSet will not contain repeat ints (if scoreSet[i] == scoreSet[j], then i
== j)
EXAMPLES
Example: {4, 7, 11}
The following positive scores are not achievable: 1, 2, 3, 5, 6, 9, 10, 13, 17
All of the other scores from 0 to 999 are achievable, for example, 18 = 11 + 7,
19 = 11 + 4 + 4, etc.
Returns 17
Example2: {1, 2, 5, 10}
Returns -1
Example3: {3, 6, 9}
Returns 998