Cheating Codemaker
Updated
Problem statement
A secret code is a four-character string. Each character is one of R, O, Y, G, B, or P, and colors may repeat.
For a guess and a secret code, the response contains two integers:
- Exact matches: positions whose colors match exactly.
- Color matches: remaining colors that occur in both strings but at different positions.
Every character can contribute to at most one match. Count exact matches first, then match the remaining characters by color.
You are the codemaker, but you do not commit to one secret code at the beginning. A history of earlier guesses and responses is provided. A secret code is currently possible if its response to every earlier guess equals the corresponding earlier response.
Given the next guess, return the response that leaves the largest number of currently possible secret codes. In other words, group all currently possible codes by the response they would produce for guess and choose the largest group.
If several responses leave the same number of codes, choose the response with more exact matches. If there is still a tie, choose the response with more color matches.
Return [exactMatches, colorMatches].
Function
chooseResponse(guess: String, previousGuesses: List<String>, previousResponses: List<List<Integer>>) → int[]Examples
Example 1
guess = "RGBY"previousGuesses = []previousResponses = []return = [0,2]All 1,296 codes are initially possible. The response [0,2] is produced by 312 of them, more than any other response.
Example 2
guess = "GPPP"previousGuesses = ["RGBY","PPPP"]previousResponses = [[0,0],[3,0]]return = [2,1]The history leaves exactly GPPP, PGPP, PPGP, and PPPG. Three produce [2,1] for the new guess, while one produces [3,0].
Example 3
guess = "YYYY"previousGuesses = ["PPPP"]previousResponses = [[0,0]]return = [1,0]Responses [0,0] and [1,0] each leave 256 codes. The exact-match tie-break selects [1,0].
Example 4
guess = "RGBY"previousGuesses = ["RGBY"]previousResponses = [[4,0]]return = [4,0]The history identifies RGBY as the only possible code, so the response is forced.
Constraints
guess.length() == 4.- Every guess contains only
R,O,Y,G,B, andP. previousGuesses.size() == previousResponses.size().- Every earlier guess has length 4.
- Every earlier response contains two integers in the order
[exactMatches, colorMatches]. - The provided history is well-formed, internally consistent, and leaves at least one possible secret code.
More Jane Street interview questions
- Product Profit SummaryOA · Seen Sep 2026
- Bond Haircut by Ratings and MaturityOA · Seen Aug 2024
- Currency Haircut with FX ForwardsOA · Seen Aug 2024
- Transform StringOA · Seen Jul 2024
- Price Deviation AlertsOA · Seen Nov 2023
- Trade Blotter Summary by TickerOA · Seen Jun 2021
- Biggest Daily Move and Longest Rising StreakOA · ONSITE INTERVIEW · Seen Apr 2021
- Transaction Fees by InstrumentOA · Seen Mar 2018
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Incident MonitorStripe · OAStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Most Frequent Call Path in Interleaved LogsRoblox · ONSITE INTERVIEWRoblox interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Best Poker Category with a JokerScale AI · PHONE SCREEN · ONSITE INTERVIEWScale AI interview questions
- Find All Zip Rummy MeldsZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
- Credit Card Command ProcessorChime · PHONE SCREEN
Jane Street interview experiences
- Jane Street TDO UK and Hong Kong: 22 Experiences (Part 10 of 10)
- Jane Street TDOE US Final Round: 11 Experiences (Part 5 of 10)
- Jane Street TDO Phone Math Round: 26 Experiences (Part 9 of 10)
- Jane Street TDOE UK Phone Screen: 15 Experiences (Part 4 of 10)
- Jane Street TDO Excel and VBA Test: 23 Experiences (Part 8 of 10)
- Jane Street TDOE UK Coding Round: 15 Experiences (Part 3 of 10)