FastPrepMastermind Guess Score
Problems/Mastermind Guess Score

Mastermind Guess Score

Zillow logoZillow● EasyFULLTIMEOAPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow in 2011 and 2019. In 2011 a candidate posted written answers to a set of Zillow questions; one question was scoring a guess in a four-ball color game, with one worked example. In 2019 a Senior Software Development Engineer candidate named Mastermind as the technical question of an interview with a director and called it a very old question.

The 2011 question gives the four balls, the four colors, the two counts and the example, which writes each code as four color letters. Here we settle repeated colors and the return form: each ball counts at most once and a location ball is never also a color; the two codes arrive as two string arguments, the colors are the four letters its example uses (R, G, B, Y), every input is valid, and the function returns [locations, colors]. These choices are ours. We read the 2019 Mastermind question as the same scoring task, which is our assumption. The 2011 answers were written up as files with runnable code, so we read that set as a take-home and place the task in an online assessment; we file the 2019 interview as a phone screen. Both placements are our reading.

Our version is about 90% the same as the reported question.

A code is a row of four balls. Each ball has one of four colors, written as a letter: R (red), G (green), B (blue) or Y (yellow). One code is the hidden solution, and a player tries a guess code. Both are strings of four letters, and spot i of a code is its character at index i.

The game answers the guess with two counts:

  • Locations: the number of spots where the guess has the same color as the solution.
  • Colors: the number of other guess balls whose color is in the solution, but at a different spot.

Each ball is counted at most once. A ball counted as a location is not counted again as a color. After the locations are removed, each color adds to the colors count the smaller of two numbers: how many of its balls are left in the solution and how many are left in the guess.

Return [locations, colors]. A guess equal to the solution gives [4,0].

Function

masterMind(solution: String, guess: String) → int[]

Examples

Example 1

solution = "BGRR"guess = "RGYY"return = [1,1]

Spot 1 is G in both codes, so there is 1 location. The left-over solution balls are B, R, R and the left-over guess balls are R, Y, Y. Only red is in both: 2 red balls in the solution and 1 in the guess, so it adds 1 color. Yellow is not in the solution. The answer is [1,1].

Example 2

solution = "RGBY"guess = "RGBY"return = [4,0]

The guess equals the solution, so all 4 spots are locations and no ball is left over for colors.

Example 3

solution = "RGBY"guess = "RRRR"return = [1,0]

Spot 0 is red in both codes, so there is 1 location. The solution has no other red ball, so the other three red guess balls add no color. The answer is [1,0].

Example 4

solution = "RRGG"guess = "GGRR"return = [0,4]

No spot matches. The two red balls of the guess match the two red balls of the solution, and the two green balls match the two green balls, so there are 4 colors.

Constraints

  • solution.length == 4
  • guess.length == 4
  • solution and guess consist only of the letters 'R', 'G', 'B' and 'Y'.

More Zillow interview questions

  • Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 2021
  • First Subarray with the Largest SumOA · ONSITE INTERVIEW · Seen Aug 2021
  • Reverse StringOA · PHONE SCREEN · Seen Sep 2019
  • Sort Objects by a FieldOA · Seen Aug 2018
  • Convert a String to a LongOA · Seen Jan 2018
  • Insert and Delete in a Trinary TreeOA · Seen May 2016
  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
  • Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023

Similar questions at other companies

  • Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • First Letter to Appear TwiceCisco · PHONE SCREENCisco interview questions
  • Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int[] masterMind(String solution, String guess) {
        // Write your code here.
    }
}
Checking account…