Bulls and Cows

MediumSimulation

Description

Given the secret and your guess in the Bulls and Cows game, return the hint. Bulls: correct digit in correct place. Cows: correct digit in wrong place.

Examples

Input:secret = "1807", guess = "7810"
Output:"1A3B"
Explanation:

Position 3: '0' matches (1 bull). Digits 1,8,7 appear but in wrong positions (3 cows). Result: '1A3B'.

Input:secret = "5234", guess = "5678"
Output:"1A0B"
Explanation:

1 bull and 0 cows. The digit '5' is in the correct position (index 0), so it's a bull. None of the other digits in the guess (6, 7, 8) appear anywhere in the secret, so there are no cows.

Input:secret = "1122", guess = "2211"
Output:"0A4B"
Explanation:

0 bulls and 4 cows. No digits are in the correct positions, but all digits in the guess exist in the secret at different positions. The secret has two 1's and two 2's, and the guess also has two 1's and two 2's, all misplaced.

Constraints

  • 1 ≤ secret.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!