256. Bulls and Cows

MediumStringString

You play the Bulls and Cows guessing game. Given a secret number and a friend's guess (both digit strings of equal length), return a hint in the format 'xAyB' where x is the number of bulls (correct digit in the correct position) and y is the number of cows (correct digit, wrong position). Input: '"secret", "guess"'.

Input: '"secret", "guess"'.

Output: Quoted string — the hint 'xAyB'.

Examples

Example 1
Input: "1807", "7810"
Output: "1A3B"
Explanation: 1 bull (8), 3 cows.
Example 2
Input: "1123", "0111"
Output: "1A1B"
Explanation: 1 bull, 1 cow.
Example 3
Input: "1234", "1234"
Output: "4A0B"
Explanation: All bulls.

Constraints

Asked by

GoogleAmazonBloombergMeta
Solve this problem in the editor →