Solution: Bulls and Cows
Let’s solve the Bulls and Cows problem using the Hash Maps pattern.
We'll cover the following...
Statement
You are playing a number guessing game called “Bulls and Cows” with a friend.
You write down a secret
number, and your friend tries to guess
it. After each guess
, you provide a hint based on the following:
Bulls: The number of digits that are in the correct position in the
guess
.Cows: The number of digits that are in both the
secret
and theguess
but in different positions. (These are non-bull digits that could become bulls if rearranged.)
Your task is to return a hint for the guess
, formatted as “xAyB”, where: ...
Access this course and 1400+ top-rated courses and projects.