# Who can explain the definition of bulls and cow, I am confused by the question?

• In this case: only one digit 1 is counted, and it is unmatched for all the place, so 0A1B.

Input:
"1234"
"0111"
Output:
"0A3B"
Expected:
"0A1B"

In this case: two digits, 1, and 2, both are in wrong place, so I think it should be 0A2B, but the answer is 0A4B, so it double counts the unmatched digits. This really confused me.

Input:
"1122"
"2211"
Output:
"0A2B"
Expected:
"0A4B"

I think I misunderstood the rule of "bull and cow", could someone explain this? Thanks.

• The problem description is not ideal. Both bulls and cows are defined for "pair", which is a pair of identical digit from secret and guess.

For example, there is a pair of '1' that is not matching in "1234" and 0111", hence the result is 0A1B. Whilst in "1122" and "2211", there are 2 pairs of '1's and 2 pairs '2's. Because the 2 '1's and 2 '2's are not matching pairs, we have 4 bulls.

• In case "1122" "2211", obviously you got all the right digits (two 1s and two 2s), but none of them is in the right place. So the result is "0A4B"

• I think there are 2 steps.
Step1: find the right digits.
Step2: determine whether those digits are in the right place or not.

In case "1122" "2211", obviously you got all the right digits (two 1s and two 2s), but none of them is in the right place. So the result is "0A4B"

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.