Guess the Word
master · 1865 · lc hard +32 · verified · 36.9% accepted · 1,631 likes · top 15%
Description
You have an array of unique 6-letter strings words. One of them is the secret word.
A helper object Master is available. Calling Master.guess(word) where word is a 6-letter string from words returns:
- -1 if word is not in words, or
- The number of positions where word and the secret word share the same character.
Each test case imposes an allowedGuesses limit on calls to Master.guess.
Complete the task by calling Master.guess with the secret word within the allowed number of guesses. You will receive:
- "Either you took too many guesses, or you did not find the secret word." if you exceed the limit or never guess correctly, or
- "You guessed the secret word correctly." if you identify it within the limit.
Test cases are constructed so that a reasonable strategy (not brute force) can always succeed.
Example 1:
Example 2:
Code