You write down a secret number and your friend makes a guess of the same length. The hint reports bulls, the digits in the guess that are in the correct position, and cows, the digits that appear in the secret but in a different position and that are not already bulls (each secret digit can be matched at most once). Given secret and guess, return the hint as "xAyB", where x is the number of bulls and y is the number of cows. Both strings may contain duplicate digits.
You write down a secret number and your friend makes a guess of the same length. The hint reports bulls, the digits in the guess that are in the correct position, and cows, the digits that appear in the secret but in a different position and that are not already bulls (each secret digit can be matched at most once). Given secret and guess, return the hint as "xAyB", where x is the number of bulls and y is the number of cows. Both strings may contain duplicate digits.
Example 1:
Input: {"secret":"1807","guess":"7810"}
Output: 1A3B
Constraints:
1≤secret.length,guess.length≤1000
secret.length == guess.length
secret and guess consist of digits only.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"secret":"1807","guess":"7810"}
Walk both strings together. Same digit in the same spot is a bull; otherwise park the digits in count[] so a later position can pair them up as cows.
A secret digit that finds guess copies waiting (count < 0) is a cow, and so is a guess digit that finds secret copies waiting (count > 0). Each copy is used once.