As reported: Google L4 onsite, round 1 (US, 2025): a word guessing game. Player 1 picks a five-letter secret word with no duplicate letters; player 2 guesses, and each guess is scored out of 5 by how many of its letters exist in the secret word. Implement
score(secret, guess) -> int(score("teams", "abide")returns2);is_possible_guess(hist, guess): given the earlier guesses with their scores, is the guess a reasonable next guess; andnext_guess(hist) -> str: given the previous guesses and scores, what should player 2 guess. The function headers and usage were left for the candidate to define.
All words have exactly five distinct lowercase letters.
score(secret, guess)— the number of letters ofguessthat also appear insecret(position does not matter).isPossibleGuess(history, guess)—historyis a list of earlier(word, score)pairs. Returntrueifguesscould still be the secret: for every pair,score(guess, word)equals the recorded score.nextGuess(history)— given a word list, pick player 2's next guess. Discuss the strategy; this part is not judged.
Example
score("teams", "abide") -> 2 a and e
isPossibleGuess([("abide",2)], "teams") -> true
isPossibleGuess([("abide",2), ("teams",1)], "tears") -> false tears shares 4 letters with teams
isPossibleGuess([("crane",0)], "lofty") -> true
isPossibleGuess([("crane",0)], "abide") -> false a and e appear in crane
Clarifications
- Because neither word repeats a letter, the score is the size of the intersection of their letter sets — and it is symmetric.
- A guess that was already made with a score below 5 is never possible (it would score 5 against itself).
Constraints: up to 10^4 operations; histories of up to 50 pairs.
Code runner format: the first line is q, then q lines, either SCORE secret guess or POSSIBLE k w1 s1 … wk sk guess. Implement score(secret, guess) and isPossibleGuess(history, guess); the harness prints the number or true / false per line.