Guess the Word
Updated
Problem statement
You are given an array words of distinct six-letter lowercase words and a secret word that appears in words.
A guess receives the number of positions whose letters exactly match secret. Simulate the following solver for at most 10 guesses:
- Start with every word as a possible secret.
- For each possible guess among the current candidates, group the current candidates by the feedback they would give, from
0through6. - For each guess, find the size of its largest group. Choose the guess with the smallest such size. Break ties by lexicographically smaller word.
- If all six positions match, return the one-based guess number. Otherwise retain only candidates with the observed feedback and continue.
Return -1 if this solver does not guess secret within ten attempts.
Function
guessesToFindSecret(words: String[], secret: String) → intExamples
Example 1
words = ["acckzz","ccbazz","eiowzz","abcczz"]secret = "acckzz"return = 1The minimax rule chooses acckzz first because every feedback bucket has size at most one.
Example 2
words = ["acckzz","ccbazz","eiowzz","abcczz"]secret = "eiowzz"return = 2The first guess acckzz receives feedback 2, leaving only eiowzz, which is guessed next.
Example 3
words = ["aaaaaa","bbbbbb","cccccc"]secret = "cccccc"return = 3Every distinct pair has feedback zero, so lexicographic tie-breaking guesses aaaaaa, then bbbbbb, then cccccc.
Constraints
1 <= words.length <= 100.- Every word has exactly six lowercase English letters.
- All words are distinct.
secretappears inwords.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Balance a Chemical EquationMicrosoft · OA
- Binary CircuitAkuna Capital · OA
- Parse, Normalize, and Combine PolynomialsSquarepoint Capital · PHONE SCREEN
- Minimum Numeric Code TransformationAdobe · OA
- Good SubsequencesNutanix · OA
- Break a PalindromeRoblox · OA
- Minimize Expression with ParenthesesPinterest · OA
- Signed Digit Partitions Reaching a TargetMeta · PHONE SCREEN
- String Transformation (Also for Infra Automation Intern)Snowflake · OA
- Sum of All ValuesFlexport · OA