Practice/Google/Leetcode 843. Guess the Word
CodingMust
You are playing a word guessing game where you need to identify a secret word from a given list. All words in the list are exactly 6 characters long and contain only lowercase letters.
You have access to a Master API with a single method:
guess(word): Takes a word from the wordlist and returns an integer representing how many characters match the secret word in both value and position. For example, if the secret is "acckzz" and you guess "ccbazz", the API returns 3 because positions 2, 4, and 5 match (both have 'c', 'z', 'z' in those positions).Your task is to implement a function that uses the Master API to discover the secret word within a given number of allowed guesses. The challenge is to design an efficient strategy that narrows down candidates optimally.
findSecretWord(wordlist, master) that identifies the secret wordmaster.guess(word) API to obtain match informationExample 1:
` Input: wordlist = ["acckzz", "ccbazz", "eiowzz", "abcczz"], secret = "acckzz" Process:
Example 2:
` Input: wordlist = ["hamada", "khaled", "mahmud", "samira", "kamran"], secret = "hamada" Process:
Example 3:
` Input: wordlist = ["aaaaaa", "bbbbbb", "cccccc", "dddddd"], secret = "bbbbbb" Process: