Count Position Matches and Remaining Digit Matches

Quick Overview

Count Position Matches and Remaining Digit Matches. Return a Bulls and Cows hint for secret and guess. Bulls are equal digits at equal positions. Cows are the remaining guess digits that can match remaining secre

Count Position Matches and Remaining Digit Matches

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return a Bulls and Cows hint for secret and guess. Bulls are equal digits at equal positions. Cows are the remaining guess digits that can match remaining secret digits after rearrangement. Match each occurrence at most once. Format the result exactly as "xAyB". ```cpp string getHint(string secret, string guess); ``` ### Examples ```text secret="1234", guess="1243" -> "2A2B" secret="1100", guess="1011" -> "1A2B" ``` ### Constraints - Both digit strings have equal length in [1,1000]. - Duplicate decimal digits are allowed.

Overview: Count Position Matches and Remaining Digit Matches. Return a Bulls and Cows hint for secret and guess. Bulls are equal digits at equal positions. Cows are the remaining guess digits that can match remaining secre

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return a Bulls and Cows hint for secret and guess. Bulls are equal digits at equal positions. Cows are the remaining guess digits that can match remaining secret digits after rearrangement. Match each occurrence at most once. Format the result exactly as "xAyB".

string getHint(string secret, string guess);

Examples

secret="1234", guess="1243" -> "2A2B"
secret="1100", guess="1011" -> "1A2B"

Constraints

  • Both digit strings have equal length in [1,1000].
  • Duplicate decimal digits are allowed.