AlgoInsight

DSA problem

Guess the Word

HardStringsPattern: Interactive / Minimaxtop600GoogleAmazon

You are given an array of unique strings words where words[i] is six letters long. One of these strings will be a secret word that you must identify.

You are also given a helper object Master. You may call Master.guess(word) where word is a six-letter-long string, and it must be from words. Master.guess(word) returns:

There is a parameter allowedGuesses for each test case where allowedGuesses is the maximum number of times you can call Master.guess(word).

For each test case, you should call Master.guess with the secret word without exceeding the maximum number of allowed guesses. You will get:

Examples

Example 1
Input: secret = "acckzz", words = ["acckzz","ccbazz","eiowzz","abcczz"], allowedGuesses = 10
Output: You guessed the secret word correctly.
Explanation: master.guess("aaaaaa") returns -1, because "aaaaaa" is not in words. master.guess("acckzz") returns 6, because "acckzz" is secret and has all 6 matches. master.guess("ccbazz") returns 3. master.guess("eiowzz") returns 2. master.guess("abcczz") returns 4. We made 5 calls and found the secret, so we pass.
Example 2
Input: secret = "hamada", words = ["hamada","khaled"], allowedGuesses = 10
Output: You guessed the secret word correctly.
Explanation: The secret word is "hamada"; guessing it within the allowed number of calls passes the test.

Constraints

3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.

arraystringinteractivegame-theoryminimax

Browse all DSA problems