Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Bulls and Cows

XPChallenge Points: 20
levelLevel: Medium

You are playing a number-guessing game with your friend.
You write down a secret number, and your friend tries to guess it.
After each guess, you must give feedback in the form of bulls and cows:
• A bull šŸ‚ means a digit in the guess is correct and in the right position.
• A cow šŸ„ means a digit is present in the secret number but in the wrong position.
Your task is to calculate and return the result in the format:
"<bulls>A<cows>B",
where:
• bulls = count of digits that match in both value and position
• cows = count of digits that exist in the secret but in a different position
Both secret and guess may contain duplicate digits.

Example 1:

Input: secret = "4291" guess = "1234"

Output: "1A2B"

Example 2:

Input: secret = "5568" guess = "6555"

Output: "1A2B"

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result