Bulls and Cows
You are playing Bulls and Cows. Given the secret number and the friend's guess as equal-length digit strings, return the hint as "xAyB": x bulls are digits correct in both value and position, and y cows are digits present in the secret but placed at a wrong position.
Open official problem prompt ↗Produce the bulls-and-cows hint counting exact matches and misplaced-but-present digits.
Like grading a lock-combination guess: dials that are exactly right are bulls, and dials whose number appears somewhere else on the real combination but in the wrong slot are cows.
- Input
- secret = "1807", guess = "7810"
- Output
- "1A3B"
- Why
- The 8 at index 1 is a bull; the digits 1, 0, and 7 exist in the secret but at different positions, giving 3 cows.
1 <= secret.length, guess.length <= 1000secret.length == guess.lengthsecret and guess consist of digits onlyguess and secret may contain duplicate digits