Good morning! Here's your coding interview problem for today.
This problem was asked by Facebook.
Mastermind is a two-player game in which the first player attempts to guess the secret code of the second. In this version, the code may be any six-digit number with all distinct digits.
Each turn the first player guesses some number, and the second player responds by saying how many digits in this number correctly matched their location in the secret code. For example, if the secret code were 123456, then a guess of 175286 would score two, since 1 and 6 were correctly placed.
Write an algorithm which, given a sequence of guesses and their scores, determines whether there exists some secret code that could have produced them.
For example, for the following scores you should return True, since they correspond to the secret code 123456:
{175286: 2, 293416: 3, 654321: 0}
However, it is impossible for any key to result in the following scores, so in this case you should return False:
Good morning! Here's your coding interview problem for today.
This problem was asked by Facebook.
Mastermind is a two-player game in which the first player attempts to guess the secret code of the second. In this version, the code may be any six-digit number with all distinct digits.
Each turn the first player guesses some number, and the second player responds by saying how many digits in this number correctly matched their location in the secret code. For example, if the secret code were
123456
, then a guess of175286
would score two, since1
and6
were correctly placed.Write an algorithm which, given a sequence of guesses and their scores, determines whether there exists some secret code that could have produced them.
For example, for the following scores you should return
True
, since they correspond to the secret code123456
:{175286: 2, 293416: 3, 654321: 0}
However, it is impossible for any key to result in the following scores, so in this case you should returnFalse
:{123456: 4, 345678: 4, 567890: 4}