FunctionRacerProblemsRace

Bulls and Cows

MediumHash mapsPython, JavaScript, TypeScript, Java, C++

You hold a string of digits secret and a friend guesses a string guess of the same length.

Return the hint as "xAyB", where x is the number of bulls and y the number of cows.

Example 1

secret "1807"
guess "7810"
returns "1A3B"

One bull (the 8), three cows (1, 0, 7): 1A3B.

Example 2

secret "1123"
guess "0111"
returns "1A1B"

One bull, one cow: 1A1B.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Hash maps problems