You are playing the Bulls and Cows game with your friend.

You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:


	The number of "bulls", which are digits in the guess that are in the correct position.
	The number of "cows", which are digits in the guess that are in your secret number but are located in the wrong position. Specifically, the non-bull digits in the guess that could be rearranged such that they become bulls.


Given the secret number secret and your friend's guess guess, return the hint for your friend's guess.

The hint should be formatted as "xAyB", where x is the number of bulls and y is the number of cows. Note that both secret and guess may contain duplicate digits.

&nbsp;
Example 1:

Input: secret = "1807", guess = "7810"
Output: "1A3B"
Explanation: Bulls are connected with a '|' and cows are underlined:
"1807"
  |
"7810"

Example 2:

Input: secret = "1123", guess = "0111"
Output: "1A1B"
Explanation: Bulls are connected with a '|' and cows are underlined:
"1123"        "1123"
  |      or     |
"0111"        "0111"
Note that only one of the two unmatched 1s is counted as a cow since the non-bull digits can only be rearranged to allow one 1 to be a bull.


&nbsp;
Constraints:


	1 &lt;= secret.length, guess.length &lt;= 1000
	secret.length == guess.length
	secret and guess consist of digits only.


class Solution:
    def getHint(self, secret: str, guess: str) -> str:
        
        # Setup counts for bulls and cows
        bulls = cows = 0
        
        # Copy secret and guess into lists that are easier to work with
        secretCopy = list(secret)
        guessCopy = list(guess)
        
        # In a for loop, check every pair of letters at the same index in both guess and secret for matching letters, AKA bulls
        for i in range(len(secret)):
            
            # If they match, bulls += 1 and pop() the letters from the copy lists via their .index()
            if secret[i] == guess[i]:
                bulls += 1
                secretCopy.pop(secretCopy.index(secret[i]))
                guessCopy.pop(guessCopy.index(guess[i]))
                
                
        # Count() the letters remaining in secret and guess lists
        secretCounter = Counter(secretCopy)
        guessCounter = Counter(guessCopy)
        
        # Counter1 - Counter2 gives us Counter1 with any matching values of Counter1 and Counter2 removed; leftover Counter2 values are trashed
        # secretCounter - guessCounter gives us the secretCounter except for any correctly guessed letters
        # Therefore, subtract this difference from the OG secretCounter to be left with a counter of only correctly guessed letters
        dif = secretCounter - (secretCounter - guessCounter)
        
        # The .total() of the dif Counter is the number of cows
        cows = dif.total()

        # return the formatted string with req. info
        return f'{bulls}A{cows}B'
class Solution {
    public String getHint(String secret, String guess) {
        int arr[] = new int[10], bulls = 0, cows = 0;
        for (int i = 0; i < secret.length(); i++) {
            char sec = secret.charAt(i);
            char gue = guess.charAt(i); 
            if (sec == gue) bulls++;
            else {
                if (arr[sec - '0'] < 0) cows++;
                if (arr[gue - '0'] > 0) cows++;
                arr[sec - '0']++;
                arr[gue - '0']--;
            }
        }
        return new StringBuilder(String.valueOf(bulls)).append("A").append(cows).append("B").toString();
    }
}
class Solution
{
public:
    string getHint(string secret, string guess)
    {
        int bulls = 0;
        vector<int> v1(10, 0);
        vector<int> v2(10, 0);
        for (int i = 0; i < secret.size(); ++i)
        {
            if (secret[i] == guess[i])
            {
                ++bulls;
            }
            else
            {
                ++v1[secret[i] - '0'];
                ++v2[guess[i] - '0'];
            }
        }
        int cows = 0;
        for (int i = 0; i < 10; ++i)
        {
            cows += min(v1[i], v2[i]);
        }
        return to_string(bulls) + "A" + to_string(cows) + "B";
    }
};
var getHint = function(secret, guess) {
    let ACount = 0, BCount = 0;
    const secretMap = new Map(), guessMap = new Map();
    for(let i = 0; i < secret.length; i++) {
        if(secret[i] == guess[i]) {
            ACount++;
        }
        else {
            if(secretMap.has(secret[i])) {
                secretMap.set(secret[i], secretMap.get(secret[i])+1);
            }
            else {
                secretMap.set(secret[i], 1);
            }
        }
    }
    for(let i = 0; i < guess.length; i++) {
        if(secret[i] !== guess[i]) {
            if(secretMap.get(guess[i]) > 0) {
                secretMap.set(guess[i], secretMap.get(guess[i])-1);
                BCount++;
            }
        }
    }
    return ACount+'A'+BCount+'B';
};
Bulls and Cows