Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Secret vs Guess String Counts

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Secret vs Guess String Counts. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Tala needs to score a candidate verification string against a secret string. Given two strings of equal length, count characters that match both the value and position, then count remaining characters that exist in the secret but appear at different positions.

Each character occurrence can be matched at most once. Exact matches must be removed before counting misplaced matches, and repeated characters require careful frequency tracking.

Formal Specification

Implement score_guess(secret, guess):

  • Input: Two strings, secret and guess, with equal length.
  • Output: A two-element list [exact, misplaced], where exact is the number of matching characters at the same index and misplaced is the number of remaining guess characters that occur elsewhere in secret.

Characters are case-sensitive. The input contains only lowercase English letters and digits.

Constraints

  • 1 <= len(secret) == len(guess) <= 10^5
  • Characters are lowercase English letters or digits
  • Duplicate characters may appear
  • Each character occurrence can be matched at most once

Function Signature

def score_guess(secret, guess):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output