PROBLEM STATEMENT
Your office is having a lotto. Every employee is allowed to pick a number
between 1000 and 9999 inclusive, and whoever gets the correct number will win a
fabulous prize. In order to make this a "motivational" exercise, the HR
manager has been giving out hints to employees who work extra hard. By
overhearing these hints, you've managed to narrow the selection down to between
1 and 50 (inclusive) possible numbers. By consulting an astrological advisor,
you have also come up with a number between 1000 and 9999 that is supposed to
be your lucky number for that day. Write a program that will use that lucky
number to find out which of the options is the luckiest for you.
The luckiest number is a number that shares the most digits with your
luckyNumber. Digits can be repeated (ie if your lucky number is 1234, and one
of the options is 4444, that number shares all 4 digits with your lucky
number). This "sharing" is one way. If your lucky number is 4444 and the
option is 1234, they only share 1 digit. In the case that two or more of the
options share the same number of digits, the luckiest one is the one closest to
your lucky number. In the case that two numbers have the same number of shared
digits and are at an identical distance to your lucky number, then return the
smaller of the two numbers.
DEFINITION
Class name: Lotto
Method name: pickNums
Parameters: int[], int
Return type: int
Method signature: int pickNums( int[] options, int luckyNumber )
Be sure to make your method public.
TopCoder will ensure the validity of the inputs. Inputs are valid if all of
the following criteria are met:
options: 1-50 inclusive numbers between 1000 and 9999 inclusive with no repeats.
luckyNumber: a number between 1000 and 9999 inclusive.
EXAMPLES:
options { 1000, 2000, 3000, 4000 }, luckyNumber 1200
Returns 1000, because 1000 and 2000 both share 4 digits, but 1200 is only 200
away from 1000 and 800 away from 2000.
options { 1234, 4444, 9999 }, luckyNumber 5678
Returns 4444 because all 3 share 0 digits with luckyNumber, but 4444 is the
closest.
options { 1000, 3000 }, luckyNumber 2000
Returns 1000, because both 1000 and 3000 share 3 digits with 2000, both are
1000 away from 2000, and 1000 is the smaller number.