|
| 1 | +<h2><a href="https://leetcode.com/problems/guess-the-word/?envType=study-plan-v2&envId=google-spring-23-high-frequency">843. Guess the Worda>h2><h3>Hardh3><hr><p>You are given an array of unique strings <code>wordscode> where <code>words[i]code> is six letters long. One word of <code>wordscode> was chosen as a secret word.p> |
| 2 | + |
| 3 | +<p>You are also given the helper object <code>Mastercode>. You may call <code>Master.guess(word)code> where <code>wordcode> is a six-letter-long string, and it must be from <code>wordscode>. <code>Master.guess(word)code> returns:p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + -1 if word is not from words , or |
| 7 | + an integer representing the number of exact matches (value and position) of your guess to the secret word. |
| 8 | +ul> |
| 9 | + |
| 10 | +<p>There is a parameter <code>allowedGuessescode> for each test case where <code>allowedGuessescode> is the maximum number of times you can call <code>Master.guess(word)code>.p> |
| 11 | + |
| 12 | +<p>For each test case, you should call <code>Master.guesscode> with the secret word without exceeding the maximum number of allowed guesses. You will get:p> |
| 13 | + |
| 14 | +<ul> |
| 15 | + "Either you took too many guesses, or you did not find the secret word." if you called Master.guess more than allowedGuesses times or if you did not call Master.guess with the secret word, or |
| 16 | + "You guessed the secret word correctly." if you called Master.guess with the secret word with the number of calls to Master.guess less than or equal to allowedGuesses . |
| 17 | +ul> |
| 18 | + |
| 19 | +<p>The test cases are generated such that you can guess the secret word with a reasonable strategy (other than using the bruteforce method).p> |
| 20 | + |
| 21 | +<p> p> |
| 22 | +<p><strong class="example">Example 1:strong>p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:strong> secret = "acckzz", words = ["acckzz","ccbazz","eiowzz","abcczz"], allowedGuesses = 10 |
| 26 | +<strong>Output:strong> You guessed the secret word correctly. |
| 27 | +<strong>Explanation:strong> |
| 28 | +master.guess("aaaaaa") returns -1, because "aaaaaa" is not in wordlist. |
| 29 | +master.guess("acckzz") returns 6, because "acckzz" is secret and has all 6 matches. |
| 30 | +master.guess("ccbazz") returns 3, because "ccbazz" has 3 matches. |
| 31 | +master.guess("eiowzz") returns 2, because "eiowzz" has 2 matches. |
| 32 | +master.guess("abcczz") returns 4, because "abcczz" has 4 matches. |
| 33 | +We made 5 calls to master.guess, and one of them was the secret, so we pass the test case. |
| 34 | +pre> |
| 35 | + |
| 36 | +<p><strong class="example">Example 2:strong>p> |
| 37 | + |
| 38 | +<pre> |
| 39 | +<strong>Input:strong> secret = "hamada", words = ["hamada","khaled"], allowedGuesses = 10 |
| 40 | +<strong>Output:strong> You guessed the secret word correctly. |
| 41 | +<strong>Explanation:strong> Since there are two words, you can guess both. |
| 42 | +pre> |
| 43 | + |
| 44 | +<p> p> |
| 45 | +<p><strong>Constraints:strong>p> |
| 46 | + |
| 47 | +<ul> |
| 48 | + 1 <= words.length <= 100 |
| 49 | + words[i].length == 6 |
| 50 | + words[i] consist of lowercase English letters. |
| 51 | + All the strings of wordlist are unique. |
| 52 | + secret exists in words . |
| 53 | + 10 <= allowedGuesses <= 30 |
| 54 | +ul> |
0 commit comments