Bulls and Cows
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
In a guessing game, one player holds a secret digit string secret and the other submits a guess of the same length. The feedback reports two numbers:
- **bulls**: positions where guess has exactly the same digit as secret.
- **cows**: digits of guess that do appear in secret, but not at that position. Each secret digit can be matched at most once: bulls are counted first, and the remaining unmatched digits of each value pair up as cows.
Return the feedback as the string "xAyB", where x is the number of bulls and y is the number of cows.
Examples
Constraints
- 1 <= secret.length, guess.length <= 1000
- secret.length == guess.length
- Both strings consist of digits only.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.