Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Letter Feedback Comparison
00:00
5 left

Letter Feedback Comparison

MediumPython

Problem

Character AI is testing a word-guessing interaction where each guess needs precise letter feedback. Implement a function that compares a guessed word with a secret word and classifies every guessed character.

Return a list with one status per character in guess:

  • 2 means the character is correct and in the correct position.
  • 1 means the character appears in the secret word but belongs in a different position.
  • 0 means the character does not have an unused matching occurrence in the secret word.

Formal Specification

Implement word_feedback(secret, guess), where both inputs are lowercase strings of equal length. Return a list of integers with the same length as guess. Each occurrence in the secret may be matched at most once. Exact matches must take priority over misplaced matches, which is important when either word contains repeated characters.

Constraints

  • 1 <= len(secret) == len(guess) <= 10^5
  • secret and guess contain only lowercase English letters
  • Each secret character occurrence can be matched at most once
  • Exact matches take priority over misplaced matches

Function Signature

def word_feedback(secret, guess):
Interviewer

Your question is Letter Feedback Comparison. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.