First, count bulls by checking positions where secret[i] == guess[i]. That part is straightforward.
For cows, you need to count digits that appear in both strings but aren't already bulls. Use a frequency array of size (one slot per digit). Walk through both strings simultaneously. When a position is not a bull, increment the count for secret[i] and decrement the count for guess[i].
You can do this in a single pass. If secret[i] finds a negative count (meaning guess already contributed that digit), that's a cow. Similarly, if guess[i] finds a positive count, that's also a cow.