← 返回 tesla 的题目列表Guess the Word (Master API)
类型:online_judge
You need to find a secret 6-letter word by calling an API master.guess(word) a limited number of times.
You are given a list wordlist of unique 6-letter words. The secret word is guaranteed to be in wordlist.
API:
master.guess(word: str) -> int
Given a guessed word, returns the number of positions (0 to 6) where the guessed word matches the secret word exactly.
You can call master.guess at most 10 times.
Implement:
findSecretWord(wordlist, master) -> None
Your goal is to find the secret word within 10 guesses as reliably as possible.
Constraints/Notes:
len(wordlist) can be large (assume ~100–1000 in interviews).
This is an interactive-style problem: after each guess, you must narrow down candidates.
Explain how you choose the next word to guess and how you filter candidates based on the returned match count.
Follow-up:
If you cannot use position-wise character frequency counters to score/select guesses, what alternative strategy would you use? Describe the idea and its complexity.
Example
Input
(interactive)
wordlist = ["acckzz","ccbazz","eiowzz","abcczz"]
secret = "acckzz"
max_calls = 10
Output
A valid run should call master.guess no more than 10 times and eventually guess "acckzz" (match count 6).