Build a Wordle-style game in React
Company: Ramp
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates proficiency in React-based front-end development, including state and component management, user interaction handling, and algorithmic skills for string comparison and duplicate-letter matching.
Constraints
- secret is a 5-letter English word containing only alphabetic characters
- 0 <= len(guesses) <= 10^4
- Only guesses of length 5 containing letters A-Z count toward the 6-attempt limit
- Processing stops immediately after a win or after 6 valid guesses
Examples
Input: ('CRANE', ['crane'])
Expected Output: {'history': [('CRANE', 'CCCCC')], 'status': 'win', 'secret': None}
Explanation: The first valid guess matches the secret exactly, so the player wins immediately.
Input: ('APPLE', ['ALLEY'])
Expected Output: {'history': [('ALLEY', 'CPAPA')], 'status': 'incomplete', 'secret': None}
Explanation: A is correct, the first L is present, the second L is absent because only one unmatched L remains in the secret, E is present, and Y is absent.
Input: ('MANGO', ['man', '12345', 'mang0', 'Mango', 'extra'])
Expected Output: {'history': [('MANGO', 'CCCCC')], 'status': 'win', 'secret': None}
Explanation: The first three submissions are invalid and ignored. 'Mango' is the first valid guess and wins the game. Later guesses are not processed.
Input: ('ROBOT', ['AAAAA', 'BBBBB', 'CCCCC', 'DDDDD', 'EEEEE', 'FFFFF', 'ROBOT'])
Expected Output: {'history': [('AAAAA', 'AAAAA'), ('BBBBB', 'AACAA'), ('CCCCC', 'AAAAA'), ('DDDDD', 'AAAAA'), ('EEEEE', 'AAAAA'), ('FFFFF', 'AAAAA')], 'status': 'game_over', 'secret': 'ROBOT'}
Explanation: After 6 valid guesses without finding the secret, the game ends and the secret is revealed. The 7th guess is ignored.
Input: ('TIGER', [])
Expected Output: {'history': [], 'status': 'incomplete', 'secret': None}
Explanation: No guesses were submitted, so the game is still incomplete.
Hints
- Use a two-pass approach for each guess: first mark exact matches, then use remaining letter counts to mark present letters.
- Keep a separate counter for valid guesses, since invalid submissions should be ignored and must not consume an attempt.