Number Guessing Game - Problem
Create an interactive number guessing game where the computer generates a random number between 1 and 100, and the player tries to guess it.
Game Rules:
- Generate a random number between 1-100 (inclusive)
- Player enters guesses one by one
- After each guess, provide feedback:
"Too high","Too low", or"Correct!" - When the correct number is guessed, display the total number of attempts
- The game ends when the player guesses correctly
Note: For this implementation, you'll receive the target number and a list of guesses, then return the sequence of feedback messages ending with the attempt count.
Input & Output
Example 1 — Basic Game
$
Input:
target = 67, guesses = [50, 80, 67]
›
Output:
["Too low", "Too high", "Correct!", "Attempts: 3"]
💡 Note:
First guess 50 is too low, second guess 80 is too high, third guess 67 is correct. Game ends after 3 attempts.
Example 2 — Quick Win
$
Input:
target = 42, guesses = [42]
›
Output:
["Correct!", "Attempts: 1"]
💡 Note:
Lucky first guess! Player gets it right immediately in just 1 attempt.
Example 3 — Longer Game
$
Input:
target = 25, guesses = [50, 30, 20, 25]
›
Output:
["Too high", "Too high", "Too low", "Correct!", "Attempts: 4"]
💡 Note:
Player gradually narrows down: 50 too high, 30 too high, 20 too low, finally 25 is correct after 4 attempts.
Constraints
- 1 ≤ target ≤ 100
- 1 ≤ guesses.length ≤ 20
- 1 ≤ guesses[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code