Problems > Bulls and Cows > Editorial

Bulls and Cows — Solution & Editorial

Back to the Problem

Bulls are positional matches; total digit matches are ∑ min(count in secret, count in guess); cows = total − bulls.

Complexity: O(length)

Watch out: Duplicate digits: count matches with multiset minimums, or 1123 vs 0111 comes out wrong.